### Module 5 Section 2- Boolean Expressions and Truth Tables

Boolean expressions can be more complex than just a simple disjunction, conjunction, or complementation. It is by combining these three basic operations that more complex expressions are formed. Consider the following expression:

This expression involves two operations. The first operation is the conjunction of A and B. The second operation is the complement the result of the conjunction. This double operation has a special name, nand, for "not and." Compare this to:

This expression involves three operations. The first is to complement A. The second is the complement B. The third is two compute the disjunction of the two complements. The above has no special name. It's just the conjuction of two complements. This leads to a basic rule about the overline (the complementation operator). The complement is performed on the expression beneath the bar. In the first example, one bar covered the conjunction AB, so it was performed after the conjunction. In the second example, there are two complementation operators, each one over a single variable. Similarly:

is called nor for "not or." The disjunction is performed first, followed by the complementation. Then there's:

which is the disjunction of two complements. The truth table below shows the relationships between these four expressions:

 0 0 1 1 1 1 0 1 1 0 0 1 1 0 1 0 0 1 1 1 0 0 0 0

Examining this table you can see that:

This result, known as DeMorgan's Law, is quite heavily used in the process of expression reduction. For example, the first form of DeMorgan's law shown above computes A nand B in two different ways, but the expression on the left side of the equality uses only two operations whereas the version on the right side uses three operations. Obviously, if you were to compute nand you would choose the two-operation version over the three-operation version.  What's more, if you saw the three-operation version, you could replace it with the two-operation version, thus reducing the number of operations the entire expression would require to compute. This becomes very important when we want to build fast computers; we will always want to choose the fastest version of any operation. We address reduction more fully in the next section.

Another thing to notice is the operator precedence for these three operations. In the absence of parenthesis, or if the complement operator is over a single value, then the following rules apply:

1. Complementation is done first
2. Conjunction is done second
3. Disjunction is done last

So, the following expression

could be evaluated in the following order

We can now build complex Boolean expressions to answer questions such as the one posed by this word problem:

Jane is usually paid on the last day of the month. Jane is never paid on a weekend or holiday with one exception: if the month is December or June, then Jane can be paid on a weekend or holiday if necessary. Is Jane getting paid today?

We need the following independent variables:

L - true if today is the last day of the month
W - true if today is a weekend or holiday
M - true if the month is December or June

The expression to compute whether Jane is paid today would be expressed as:

This expression is true if today is the last day of the month and it is not a weekend or holiday, or its is December or June. A truth table to compute this value could be built up component by component. The truth table below shows this method:

 0 0 0 1 1 0 0 0 1 1 1 0 0 1 0 0 0 0 0 1 1 0 1 0 1 0 0 1 1 1 1 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 1 1

### Homework Questions

1. Write Boolean expressions and the accompanying truth tables for the following word problems.
1. People always buy popcorn if it is hot. People only buy drinks if they are cold. People will also buy popcorn if the movie is scary, but only if they also buy a drink. Will we be selling any popcorn?
2. A Slim Whitman song causes listeners to tune out. Listeners never tune out if the million dollar contest is being conducted. The million dollar contest is only conducted during sweeps. Are listeners staying tuned in?
3. Pascal is an easy, safe programming language. C is a hard, dangerous programming language. BASIC is an easy, dangerous programming language. COBOL is a hard, safe programming language. We only use dangerous programming languages if safe ones are not available. We only use hard programming languages if easy ones are not available. Are we using C?

Next Section: Boolean Algebra
Previous Section: Basic Logic Operations and Truth Tables