The Thinking Machine Chronicles #0002: Electricity Learns to Think: Shannon's Boolean Algebra for Circuits

ENIAC (1945), the room-sized electronic computer whose very existence depended on Shannon's insight that Boolean algebra and switching circuits speak the same language. Paul W. Shaffer, University of Pennsylvania, CC BY-SA 3.0, via Wikimedia Commons.
Era 1 · The Foundations (1936–1955) An engineer reads a mathematician. A century of abstract algebra becomes silicon.
The World in 1937
Nineteen thirty-seven was a year of creeping catastrophe. Japan invaded China in July; the Hindenburg had burned in May; Picasso completed Guernica in response to the bombing of a Basque town. In the United States, the New Deal was reshaping the economy, and AT&T's Bell Labs was at the height of its influence over the world's telecommunications infrastructure. At MIT, a 21-year-old master's student named Claude Shannon was working in the differential analyser lab, a room-sized mechanical computer made of gears, shafts, and spinning discs, and noticing that something was deeply inefficient about the way relay switching circuits were designed. Engineers were building them by trial and error, intuition, and costly physical prototyping. Shannon believed there had to be a better way. He was right, and the tool he reached for had been sitting unused in a mathematics library since 1854.
The Tool: Boolean Algebra
George Boole published An Investigation of the Laws of Thought in 1854. He showed that logical reasoning, the classical Aristotelian syllogism, could be reduced to algebraic manipulation of symbols constrained to one of two values: true and false (or equivalently, 1 and 0). Boole's algebra had three fundamental operations:
- Conjunction (logical AND): iff both and
- Disjunction (logical OR): iff at least one of equals 1
- Complement (logical NOT):
Boole's algebra obeyed a set of elegant laws. For any , , :
| Law | AND form | OR form |
|---|---|---|
| Identity | ||
| Null | ||
| Idempotency | ||
| Complement | ||
| Commutativity | ||
| Associativity | ||
| Distributivity | ||
| De Morgan |
For eighty years after Boole, this algebra was used almost exclusively by logicians. It was beautiful mathematics. But no one had connected it to anything physical.
Shannon's Key Insight
Shannon's master's thesis, submitted to MIT in November 1937 and published in the Transactions of the American Institute of Electrical Engineers in 1938, established a precise, one-to-one correspondence between Boolean algebra and switching circuits:
| Boolean concept | Physical counterpart |
|---|---|
| Variable | Switch (open = 0, closed = 1) |
| Two switches in series | |
| Two switches in parallel | |
| Normally-closed relay contact | |
| Boolean expression | Circuit schematic |
| Algebraic simplification | Fewer relays, less wire, lower cost |
Under this correspondence, every relay circuit is a Boolean function , and every Boolean function can be realised as a relay circuit. The mapping was not approximate or metaphorical; it was exact.
This meant that engineers could:
- Describe a circuit as a Boolean expression.
- Simplify the expression using algebraic laws.
- Build the simplified expression: fewer components, lower cost, greater reliability.
Before Shannon, simplifying a relay circuit required physically rewiring the hardware. After Shannon, it required algebraic manipulation on paper.
Truth Tables and Canonical Forms
A Boolean function of variables is completely specified by its truth table, the -row table listing the output for every possible input combination. From a truth table, two canonical forms follow mechanically:
Sum of Products (SOP): Write a product term (minterm) for each row where the output is 1. Each minterm is the product of all variables, complemented for each input variable that equals 0 in that row. The SOP is the disjunction of all minterms.
For the majority function iff at least two inputs equal 1:
| Minterm | ||||
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | : |
| 0 | 0 | 1 | 0 | : |
| 0 | 1 | 0 | 0 | : |
| 0 | 1 | 1 | 1 | |
| 1 | 0 | 0 | 0 | : |
| 1 | 0 | 1 | 1 | |
| 1 | 1 | 0 | 1 | |
| 1 | 1 | 1 | 1 |
Simplifying by applying distributivity and complement laws:
This is the minimum SOP form: three 2-input AND gates feeding a 3-input OR gate, versus the four 3-input AND gates the canonical form required.
The Full Adder: Boolean Algebra Meets Arithmetic
The most important combinational circuit is the full adder, a 3-input, 2-output circuit that adds two bits and a carry-in, producing a sum bit and a carry-out. Cascaded in sequence, full adders form the ripple-carry adder, the simplest integer arithmetic unit, which became the foundation of every CPU's ALU (arithmetic logic unit).
For inputs , , and :
where denotes XOR ().
The sum is a 3-way XOR: 1 iff an odd number of inputs are 1. The carry is 1 iff at least two inputs are 1, the majority function again. You can verify this against the truth table:
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
Shannon's Expansion Theorem
Beyond simplification, Shannon's thesis introduced what is now called the Shannon expansion (or cofactor decomposition). For any Boolean function and any variable :
The two functions and are called the positive and negative cofactors of with respect to . This expansion is recursive: apply it again to the cofactors, splitting on another variable, and you build a binary tree of sub-functions. Applied exhaustively, this tree is a Binary Decision Diagram (BDD), the data structure at the heart of hardware verification tools used by Intel, ARM, and every chip designer in the world.
When Intel verifies that the Pentium 4 multiplier is correct before taping out a $2 billion chip, it uses BDDs. Shannon's 1937 theorem is what makes that verification computationally tractable.
De Morgan's Laws and NAND Completeness
One of the most practically significant identities in Shannon's framework is De Morgan's theorem, which he systematically applied to circuit transformation:
De Morgan's laws have a remarkable consequence for hardware design: the NAND gate (which computes ) is functionally complete. Every Boolean function, AND, OR, NOT, XOR, and any combination thereof, can be expressed using only NAND gates. Similarly for NOR. This is why early transistor-transistor logic (TTL) integrated circuits were manufactured almost entirely as NAND and NOR gates. Fewer part types, simpler manufacturing, universal capability.
NAND universality in practice: Intel's 4004 (1971) and the entire family of 7400-series TTL chips were designed with NAND-centric logic families. The functional completeness of NAND, which Shannon's framework makes rigorous, was the direct economic driver of the transistor-count reduction that made affordable CPUs possible.
The Code
The Python implementation below models the formal circuit algebra. Each Gate is a composable object that evaluates recursively over a variable assignment, following the same evaluation semantics as Shannon's correspondence.
from typing import Callable, Dict, FrozenSet
import itertools
class Gate:
"""
A single logic gate: f: {0,1}^n → {0,1}.
Inputs can be variable names (str), booleans, or other Gates.
"""
def __init__(self, name: str, fn: Callable[..., bool], *inputs):
self.name = name
self.fn = fn
self.inputs = inputs
def evaluate(self, assignment: Dict[str, bool]) -> bool:
resolved = [
inp.evaluate(assignment) if isinstance(inp, Gate)
else assignment[inp] if isinstance(inp, str)
else bool(inp)
for inp in self.inputs
]
return self.fn(*resolved)
def variables(self) -> FrozenSet[str]:
result = set()
for inp in self.inputs:
result |= inp.variables() if isinstance(inp, Gate) else {inp} if isinstance(inp, str) else set()
return frozenset(result)
def truth_table(self):
vars_sorted = sorted(self.variables())
return [
(dict(zip(vars_sorted, vals)), self.evaluate(dict(zip(vars_sorted, vals))))
for vals in itertools.product([False, True], repeat=len(vars_sorted))
]
# Full adder
def XOR(a, b): return a != b
def AND(*args): return all(args)
def OR(*args): return any(args)
xor_ab = Gate("xor_ab", XOR, "A", "B")
sum_gate = Gate("sum", XOR, xor_ab, "Cin")
and_ab = Gate("and_ab", AND, "A", "B")
cout = Gate("cout", OR, and_ab, Gate("xor_cin", AND, xor_ab, "Cin"))
The full project includes the majority circuit, a 2-bit ripple-carry adder, verification of De Morgan's laws, the Shannon cofactor expansion, and a truth table generator for arbitrary Boolean expressions.
Why It Mattered
Shannon's thesis is, by a fair accounting, the most important master's thesis in the history of science. Claude Shannon was 21 when he wrote it. It did three things that together define the entire digital age:
It gave engineers a mathematical language. Before 1938, circuit design was a craft. After Shannon, it was algebra. Complex circuits could be described, compared, and optimised using pencil and paper before a single component was ordered.
It enabled reliable minimisation. Boolean simplification reduces the number of gates in a circuit, which reduces cost, power consumption, propagation delay, and failure probability. Every chip that has ever been manufactured has been designed using techniques that trace back to Shannon's algebraic framework.
It unified logic and engineering. Boole's abstract logic, designed to capture human reasoning, turned out to be the exact language of physical switching. The bridge between mind and machine was mathematical, and it had been waiting in a library for eighty years. Shannon saw it.
Without Shannon's thesis, there is no digital computer as we know it. Not the vacuum tube machines of the 1940s, not the transistor machines of the 1960s, not the VLSI chips of the 1980s. They all build on this 71-page document written by a graduate student who noticed that relay circuits had something to do with algebra.
What Came Next
The algebraic framework was in place. The next question was whether a physical machine could be built that embodied Turing's universal machine. In 1938, Konrad Zuse, a German civil engineer working in his parents' living room, built the Z1: the world's first programmable, electromechanical computer. That story is next: The Thinking Machine Chronicles #0003: Gears and Logic.
The Original Thesis
C. E. Shannon, "A Symbolic Analysis of Relay and Switching Circuits," Transactions of the American Institute of Electrical Engineers, Vol. 57 (1938), pp. 713–723.
Originally submitted as Shannon's master's thesis at MIT in November 1937. Howard Gardner called it "possibly the most important, and also the most famous, master's thesis of the [twentieth] century." Available via IEEE Xplore (paywalled) and through many university library proxies.
References
- Shannon, C. E. (1938). A Symbolic Analysis of Relay and Switching Circuits. Transactions of the AIEE, 57, 713–723.
- Boole, G. (1854). An Investigation of the Laws of Thought. Walton and Maberly, London. The source of Boolean algebra; freely available on Project Gutenberg.
- Rota, G.-C. (1997). The many lives of lattice theory. Notices of the AMS, 44(11), 1440–1445. On the algebraic structure Shannon was drawing on.
- Shannon, C. E., & Weaver, W. (1949). A Mathematical Theory of Communication. University of Illinois Press. Shannon's later information theory work, which built on the same algebraic foundations.
- Knuth, D. E. (1997). The Art of Computer Programming, Vol. 2: Seminumerical Algorithms (3rd ed.). Addison-Wesley. Chapter 4 covers Boolean function minimisation.
- Bryant, R. E. (1986). Graph-Based Algorithms for Boolean Function Manipulation. IEEE Transactions on Computers, 35(8), 677–691. The BDD paper; the direct descendant of Shannon expansion.