ELE-210 · Lesson 3 of 12 · 24 min

Boolean algebra

In 1854 the English mathematician George Boole published an algebra of logic in which variables stand for true or false and are combined with AND, OR and NOT. For eighty years it was a branch of philosophy. Then in 1938 Claude Shannon, a master's student at MIT, showed that Boole's algebra describes exactly how networks of relay switches behave, and digital design was born. Boolean algebra lets a designer write down what a circuit must do as an expression, transform the expression into a simpler or faster equivalent, and prove that two circuits do the same thing. This lesson covers the operations, the truth table, the laws and theorems, and the canonical sum-of-products and product-of-sums forms that connect a specification to a circuit.

Variables and operations

A Boolean variable has one of two values, 0 or 1. There are three basic operations. NOT, or complement, inverts a value: the complement of A is written Ā or A′, and it is 1 when A is 0. AND gives 1 only when all its inputs are 1; it is written as a product, A·B or simply AB. OR gives 1 when at least one input is 1; it is written as a sum, A + B. The plus sign does not mean arithmetic addition here: in Boolean algebra 1 + 1 = 1.

\[\overline{0} = 1 \quad \overline{1} = 0 \qquad A \cdot B = 1 \iff A = B = 1 \qquad A + B = 0 \iff A = B = 0\]

When operations are combined, NOT has the highest precedence, then AND, then OR, just as in ordinary algebra where multiplication comes before addition. So A + BC̄ means A OR (B AND (NOT C)). Parentheses override precedence when needed. A bar over a whole expression complements the whole expression after it has been evaluated.

Truth tables

A Boolean function of n variables can be described completely by a truth table that lists the output for every one of the 2ⁿ input combinations. The rows are normally written in binary counting order, so a function of three variables has eight rows from 000 to 111. The truth table is the most basic and least ambiguous specification of combinational logic: any two expressions or circuits with the same truth table are equivalent, however different they look.

Amara's first task on the pedestrian crossing is the walk-request logic. The controller should register a walk request (W = 1) when the pedestrian button P is pressed, but only if the system is not in maintenance mode (M = 0), or when the remote test input T from the traffic center is active, regardless of the button. Writing the behavior as a truth table makes it exact.

Truth table for the walk-request signal W. The request is registered when the button is pressed outside maintenance mode, or when the remote test is active.
PMTW
0000
0011
0100
0111
1001
1011
1100
1111

Reading the rows where W = 1 gives the function directly, and the words of the specification give the same thing as an expression: W = PM̄ + T. Checking the expression against all eight rows confirms it. For small functions, this check is the simplest proof of correctness, and Python can do it automatically for larger ones.

Postulates and basic laws

Boolean algebra rests on a few postulates, from which every other law follows. Each law comes in a pair: the dual of a law is obtained by swapping AND with OR and 0 with 1, and the dual of a true law is always true. This principle of duality halves the number of laws to remember.

The basic laws of Boolean algebra in dual pairs.
LawAND formOR form
IdentityA · 1 = AA + 0 = A
Null (dominance)A · 0 = 0A + 1 = 1
IdempotentA · A = AA + A = A
ComplementA · Ā = 0A + Ā = 1
Involutiondouble complement of A = A(same)
CommutativeAB = BAA + B = B + A
Associative(AB)C = A(BC)(A + B) + C = A + (B + C)
DistributiveA(B + C) = AB + ACA + BC = (A + B)(A + C)
AbsorptionA(A + B) = AA + AB = A
SimplificationA(Ā + B) = ABA + ĀB = A + B

Most laws look like ordinary algebra, but three do not. A + A = A and A + 1 = 1 have no counterpart in arithmetic, and the second distributive law, A + BC = (A + B)(A + C), is false for numbers but true for Booleans. Each can be proved by perfect induction: check all combinations of the variables in a truth table. For A + BC = (A + B)(A + C), the eight rows of A, B and C give identical columns on both sides.

De Morgan's theorems

The two most useful theorems in digital design were stated by Augustus De Morgan, a contemporary of Boole. They say how to complement an AND or an OR: the complement of a product is the sum of the complements, and the complement of a sum is the product of the complements.

\[\overline{A \cdot B} = \overline{A} + \overline{B} \qquad \overline{A + B} = \overline{A} \cdot \overline{B}\]

The theorems extend to any number of variables, and they give a mechanical rule for complementing any expression: change every AND to OR and every OR to AND, and complement every variable, keeping the original grouping. De Morgan's theorems are what make NAND and NOR gates universal (lesson 4), and they let a designer move inversion bubbles around a circuit to suit the gates available.

Worked problem

Complementing an expression

Daniel wants the condition under which the walk request is NOT registered, written without a bar over a long expression. Find the complement of W = PM̄ + T.

Show solution
  1. \[\overline{W} = \overline{P\overline{M} + T}\]
  2. Apply De Morgan to the OR: =\overline{W} = \overline{P\overline{M}} \cdot \overline{T}
  3. Apply De Morgan to the AND: =\overline{W} = (\overline{P} + M)\,\overline{T}
  4. Read it back: no request when the test input is off and either the button is not pressed or the system is in maintenance.

