Boolean Algebra

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Curriculum

 Coder Merlin™  Computer Science Curriculum Data Unit: Boolean algebra Experience Name: Boolean Algebra (W1013) Knowledge and skills: §10.321 Demonstrate understanding and proficiency in the use of Boolean algebra §10.322 Demonstrate understanding and proficiency in the use of Boolean algebra truth tables §10.323 Demonstrate understanding and proficiency in the use of Boolean algebra canonical representation §10.324 Demonstrate understanding and proficiency in the use of DeMorgan's Laws Topic areas: Boolean algebra Classroom time (average): 60 minutes Study time (average): 240 minutes Successful completion requires knowledge: understand the principles of Boolean algebra; understand how to use truth tables; understand how to represent a Boolean expression canonically; understand the use of DeMorgan's laws; understand the use of operators in Boolean algebra; understand the order of operations in Boolean algebra Successful completion requires skills: demonstrate proficiency in using Boolean algebra; demonstrate proficiency in constructing and using truth tables; demonstrate the use of canonical representation for arbitrary Boolean expressions; demonstrate the appropriate application of DeMorgan's laws

Background

The branch of algebra in which the values of the variables are the truth values true and false, usually denoted 1 and 0 respectively. It is a formal description of logical relations. It was introduced by George Boole in his first book The Mathematical Analysis of Logic in 1847.

Alternative names for true and false:

false true
no yes
0 1
F T

Basic Operations

There are three basic operations, all of which have two inputs and one output.

• AND, formally termed conjunction and denoted by ${\displaystyle A\land B}$. The output is true iff (iff means if and only if) both inputs are true.
• OR, formally termed disjunction and denoted by ${\displaystyle A\lor B}$. The output is true if either of the inputs are true. This is sometimes also referred to as inclusive disjunction. This is because the output is true if either of the inputs are true, including the case where both inputs are true.
• NOT, formally termed negation, and denoted by ${\displaystyle \neg A}$. The output is simply the opposite of the input.

There are also several "shortcut" notations that we can use for more succinct expressions:

• conjunction may be written as multiplication, i.e. ${\displaystyle A\cdot B}$ or, more simply, ${\displaystyle AB}$
• disjunction may be written as addition, i.e. ${\displaystyle A+B}$
• negation may be written with a bar above the variable, i.e. ${\displaystyle {\bar {A}}}$

All Boolean operations can be expressed through a composition of these basic operations.

Secondary Operations

• NAND is denoted by ${\displaystyle A{\overline {\land }}B}$ and is equivalent to the negation of the result of ${\displaystyle A\land B}$, i.e. ${\displaystyle {\overline {A\land B}}}$. The output is true in all cases except when both A and B are true.
• NOR is denoted by ${\displaystyle A{\overline {\lor }}B}$ and is equivalent to the negation of the result of ${\displaystyle A\lor B}$, i.e. ${\displaystyle {\overline {A\lor B}}}$. The output is true only if both A and B are false.
• EQUAL, formally termed equivalence and denoted by ${\displaystyle A\equiv B}$. The output is true iff both inputs have the same value.
• XOR, formally termed exclusive disjunction and denoted by ${\displaystyle A\oplus B}$, ${\displaystyle A{\dot {\lor }}B}$, ${\displaystyle A{\underline {\lor }}B}$, ${\displaystyle A\not \equiv B}$. The output is true if either of the inputs are true but both are not true. Compare this to inclusive disjunction.
• IMPLY, formally termed material implication and denoted by ${\displaystyle A\rightarrow B}$. This is sometimes read as "if A then B" or "A implies B". The output is true in all cases except the case where A is true and B is false.
• CONVERSE IMPLY, formally termed converse implication and denoted by ${\displaystyle A\leftarrow B}$. This is sometimes read as "if B then A" or "B implies A". The output is true in all cases except the case where B is true and A is false.
• BIDIRECTIONAL IMPLY, formally termed material biconditional and denoted by ${\displaystyle A\leftrightarrow B}$. This is sometimes read as "A if and only if B" and abbreviated as "A iff B". It is logically equivalent to ${\displaystyle A\rightarrow B\land B\rightarrow A}$. The output is true if both A and B are true or if both A and B are false.

Observe
Observe, Ponder, and Journal: Section 1
1. Why is one of the symbols used for exclusive disjunction ${\displaystyle \not \equiv }$?

Order of Operations

Expressions with multiple operators are evaluated from left to right, respecting the operator precedence as follows:

