Boolean algebra

A simpler expression means a circuit with fewer gates: cheaper, smaller, faster and using less power. Boolean algebra gives the rules for simplifying. Variables are 0 or 1, + is OR, · is AND (often left out: AB) and ' is NOT.

The laws

LawOR formAND form
IdentityA + 0 = AA · 1 = A
NullA + 1 = 1A · 0 = 0
IdempotentA + A = AA · A = A
ComplementA + A' = 1A · A' = 0
Double negation(A')' = A
CommutativeA + B = B + AAB = BA
DistributiveA(B + C) = AB + ACA + BC = (A + B)(A + C)
AbsorptionA + AB = AA(A + B) = A
De Morgan(A + B)' = A'B'(AB)' = A' + B'

The second distributive law has no twin in ordinary algebra: try it with A = 1.

De Morgan's laws say: to complement an expression, swap AND with OR and complement each variable. "Not (rain or snow)" is "not rain and not snow".

Simplifying by hand

F = A'B + AB + AB'

  • Group the first two: A'B + AB = (A' + A)B = 1 · B = B.
  • So F = B + AB'. By the distributive law (A + BC form): B + AB' = (B + A)(B + B') = (A + B) · 1.
  • F = A + B: three ANDs and an OR became one OR gate.

Proof by truth table

Algebra can go wrong. A truth table cannot: two expressions are equal exactly when they agree on every input. With n variables there are 2ⁿ cases, few enough to check by machine.

from itertools import product

def same(f, g, n):
    for values in product([0, 1], repeat=n):
        if f(*values) != g(*values):
            return "differ at " + str(values)
    return "equal for all " + str(2 ** n) + " inputs"

# De Morgan: (A + B)' = A'B'
print("De Morgan:", same(lambda a, b: 1 - (a | b), lambda a, b: (1 - a) & (1 - b), 2))
# A wrong 'law': (AB)' = A'B'
print("Wrong law:", same(lambda a, b: 1 - (a & b), lambda a, b: (1 - a) & (1 - b), 2))
Open in compiler
from itertools import product

for a, b in product([0, 1], repeat=2):
    f = ((1 - a) & b) | (a & b) | (a & (1 - b))     # A'B + AB + AB'
    print(a, b, "F =", f, " A + B =", a | b)
Open in compiler

The next lessons give a systematic way to simplify: canonical forms and Karnaugh maps.

Common mistakes

  • Writing (AB)' = A'B'. De Morgan swaps the operator: (AB)' = A' + B'.
  • "Cancelling" like in ordinary algebra: from A + B = A + C you cannot conclude B = C (try A = 1).
  • Forgetting that AB means AND, not a two-letter variable.

Quick check

1. By De Morgan's law, (A + B)' equals:
2. What is A + AB?
3. What is A · A'?
4. How do you prove two Boolean expressions equal without algebra?

Practice problems for this lesson

My notes

Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.