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
| Law | OR form | AND form |
|---|---|---|
| Identity | A + 0 = A | A · 1 = A |
| Null | A + 1 = 1 | A · 0 = 0 |
| Idempotent | A + A = A | A · A = A |
| Complement | A + A' = 1 | A · A' = 0 |
| Double negation | (A')' = A | |
| Commutative | A + B = B + A | AB = BA |
| Distributive | A(B + C) = AB + AC | A + BC = (A + B)(A + C) |
| Absorption | A + AB = A | A(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))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)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
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.