1. ${\displaystyle \neg }$ (NOT) has the highest priority, followed by
2. ${\displaystyle \land }$ (AND), ${\displaystyle {\overline {\land }}}$ (NAND)
3. ${\displaystyle \lor }$ (OR), ${\displaystyle {\overline {\lor }}}$ (NOR)
4. ${\displaystyle \rightarrow }$ (IMPLY), ${\displaystyle \leftarrow }$ (CONVERSE IMPLY)
5. ${\displaystyle \oplus }$, ${\displaystyle {\dot {\lor }}}$, ${\displaystyle {\underline {\lor }}}$, ${\displaystyle \not \equiv }$ (XOR), ${\displaystyle \equiv }$, ${\displaystyle \leftrightarrow }$ (EQUIV)

As always, parentheses may be used to both emphasize and override the order of operations.

For clarification, here are several examples of equivalent expressions:

Without Parentheses With Parentheses
${\displaystyle A\lor B\land C}$ ${\displaystyle A\lor (B\land C)}$
${\displaystyle A\land B\land C\lor D}$ ${\displaystyle ((A\land B)\land C)\lor D}$
${\displaystyle A\land B\lor C\land D}$ ${\displaystyle (A\land B)\lor (C\land D)}$
${\displaystyle \neg A\land B\lor C}$ ${\displaystyle ((\neg A)\land B)\lor C}$
Caution

It is important to note that the precedence list above, while generally agreed upon, is not implemented by all computer programming languages. It's important to pay close attention to the rules of each language, or, better yet, use parentheses to avoid ambiguity.

Truth Tables

Truth tables provide us with a straightforward means to specify the required output(s) for the specified input(s), in table form. On the left-hand side of the table we enumerate the input(s) and on the right-hand side of the table we specify the output(s). Assuming that we have ${\displaystyle n}$ inputs we may label each input as ${\displaystyle I_{1},I_{2},I_{3},...I_{n}}$. The value of the inputs on any given row, may be referred to as an input tuple. Likewise, assuming that we have ${\displaystyle m}$ outputs we may label each output as ${\displaystyle O_{1},O_{2},O_{3},...O_{m}}$, and the value of these outputs on any given row may be referred to as an output tuple. The number of rows in any such table is given by the formula ${\displaystyle 2^{n}}$. When there is a single output, we can formalize the relationship as ${\displaystyle O_{1}=f(I_{1},I_{2},I_{3},...)}$

Observe
Observe, Ponder, and Journal: Section 2
1. Why is the formula for determining the number of rows in a truth table related only to the number of inputs, and why is the formula ${\displaystyle 2^{n}}$?

Note that for convenience we sometimes label inputs as A, B, C, etc. rather than ${\displaystyle I_{1},I_{2},I_{3},}$ etc. and do the same for outputs, often beginning with the letter Q.

When writing truth tables, it is very helpful to always write them in the same order. This helps in reading and memorizing the tables because we can simply memorize the output column(s), because the input columns will always be the same. For example, consider the AND truth table:

x y ${\displaystyle x\cdot y}$
0 0 0
0 1 0
1 0 0
1 1 1

Rather than memorizing the entire table, we can just memorize the output column, i.e. 0 0 0 1. And, in most cases, we really only need to memorize the exceptional cases. We call this the standard order, i.e. ascending order of the binary inputs.

There are ${\displaystyle 2^{2^{n}}}$ possible single-output Boolean functions that can be defined over ${\displaystyle n}$ inputs. These are enumerated, with explanations, in the following table.

Function Name Boolean Algebraic Formula Truth Table Explanation
x 0 0 1 1
y 0 1 0 1
Contradiction 0 0 0 0 Always false
AND ${\displaystyle x\cdot y}$ 0 0 0 1 x and y are true
${\displaystyle x}$ AND NOT ${\displaystyle y}$ ${\displaystyle x\cdot {\bar {y}}}$ 0 0 1 0 x is true and y is false
${\displaystyle x}$ ${\displaystyle x}$ 0 0 1 1 x is true, y is irrelevant
NOT ${\displaystyle x}$ AND ${\displaystyle y}$ ${\displaystyle {\bar {x}}\cdot y}$ 0 1 0 0 x is false and y is true
${\displaystyle y}$ ${\displaystyle y}$ 0 1 0 1 y is true, x is irrelevant
XOR ${\displaystyle x\cdot {\bar {y}}+{\bar {x}}\cdot y}$ 0 1 1 0 x is true or y is true but both are not true
x is different than y
OR ${\displaystyle x+y}$ 0 1 1 1 Either x or y is true
NOR ${\displaystyle {\overline {x+y}}}$ 1 0 0 0 Neither x nor y is true
EQUIVALENCE ${\displaystyle x\cdot y+{\bar {x}}\cdot {\bar {y}}}$ 1 0 0 1 x is the same as y
NOT ${\displaystyle y}$ ${\displaystyle {\bar {y}}}$ 1 0 1 0 y is false, x is irrelevant
${\displaystyle y}$ IMPLYs ${\displaystyle x}$ ${\displaystyle x+{\bar {y}}}$ 1 0 1 1 x is true or y is false
${\displaystyle y\rightarrow x}$
NOT ${\displaystyle x}$ ${\displaystyle {\bar {x}}}$ 1 1 0 0 x is false, y is irrelevant
${\displaystyle x}$ IMPLYs ${\displaystyle y}$ ${\displaystyle {\bar {x}}+y}$ 1 1 0 1 y is true or x is false
${\displaystyle x\rightarrow y}$
NAND ${\displaystyle {\overline {x\cdot y}}}$ 1 1 1 0 x and y are not both true
Tautology 1 1 1 1 Always true