Answer: W̄ = (P̄ + M)T̄.

Consensus and other theorems

The consensus theorem removes a redundant term. In XY + X̄Z + YZ, the term YZ is the consensus of the first two terms, formed from the variables left after removing X and X̄, and it adds nothing: whenever YZ = 1, either XY or X̄Z is already 1. So XY + X̄Z + YZ = XY + X̄Z. Its dual is (X + Y)(X̄ + Z)(Y + Z) = (X + Y)(X̄ + Z). Interestingly, lesson 11 shows that the redundant consensus term is sometimes deliberately kept in a circuit to remove a timing glitch called a hazard.

\[XY + \overline{X}Z + YZ = XY + \overline{X}Z\]

Shannon's expansion theorem splits any function around one variable: F = X·F(X = 1) + X̄·F(X = 0). The two restricted functions, called cofactors, have one fewer variable. Shannon expansion is the basis of the multiplexer implementation of logic (lesson 6), of the binary decision diagrams that verification tools use, and of the lookup tables inside programmable chips (lesson 12).

Simplifying with algebra

A simpler expression usually means fewer gates, fewer inputs per gate, less power and often more speed. Algebraic simplification applies the laws step by step until no law makes the expression smaller. It requires some practice and judgment, which is why lesson 5 introduces Karnaugh maps as a more systematic method for up to four or five variables, and why software tools are used for large functions.

Worked problem

Algebraic simplification

Simplify F = ABC + ABC̄ + AB̄C.

Show solution
  1. Group the first two terms and factor: =ABC + AB\overline{C} = AB(C + \overline{C}) = AB
  2. \[F = AB + A\overline{B}C\]
  3. Factor out A: =F = A(B + \overline{B}C)
  4. Apply the simplification law X + X̄Y = X + Y: =F = A(B + C) = AB + AC

Answer: F = AB + AC, two 2-input ANDs and one OR instead of three 3-input ANDs and a 3-input OR.

Minterms and the sum of products

A minterm is a product term that contains every variable exactly once, complemented or not, and is 1 for exactly one row of the truth table. For three variables A, B and C, the minterm for row 101 is AB̄C. Minterms are numbered by the row they represent, so AB̄C is m₅. Any function can be written as the OR of the minterms for the rows where it is 1. This is the canonical sum of products (SOP), often written compactly with the Σ notation.

\[W(P,M,T) = \sum m(1, 3, 4, 5, 7) = \overline{P}\,\overline{M}T + \overline{P}MT + P\overline{M}\,\overline{T} + P\overline{M}T + PMT\]

The canonical form is long but completely mechanical, and it maps straight onto a two-level circuit: one AND gate per minterm feeding one OR gate. Simplification then merges minterms that differ in one variable, using XY + XȲ = X. The five minterms of W shrink to PM̄ + T, two terms instead of five.

Maxterms and the product of sums

A maxterm is a sum term containing every variable once, and it is 0 for exactly one row. The maxterm for row 010 is A + B̄ + C: each variable appears complemented where the row has a 1. Any function can also be written as the AND of the maxterms for the rows where it is 0, the canonical product of sums (POS), written with Π notation. The minterm list and the maxterm list of a function are complementary: together they cover every row exactly once.

\[W(P,M,T) = \prod M(0, 2, 6) = (P + M + T)(P + \overline{M} + T)(\overline{P} + \overline{M} + T)\]

Which form is better depends on the function. If a function is 1 for only a few rows, SOP is shorter; if it is 0 for only a few rows, POS is shorter. Simplified POS for W is (M̄ + T)(P + T), which expands back to PM̄ + T. Both describe the same truth table and both are correct.

Two circuits for the walk-request function side by side. On the left a two-level sum of products: an AND gate with inputs P and M-bar, and the input T, both feeding an OR gate whose output is W. On the right a two-level product of sums: two OR gates, one with M-bar and T and one with P and T, feeding an AND gate whose output is W.
The walk-request logic as a sum of products (left) and a product of sums (right). Both have the same truth table.
Perfect induction in code: evaluate every expression on every input combination and compare the columns.
# Build a truth table and check that several expressions are the same function
from itertools import product

exprs = {
    "canonical SOP": lambda P, M, T: (not P and not M and T) or (not P and M and T) or (P and not M and not T)
                                      or (P and not M and T) or (P and M and T),
    "simplified SOP": lambda P, M, T: (P and not M) or T,
    "simplified POS": lambda P, M, T: ((not M) or T) and (P or T),
}
print("P M T | " + " | ".join(exprs))
columns = {name: [] for name in exprs}
for P, M, T in product((0, 1), repeat=3):
    row = [int(bool(f(P, M, T))) for f in exprs.values()]
    for name, v in zip(exprs, row):
        columns[name].append(v)
    print(f"{P} {M} {T} | " + " | ".join(f"{v:^{len(n)}}" for v, n in zip(row, exprs)))
