Section 6f

Truth Tables


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Logical Analysis

A Handy Tool

Since you have been working on analyzing these Boolean expressions, it might be handy to introduce you to a tool for making the analysis process a little easier. The Truth Table is usually a small chart or table that you create to identify the results of various Boolean expressions.

Consider for a moment the Boolean expression A && B. This expression should be easy to analyze, but to be thorough in your program study, you use a Truth Table to do the analysis. The Truth Table would be implemented as shown below.

For the condition A && B:

A

B

Result

false

false

false

false

true

false

true

false

false

true

true

true

Watch the following video to see how this data is analyzed and how the table is created.


Consider the A || B combination, shown next.

A

B

Result

false

false

false

false

true

true

true

false

true

true

true

true

Watch the following video to see how this data is analyzed and how the table is created.


Finally, consider the Truth Table for the leap year expression discussed previously:

isLeapYear = isAFourthYear && notACentury || isAFourthCentury;

isAFourthYear

notACentury

isAFourthCentury

Result

false

false

false

not possible

false

false

true

not possible

false

true

false

false

false

true

true

not possible

true

false

false

false

true

false

true

true

true

true

false

true

true

true

true

not possible

From your analysis of the table above, you should be able to work out the evaluation of each of the given conditions. The Truth Table can be your best friend when you are trying to resolve what decisions will be made out of the logical expressions you have put together. It takes a few minutes, but it will keep you from making silly mistakes. Consider this final logical condition example, and short history lesson, to apply your knowledge of the Truth Table.

Watch this video to see the logical analysis of the leap year condition.


Augustus de Morgan was a mathematics professor who backtracked the logic of negative logical relationships and how they impacted the AND and the OR logical operations. In a nutshell, his law states that NOT (A OR B) is the same thing as NOT A AND NOT B. The AND/OR relationship is the same: NOT (A AND B) is the same thing as NOT A OR NOT B.

This is an interesting practical application of your Truth Tables. Consider the application of his law in the following Truth Table. Remember as you analyze this that NOT simply turns the thing it is converted to into the opposite thing (i.e., NOT true is false, and NOT false is true).

A

B

Not(A or B)

Not A and Not B

false

false

true

true

true

false

false

false

false

true

false

false

true

true

false

false

Make sure you understand how each of the values were found in this example. de Morgan's Law is fairly simple and can be found at any time by just implementing a Truth Table. Just make sure you can create and apply a Truth Table, even when the conditions are all negated (i.e., they all use NOT).

Watch this video to see the logical analysis of the de Morgan's Law Truth Table.


To A or NOT to B

These first few topics on Boolean conditions will help you get started in thinking about logical operations, and how to apply them. Whenever you need to apply logical conditions to any problems, you must evaluate all the consequences of a given combination of logical operations. In the next topics, you will start learning how to use these conditions to change the direction of your programs - in other words, to make decisions.