Canonical Representation

As discussed above, regardless of the function being implemented, each input and output combination can be represented by a single row in a truth table. Therefore, if we correctly represent each row, and then join those representations together, we'll be able to accurately recreate the function. There's a very straightforward means of doing so:

• For each output, we consider only those rows where the output value is true. We then form an expression representing all of the inputs for that same row, either the value of the input itself (if true) or its negation (if false), so that the result is true.
• We join each of the above expressions using disjunction.

Let's consider some examples:

CONJUNCTION
row ${\displaystyle x}$ ${\displaystyle y}$ ${\displaystyle x\land y}$
1. 0 0 0
2. 0 1 0
3. 1 0 0
4. 1 1 1

The first step is to scan through each row and note each case where the output is true. In the case of conjunction, there is only one such row, row #4:

CONJUNCTION
row ${\displaystyle x}$ ${\displaystyle y}$ ${\displaystyle x\land y}$
#1 0 0 0
#2 0 1 0
#3 1 0 0
#4 1 1 1

The expression representing the inputs for this row is simply ${\displaystyle xy}$, that is, the conjunction of ${\displaystyle x}$ and ${\displaystyle y}$. Because there are no other rows for which the output is true, we're done. Thus, the canonical representation of ${\displaystyle x\land y}$ is simply ${\displaystyle xy}$. Let's consider a slightly more challenging example:

EXCLUSIVE DISJUNCTION
row ${\displaystyle x}$ ${\displaystyle y}$ ${\displaystyle x\oplus y}$
#1 0 0 0
#2 0 1 1
#3 1 0 1
#4 1 1 0

Again, the first step is to scan through each row and note each case where the output is true. In the case of exclusive disjunction, there are two such rows: row #2 and row #3. The expression representing the inputs for these rows are ${\displaystyle {\bar {x}}y}$ for row #2 and ${\displaystyle x{\bar {y}}}$ for row #3. To complete the canonical representation, we combine the expression for each row with disjunction. Thus, the canonical representation of ${\displaystyle x\oplus y}$ is ${\displaystyle {\bar {x}}y+x{\bar {y}}}$.

Let's consider one final example, function f:

FUNCTION f
row ${\displaystyle x}$ ${\displaystyle y}$ ${\displaystyle z}$ ${\displaystyle f(x,y,z)}$
#1 0 0 0 0
#2 0 0 1 1
#3 0 1 0 0
#4 0 1 1 0
#5 1 0 0 0
#6 1 0 1 1
#7 1 1 0 1
#8 1 1 1 0

We note those rows in which the output is true: row #2, row #6, and row #7. The expressions representing the inputs for these rows are:
row #2: ${\displaystyle {\bar {x}}{\bar {y}}z}$
row #6: ${\displaystyle x{\bar {y}}z}$
row #7: ${\displaystyle xy{\bar {z}}}$

Combining these expressions with disjunction yields our canonical representation: ${\displaystyle {\bar {x}}{\bar {y}}z+x{\bar {y}}z+xy{\bar {z}}}$.

De Morgan's Laws

De Morgan's Laws provide a helpful formula to obtain the same truth table of:

• an AND operation by using negation and an OR operation, or
• an OR operation by using negation and an AND operation

The Laws are:

• ${\displaystyle X\land Y\Leftrightarrow \neg (\neg X\lor \neg Y)}$
• ${\displaystyle X\lor Y\Leftrightarrow \neg (\neg X\land \neg Y)}$

Exercises

Exercises
•  J1013  Create a journal and answer all questions in this experience. Be sure to:
• properly name your journal as J1013.txt
• include all sections of the journal, properly formatted
• push your changes to GitHub
• properly tag your journal as J1013.Final
• push your tag to GitHub
•  M1013-10  Complete  Merlin Mission Manager  Mission M1013-10.
•  M1013-11  Complete  Merlin Mission Manager  Mission M1013-11.
•  M1013-12  Complete  Merlin Mission Manager  Mission M1013-12.
•  M1013-31  Complete  Merlin Mission Manager  Mission M1013-31.