definition of Boolean True

classic Classic list List threaded Threaded
♦
♦
11 messages Options
Reply | Threaded
Open this post in threaded view
♦
♦
|

definition of Boolean True

DaveAZ
Section 7 on Slide 95 states that the boolean value for False is 0 (zero) and True is -1.

Section 8 on Slide 10 states: "The code writer (typically, a compiler) must write
code that pushes a boolean expression onto the stack before the
if-goto command;"

In the Kindle version of the book, on page 135 it again states that for the Boolean type, True represented as -1 and False is represented as 0.

On page 149/150 of the book, it implies that False is zero and another value evaluates to True.

Both of the Branching related test programs for Project 8 push the result of an ADD to the stack and do a if-goto based on that result.  The fail if you implement True as strictly -1.

It would be nice if the material were consistent in specifying that False = 0 and any other value evaluates to True.  Either that or change the test programs and examples so they push boolean results before if-goto commands.
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

WBahn
Administrator
I don't have access to the slides, but I think you are confusing two different aspects of what True is referring to.

If I have the expression:

A = B AND C

The code that implements this operation must treat any non-zero value of B or C as a logical True. However, that same code cannot just put any non-zero value into the variable A; if the result of evaluating the expression is True -- it MUST store the value -1.

So while Boolean operations must accept non-zero values as representing True, they may only PRODUCE the Boolean values 0=False and -1=True. The same is true (no pun intended) with most programming languages. For instance, in C, any non-zero value must be interpreted as a logical True, but operations that produce logical results that are True must produce a value of 1.

With that in mind, if you still feel there is an inconsistency, please explain it in more detail, perhaps including a screen shot of where you feel it exists. Also, be sure to note which edition of the book and tools you are referring to.
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

DaveAZ
This post was updated on .
Screenshots of the Slides below. Note that the book chapters are only included in the class resources up through chapter 6.  For chapters 7 on, the only descriptions of the chapter content are in the Slides and the Project descriptions.

Here are screenshots of slides 9. 10, 11, and 93.  The first three discussion branching and slide 93 shows the BasicLoop test program for branching.





Slide 9 says "let cond = pop
                   if cond, jump to execute the command just after the label;
                    else, execute the next command."

  That text is repeated on Slides 10 and 11.

Slide 10 adds: "Convention: The code writer (typically, a compiler) must write
                        code that pushes a boolean expression onto the stack before the
                        if-goto command"

and in the highlighted code section it puts the result of gt (greater than) on the stack before the if-goto.
The expression gt is a boolean expression which is consistent with the other statements on the three slides.


Then on Slide 93, the BasicLoop test program puts the result of a sub (subtract) on the stack before the if-goto.

I don't see anywhere in the slides where it says that the if-goto should jump if the value on the stack is any nonzero value.

I think i makes most sense to replace the test on slides 9 and 11 with:
                    let result = pop
                    if result is not equal to zero execute the command after the label,
                    else execute the next command

The next above from Slide 10 should either just be removed or replaced with something like.

           Convention: The code writer (typically, a compiler) must write
                        code that pushes the result of a boolean or arithmetic  expression onto the stack before the
                        if-goto command.  The if-goto command then jumps to the code after label if
                        that result is not equal to zero.
   
Perhaps I missed it but the only place I've found the text about using "not zero" as the condition for the if-goto is in the book. The version I'm using is the Second Ediition and it's in section 8.4.  In the kindle edition, at least, it's on page 158.
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

WBahn
Administrator
One issue that I do see with the 2ed, compared to the first, is that they omitted the specification that the three comparison commands must return 0 for true and -1 for false. That really should be part of the formal specification in Section 7.3. In 1ed, it was stated in Section 7.2.2 as part of the text, but not as part of the specification. Apparently, when they moved things from the body of the text into the formal specification, they didn't get that moved. Unless I'm missing something, I would consider this an error in 2ed.

As for not everything in the text being in the slides, that's not surprising. The slides aren't intended to be an independent replacement for the text, they are there as an optional supplement to support the text. It's sufficient for the formal specification in the text to specify that a jump is taken if the value on top of the stack is non-zero. This doesn't mean that also including that in the slides would be wrong or a bad idea -- doing so would be quite reasonable.

One thing that would be nice to have present, in the slides if not the text, is an explanation of why a value of -1 was chosen to represent true. But it's not absolutely essential and when you are crafting a course the covers a significant portion of four of five courses all in one semester, you have to be ruthless about deciding what must be kept.
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

DaveAZ
This post was updated on .
Do you know why they don't provide the book chapters for sections 7 and beyond?