minterms = [i for i, v in enumerate(columns["canonical SOP"]) if v]
print("minterms:", minterms, " all equal:", len({tuple(c) for c in columns.values()}) == 1)
Output
P M T | canonical SOP | simplified SOP | simplified POS
0 0 0 |       0       |       0        |       0       
0 0 1 |       1       |       1        |       1       
0 1 0 |       0       |       0        |       0       
0 1 1 |       1       |       1        |       1       
1 0 0 |       1       |       1        |       1       
1 0 1 |       1       |       1        |       1       
1 1 0 |       0       |       0        |       0       
1 1 1 |       1       |       1        |       1       
minterms: [1, 3, 4, 5, 7]  all equal: True

This brute-force check is how Amara confirms each simplification before drawing it. It costs nothing for a few variables. For many variables, 2ⁿ rows become too many and verification tools switch to cleverer methods, but the principle, that equal truth tables mean equal functions, stays the same.

Other two-input functions

With two inputs there are 2⁴ = 16 possible Boolean functions, because each of the four rows of the truth table can be 0 or 1. Besides AND and OR, the important ones are NAND (NOT-AND), NOR (NOT-OR), XOR (exclusive OR) and XNOR (equivalence). XOR is 1 when its inputs differ, A ⊕ B = AB̄ + ĀB. It is the heart of adders, comparators, parity and Gray code circuits. XNOR is 1 when the inputs are equal, which makes it an equality detector.

\[A \oplus B = A\overline{B} + \overline{A}B \qquad \overline{A \oplus B} = AB + \overline{A}\,\overline{B}\]

XOR has useful algebraic properties: it is commutative and associative, A ⊕ 0 = A, A ⊕ 1 = Ā and A ⊕ A = 0. The last property means XORing a value with the same key twice gives back the original, which is used in simple encryption, in RAID storage parity and in swapping registers without a temporary location.

Common mistakes

  • MistakeTreating + as arithmetic addition, so that 1 + 1 = 2.

    InsteadIn Boolean algebra 1 + 1 = 1; + means OR.

  • MistakeBreaking a bar over a product into a product of barred variables.

    InsteadBy De Morgan, the complement of AB is Ā + B̄, not ĀB̄.

  • MistakeApplying De Morgan without keeping the original grouping.

    InsteadAdd parentheses first so that each AND becomes a parenthesized OR.

  • MistakeListing maxterms with the same complementing rule as minterms.

    InsteadIn a maxterm a variable is complemented where the row has a 1, the opposite of a minterm.

  • MistakeTrusting a simplification without checking it.

    InsteadCompare truth tables, by hand or in code, before building the circuit.

Summary and key terms

  • Boolean variables are 0 or 1 and combine with NOT, AND and OR, with that order of precedence.
  • A truth table lists the output for all 2ⁿ input combinations and fully specifies a combinational function.
  • Every law has a dual, obtained by swapping AND with OR and 0 with 1.
  • De Morgan: the complement of a product is the sum of complements, and vice versa.
  • The canonical SOP is the OR of minterms where F = 1; the canonical POS is the AND of maxterms where F = 0.
  • XOR is 1 when its inputs differ and is central to arithmetic, parity and comparison.
Truth table
A table giving a function's output for every combination of its inputs.
Duality
The principle that swapping AND with OR and 0 with 1 in a true law gives another true law.
De Morgan's theorems
Rules for complementing a product (sum of complements) and a sum (product of complements).
Minterm
A product term containing every variable once, equal to 1 for exactly one input combination.
Maxterm
A sum term containing every variable once, equal to 0 for exactly one input combination.
Sum of products
An expression that ORs together AND terms; the canonical form uses minterms.
Consensus theorem
XY + X̄Z + YZ = XY + X̄Z: the consensus term YZ is redundant.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Prove A + ĀB = A + B by perfect induction or algebra.

    Show answer

    A + ĀB = (A + Ā)(A + B) by the second distributive law = 1 · (A + B) = A + B.

  2. Use De Morgan to complement F = (A + B̄)C.

    Show answer

    F̄ = ĀB + C̄.

  3. Simplify F = AB + AB̄ + ĀB.

    Show answer

    AB + AB̄ = A, so F = A + ĀB = A + B.

  4. Write F(A,B,C) = Σm(0, 2, 6, 7) as a canonical POS.

    Show answer

    F = ΠM(1, 3, 4, 5) = (A + B + C̄)(A + B̄ + C̄)(Ā + B + C)(Ā + B + C̄).

  5. Apply the consensus theorem to F = AB + B̄C + AC.

    Show answer

    AC is the consensus of AB and B̄C, so F = AB + B̄C.

  6. Show that A ⊕ B ⊕ B = A.

    Show answer

    XOR is associative and B ⊕ B = 0, so A ⊕ 0 = A.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz