pseudocodetruthtable

Truth table for a pseudocode


I am looking at the truth table for following pseudocode.

IF year = 11 AND (grade < target OR target >7) THEN
   SET revision_class TO true
END IF

I want to know whether the below truth table is correct or not. If it is correct, please explain me the row 5. Because it looks not correct to me:

Truthtable


Solution

  • Indeed, the last column has an error in the 5th row. That column should be exactly the same as the one-but-last column.

    Another thing that is not right is the pseudo code: it is incomplete. If the IF condition is not true, then the variable revision_class is undefined. To have this truth table, the pseudo code should start by setting that variable to false:

    SET revision_class TO false
    IF year = 11 AND (grade < target OR target > 7) THEN
       SET revision_class TO true
    END IF
    

    Or more direct:

    SET revision_class TO (year = 11 AND (grade < target OR target > 7))
    

    Normally you would first list the input booleans in the truth table, so I would put the column Year = 11 before the OR one. As the last column really is a copy of the previous one, you might exclude it, but I will keep it in here:

    grade < target target > 7 Year = 11 grade < target
    OR target > 7
    Year = 11 AND
    (grade < target
    OR target > 7)
    revision_class
    0 0 0 0 0 0
    0 0 1 0 0 0
    0 1 0 1 0 0
    0 1 1 1 1 1
    1 0 0 1 0 0*
    1 0 1 1 1 1
    1 1 0 1 0 0
    1 1 1 1 1 1