My assumption for using -1 (i.e. 0xFFFF) as True is so that the NOT ALU operation (e.g., D=!A) converts a True value to a False value and vice versa.

When I implemented it, just going off the the info on slide 11, I wrote it such that if cond = True (i.e. the result of a boolean expression that's on the stack is equal to -1),
it takes the branch.  That should work according to the specification they give on the slides (i.e. "if cond, jump to execute the command just after the label; else, execute the next command.")
However, the BasicLoop test program violates the boldface Convention statement on slide 10 by using an arithmetic operation as the result to test and branch on.

I understand, and the BasicLoop code illustrates, why it's more efficient to treat any nonzero value as True so I think that's a reasonable approach to take but the slides should be corrected to be consistent with that definition of the if-goto command.

If the intent is for the if-goto command to treat any non-zero value as True, that really needs to be made clear on slides 9–11, since I assume many people taking the course rely only on the free materials provided.  Either that, or provide the book chapters for all course sections. Even then, I think the slides should still be corrected.
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

WBahn
Administrator
DaveAZ wrote
Do you know why they don't provide the book chapters for sections 7 and beyond?
Sure. So that people will buy the book that they wrote to offset the costs of developing and maintaining the course and tools. The book is the required text for the course. If people don't want to buy the text that is required for a course, then they have only themselves to blame when they lack information needed to do well in the course. How many other authors of college textbooks make the first half of their texts free?

My assumption for using -1 (i.e. 0xFFFF) as True is so that the NOT ALU operation (e.g., D=!A) converts a True value to a False value and vice versa.
Not just the logical NOT, but also AND and OR. If all bits are 0 or all bits are 1, then the bitwise operators perform the logical operations as well.

Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

DaveAZ
From the front page of the course website:

" This website contains all the lectures, project materials and tools necessary for building a general-purpose computer system and a modern software hierarchy from the ground up. The materials are aimed at students, instructors, and self-learners. Everything is free and open-source, as long as you operate in a non-profit setting".

and further down:

" You can take the course freely, by going through the lecture notes and doing the projects in the Projects section (see menu on left)."

I'm a retired engineer working with a local high school student who is taking this course as an independent study.

This is the only case I've found where the slides are missing key information that a single clarifying sentence would resolve, so I wanted to make the course creators and maintainers aware of this.  The other alternative would be to modify the BasicLoops.vm test program so that it complies with the Convention statement given in Slide 10?

Is there a compelling reason not to choose one of these two options?
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

DaveAZ
Just to clarify a bit further.  The direct interpretation of these statements on the slides:

     let cond = pop

     if cond, jump to execute the command just after the label;
               else, execute the next command.

is:

  If the condtion, the boolean value at the top of the stack, is equal to true (-1), jump to execute the command just after the label; else execute the next command.

I originally implemented it this way but it failed the BasicLoop.vm test program.

I tihnk it would be best to replace that text, on the three slides, with one that describes the intended operation which would be something along the lines of:

     let result = pop
     if the result is not zero, jump to execute the command just after the label; else, execute the next command

Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

WBahn
Administrator
In reply to this post by DaveAZ
The supplemental materials are all free and open source. The textbook is not. This is commonly the case for textbook supplements. In fact, it's far more generous than the typical case since supplemental materials often require an access code that only comes with the purchase of the text. On top of that, the text is one of the most economical college texts I've ever seen. Instead of the usual $150 to $250, this one is under $50. Instead of being annoyed that second half of the book wasn't available on the website, I was amazed that the first half was!

I've already acknowledged that there appears to be an inadvertent omission in 2ed regarding what 'true' and 'false' mean, and that it would be perfectly reasonable for that to be included in slide decks. As for what there is a compelling reason to include (or not to include), that's for the authors to decide.

There's no need to change the pseudocode for VM commands or the test files, they are consistent with the meaning of 'true'. But that meaning does need to be presented. I've passed this along to the authors for their consideration.
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

WBahn
Administrator
I was going to post a sticky on the forum spelling this out (and I probably still will), but I see that the original admin covered this in his sticky:

VM Language and Implementation Summary

lt Pop y, pop x, push -1 if x < y, else 0.
eq Pop y, pop x, push -1 if x = y, else 0.
gt Pop y, pop x, push -1 if x > y, else 0.

...

if-goto symbol Pop x. If x ≠ 0, jump to symbol.
Reply | Threaded
Open this post in threaded view
♦
♦
|

Re: definition of Boolean True

DaveAZ
Thank you for helping out with this.

Dave