Logout

4.2.3 Calculate the values of a Boolean expression using truth tables.


Teaching Notes:
A maximum of three inputs will be expected. Include the use of truth tables to determine whether two Boolean expressions are logically equivalent.

Sample Question (Very sort of in this case...)

The method logic1(), shown below, returns the output from a particular logic gate.
The logic gate has two inputs, a and b.

//parameters a and b can only have the values of 0 or 1
public boolean logic1(int a, int b)
{ if(!(a==b)) return true;
else return false;
}

(a) Identify the logic gate represented by the above method. [1 mark]

(b) Construct the method logic2(), which would similarly return the output from
a NAND gate. [2 marks]

Recall that two circuits are equivalent if their respective truth tables are the same.

The method compareCircuits() uses nested loops to generate and pass inputs
to the methods logic1() and logic2(). It compares the outputs of the two logic
circuits represented by these methods, and returns the value true if the two circuits are
equivalent, and false if they are not.

(c) Construct the method compareCircuits(). [5 marks]

JSR Notes:

“Calculate the values of Boolean expressions using truth tables” means coming up with all the situations where they evaluate to true.  You can determine whether or not two truth tables are logically equivalent because they will have identical truth tables (assuming of course that you construct them the same way: 0000 1111 down the A column for an ABC table, etc.)

Ultimately, you will express your answer with one line, such as:

a

This will always take the (non-reduced) form one or several groups of b separated by +.
The idea is that you’re taking all of the rows of the truth table that evaluate to true (1), and adding them together.  So in the above example, what we would see in the truth is that there is a 1 at the most right-hand column for when not A, not B, and C, and also for not A, B, and C.  And all of the other columns would result in 0.

So, here’s a full example:

Calculate the values of the Boolean expression c

A

B

C

d

e

0

0

0

0

0

0

0

1

0

0

0

1

0

1

0

0

1

1

1

1

1

0

0

1

0

1

0

1

1

1

1

1

0

1

0

1

1

1

1

1

The answer is simply f since only when A and B and C are true is the whole expression true.  This maybe isn’t the best example, since there was only one 1 in the right-hand column.  See page 237 for a better example.

But as you do, keep a few things in mind.  But sure that you don’t make any careless errors two places, because it often happens: