Models of Computation
Models of Computation
Before we can ask what a quantum computer can do faster, we must pin down what "compute" even means. A model of computation is a precise mathematical object — a machine, a circuit, an algebra — against which we measure every claim of correctness and efficiency. The deep surprise of the 20th century is that the most natural-looking models all compute exactly the same functions. The deep surprise of the late 20th century is that they may not all compute them equally fast — and that is the door quantum computing walks through.
Learning Objectives
By the end of this lesson you will be able to:
- Define a deterministic Turing machine (DTM) by its tape, states, and transition function, and hand-simulate one step.
- Define the Boolean circuit model and contrast its non-uniformity with the uniformity of a Turing machine.
- Prove that is functionally complete (universal) for Boolean functions, and build XOR from NANDs.
- State the Church–Turing thesis and distinguish it from the Extended (efficiency) form.
- Explain precisely which thesis quantum computing is conjectured to violate, and why classical models are robust under the polynomial-time-equivalence relation that the Extended thesis demands.
Intuition
You already know algorithms operationally: you write Python, it runs. But "an algorithm" as a mathematical object needs a substrate. Three substrates dominate, and they form a ladder of abstraction:
- Turing machine (TM) — a single, fixed finite program scanning an unbounded tape. One machine handles inputs of every length. This is the model of uniform computation and the gold standard for "computable."
- Boolean circuit — a finite acyclic network of AND/OR/NOT gates wired to a fixed number of input bits. Each input length needs its own circuit ; a family computes a function on all lengths. This is non-uniform hardware.
- Boolean algebra — the algebra of bits the circuit gates obey. The pivotal structural fact is that one humble gate, NAND, suffices to express the entire algebra.
The reason to learn all three is that quantum computing borrows from each: the circuit model becomes the quantum circuit (Term 2), reversible gates (next lesson) sit between Boolean algebra and unitary gates, and the efficiency question — does a quantum TM solve some problem polynomially faster than any classical one? — is a statement about the Extended Church–Turing thesis that we set up at the end.
A guiding analogy: a Turing machine is a recipe (one document, works for any quantity of ingredients); a circuit is a factory line hard-wired for one batch size. They are inter-translatable, but the translation has a cost, and cost is the whole story of complexity.
Theory
1. The deterministic Turing machine
A deterministic Turing machine is a 7-tuple [Sip §3.1], [AB §1.2]
where
- is a finite set of control states;
- is the input alphabet (e.g. ), with the blank symbol ;
- is the tape alphabet;
- is the start state, and are the halting states (accept / reject), ;
- is the transition function.
The machine has a two-way infinite tape of cells, each holding one symbol of , and a head positioned over one cell. The tape begins with the input written left-to-right and everywhere else; the head starts on the leftmost input cell in state .
A configuration captures the entire instantaneous state: the control state, the tape contents, and the head position. We write it , meaning the tape reads (then blanks), the head is on the first symbol of , and the control is in state .
One step. If , then in state scanning symbol the machine (i) overwrites with , (ii) moves the head one cell in direction , and (iii) enters state . Because is a function (single-valued), the next configuration is unique — this is exactly what deterministic means. The machine halts on reaching (accept) or (reject); it may also run forever.
The machine decides a language if it halts on every input and accepts exactly the strings in . The time is the number of steps before halting; the space is the number of distinct tape cells visited. These two cost measures are the seeds of all complexity theory (next lesson).
Why this primitive model? It is deliberately minimal so that anything it cannot do is provably uncomputable, and so that its time/space costs are unambiguous. Realistic features (multiple tapes, random access, a CPU) only change running time by a polynomial factor — a fact we will lean on heavily.
2. The Boolean circuit model
A Boolean circuit on inputs is a directed acyclic graph (DAG) whose [AB §6.1]
- source nodes are the input variables (and optionally constants );
- internal nodes are gates labelled from a basis, classically (AND, OR, NOT), with the in-degree (fan-in) matching the gate's arity;
- one node is designated the output (multi-output circuits designate several).
The circuit computes a function by evaluating gates in topological order. Two cost measures dominate:
- size number of gates (analogue of time);
- depth longest input-to-output path (analogue of parallel time).
The crucial structural difference from a TM is non-uniformity. A single circuit has a fixed number of input wires, so it only handles inputs of one length . To compute a function on all lengths we need a circuit family , one circuit per length. There is no a priori requirement that the be related, let alone generated by a single finite program. That freedom makes circuit families strictly more powerful in principle (they can even compute undecidable functions, by hard-wiring the answer into each ) — which is precisely why, when we use circuits as a complexity model, we impose uniformity: a single TM must output the description of given . Uniform polynomial-size circuit families turn out to be equivalent to polynomial-time TMs [AB §6.2].
The quantum circuit model (Term 2) is the direct descendant of this picture: replace Boolean gates with unitary gates on qubit wires. The same uniformity caveat applies. See Term 2.1 · Single-Qubit Gates.
3. Boolean algebra and functional completeness
The gates obey Boolean algebra: the two-element algebra with identities such as , , the distributive laws, and the De Morgan duality .
A set of gates is functionally complete (universal) if every Boolean function can be expressed using only those gates. The standard basis is complete, via the disjunctive normal form (DNF): for any ,
Each clause is an AND of literals that is true on exactly one input ; OR-ing the true rows reconstructs . (If the empty disjunction is .) This is a complete constructive proof that is universal.
Theorem (NAND is universal)
Let . The single gate is functionally complete.
Proof. It suffices to reconstruct from NAND, since that set is already complete. Write .
- NOT. Feed both inputs the same wire:
- AND. Negate the NAND of the inputs:(We used the just-proved NOT on the wire .)
- OR. By De Morgan, . Substituting the NOT construction,
Since is complete and each is now a NAND expression, is complete.
The identical argument shows (with ) is universal, using the dual De Morgan law. NAND/NOR universality is why physical logic families are built almost entirely from one gate type. By contrast, alone is not complete: both gates are monotone (flipping an input from to never flips the output ), so they can only build monotone functions — and is not monotone. This monotonicity argument is a clean example of a "no-go" proof by an invariant, a style we will reuse for no-cloning later.
Building XOR from NAND
. A compact, classic 4-NAND realization is
We verify it exhaustively in the code section (the surest proof for a small Boolean identity is the truth table).
4. The Church–Turing thesis, and its extended form
The models above — TMs, uniform circuits, the -calculus, general recursive functions, your Python interpreter — all compute exactly the same class of functions. This empirical robustness is crystallized as a thesis (not a theorem — it relates the informal notion "effectively computable" to a formal one):
Church–Turing thesis (CTT). Every function that can be computed by any physically realizable effective procedure is computable by a Turing machine.
The CTT is about what is computable, ignoring efficiency. There is a sharper, far more fragile claim about how fast:
Extended (Strong) Church–Turing thesis (ECT). Every physically realizable model of computation can be simulated by a (probabilistic) Turing machine with at most polynomial overhead in time.
The ECT says the class of efficiently solvable problems — not just the class of solvable ones — is model-independent. It is what licenses us to speak of "polynomial time" as a robust, machine-independent notion: RAM machines, multi-tape TMs, your laptop, all simulate one another with polynomial slowdown, so they agree on . The ECT is the backbone of the next lesson.
Where quantum enters. A quantum Turing machine (equivalently, a uniform family of quantum circuits) is also physically realizable, in principle. The class of problems it solves efficiently is (Term 3.6). Shor's polynomial-time factoring algorithm gives strong evidence that
i.e. that a quantum machine is not polynomially simulable by any classical probabilistic one. If true, this refutes the Extended Church–Turing thesis (the efficiency form) — while leaving the original CTT untouched, because a quantum computer still computes only Turing-computable functions (a classical TM can simulate it, just with exponential overhead). Pinning down "where quantum fits" is the punchline of the next two lessons and of Term 3.6 · BQP & Quantum Complexity.
Worked Examples
Example 1 — Hand-tracing a Turing machine
Consider a DTM over that flips every bit of its input (a unary NOT on the whole string) and halts. Two non-halting states suffice; we sweep right flipping bits until a blank.
Trace on input . We write the configuration as (head on first symbol of ):
Output tape: — indeed bitwise. The machine ran in steps and used cells: linear time and space. This linear cost is the point — the TM definition makes "how long did it take" a counting question with no ambiguity.
Example 2 — Universality and a non-universal basis
(a) Express the 2-input multiplexer ("output if , else ") in the standard basis — it already is — and note that by NAND universality it has a pure-NAND realization. Concretely, using De Morgan on the outer OR,
because and likewise for the other term, and the outer NAND combines them as . So a 3-to-1 selector is just three NANDs plus one inverter.
(b) Show cannot compute . Every function built from (and the inputs) is monotone: if coordinatewise then , by induction on the circuit ( and are each monotone in both arguments, and inputs are trivially monotone). But violates monotonicity since . Hence no -circuit computes NOT, so the basis is not functionally complete.
Hands-on (Python)
Self-contained, dependency-free. We (1) evaluate small Boolean circuits over a NAND basis, including
the 4-NAND XOR, verifying it against Python's ^; and (2) implement a toy single-step Turing
machine that reproduces Example 1.
"""Models of Computation — runnable demos (plain Python, no dependencies)."""
# ---------------------------------------------------------------------------
# Part A. NAND universality: build NOT, AND, OR, and XOR from NAND alone,
# then verify each against Python's native operators over all inputs.
# ---------------------------------------------------------------------------
def NAND(a: int, b: int) -> int:
"""The one universal gate: NAND(a, b) = NOT (a AND b)."""
return 1 - (a & b) # a, b in {0,1}; result in {0,1}
def NOT(x: int) -> int:
return NAND(x, x) # x↑x = ¬x
def AND(x: int, y: int) -> int:
t = NAND(x, y)
return NAND(t, t) # ¬(x↑y) = x∧y
def OR(x: int, y: int) -> int:
return NAND(NOT(x), NOT(y)) # De Morgan: (¬x)↑(¬y) = x∨y
def XOR(x: int, y: int) -> int:
"""Classic 4-NAND XOR: t = x↑y; out = (x↑t) ↑ (y↑t)."""
t = NAND(x, y)
return NAND(NAND(x, t), NAND(y, t))
def truth_table(f, arity):
"""Yield (inputs_tuple, output) over all 2**arity assignments."""
for n in range(2 ** arity):
bits = tuple((n >> (arity - 1 - i)) & 1 for i in range(arity))
yield bits, f(*bits)
# Verify the NAND-built gates against Python's reference semantics.
assert all(out == (1 - x) for (x,), out in truth_table(NOT, 1))
assert all(out == (x & y) for (x, y), out in truth_table(AND, 2))
assert all(out == (x | y) for (x, y), out in truth_table(OR, 2))
assert all(out == (x ^ y) for (x, y), out in truth_table(XOR, 2))
print("All NAND-built gates match their reference truth tables. ✓")
print("\nXOR truth table (built from 4 NANDs):")
for (x, y), out in truth_table(XOR, 2):
print(f" {x} XOR {y} = {out}")
# ---------------------------------------------------------------------------
# Part B. A toy deterministic Turing machine: one step at a time.
# We encode the configuration as (state, tape: dict[int,str], head: int) and
# run the bit-flip machine from Example 1.
# ---------------------------------------------------------------------------
BLANK = "_"
def step(delta, state, tape, head):
"""Apply one transition. Returns the next (state, tape, head)."""
symbol = tape.get(head, BLANK)
new_state, write, move = delta[(state, symbol)]
tape = dict(tape) # copy so each config is immutable
tape[head] = write
head += 1 if move == "R" else -1
return new_state, tape, head
def run(delta, start, accept, reject, w, max_steps=10_000):
"""Run until a halting state. Returns (accepted, final_tape_string, steps)."""
tape = {i: ch for i, ch in enumerate(w)} # input written left-to-right
state, head, steps = start, 0, 0
while state not in (accept, reject) and steps < max_steps:
state, tape, head = step(delta, state, tape, head)
steps += 1
# Render the written portion of the tape (min..max index touched).
lo, hi = min(tape), max(tape)
out = "".join(tape.get(i, BLANK) for i in range(lo, hi + 1)).strip(BLANK)
return state == accept, out, steps
# Example 1: flip every bit, then halt-accept on the first blank.
Q0, ACC, REJ = "q0", "qacc", "qrej"
bitflip_delta = {
(Q0, "0"): (Q0, "1", "R"),
(Q0, "1"): (Q0, "0", "R"),
(Q0, BLANK): (ACC, BLANK, "R"),
}
accepted, output, steps = run(bitflip_delta, Q0, ACC, REJ, "011")
print(f"\nTuring machine on '011': output={output!r}, accepted={accepted}, steps={steps}")
assert output == "100" and accepted and steps == 4
print("Matches the hand-trace in Example 1. ✓")Expected output (abridged):
All NAND-built gates match their reference truth tables. ✓
XOR truth table (built from 4 NANDs):
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
Turing machine on '011': output='100', accepted=True, steps=4
Matches the hand-trace in Example 1. ✓Exercises
Attempt before expanding. Difficulty escalates easy → hard.
1. (Easy) NOR universality. Prove that is functionally complete by expressing NOT, OR, and AND using only .
Solution
Write .
- NOT: .
- OR: .
- AND: by De Morgan .
Since is complete and each reduces to NORs, is complete.
2. (Easy–Medium) Counting NANDs. Using the constructions in the lesson, count how many NAND gates the expressions for AND, OR, and the 4-NAND XOR use. Then give a NAND realization of (material implication, ) and count its gates.
Solution
- AND uses 2 NANDs (, then ).
- OR uses 3 NANDs (, , then NAND of those).
- XOR uses 4 NANDs as written.
- . Note directly, and . So : 2 NANDs.
3. (Medium) Adding a TM transition. Modify the bit-flip DTM so that it instead rejects if the
input contains the substring 11, and accepts otherwise (it need not flip bits). Give the full
. (Hint: one extra state to remember "the previous symbol was a 1.")
Solution
States , where means "last symbol read was 1." Move right without writing (, write back the same symbol):
Reading two 1s in a row drives . Otherwise a blank is reached in
or and we accept. (You can verify by extending the run driver with these rules.)
4. (Medium) Uniform vs. non-uniform. Explain why an arbitrary circuit family can "compute" an undecidable language, yet no Turing machine can. What single requirement on the family closes this gap, and why?
Solution
Let be any (possibly undecidable) language. For each there are finitely many strings of length , so the restriction is some Boolean function , and every Boolean function has a circuit (DNF). Choosing to compute gives a family that decides — including undecidable like the halting set. The catch: there is no finite program producing the ; the family secretly contains the uncomputable information, one circuit at a time. Imposing uniformity — a single TM must output (a description of) on input in, say, polynomial time — forbids this, because then the family is generated by one finite, computable process. Uniform poly-size circuit families are exactly [AB §6.2].
5. (Hard) Which thesis does quantum threaten? A colleague claims "quantum computers can compute things classical computers can't." Sharpen or refute this using the CTT vs. ECT distinction, and state precisely what Shor's algorithm is and is not evidence for.
Solution
The claim is false as stated under the standard CTT: a classical Turing machine can simulate any quantum circuit (track the amplitudes, apply each gate as a matrix–vector product), so quantum computers compute exactly the same functions — the original CTT is unthreatened. What quantum may threaten is the Extended CTT (efficiency): the classical simulation costs exponential time and space. Shor's polynomial-time factoring is strong evidence that $\mathrm{BQP}\not\subseteq \mathrm{BPP}\mathrm{BPP}$), i.e. that no classical probabilistic machine simulates a quantum one with only polynomial overhead. That would refute the ECT — not the CTT. (It is evidence, not proof: factoring's classical hardness is itself unproven, and so is .) See Term 3.6.
6. (Hard) DNF size blow-up. Show that the DNF construction can produce a circuit of size in the worst case, and name a function achieving it. Why does this not contradict the existence of small circuits for most useful functions?
Solution
DNF has one clause per input with ; each clause is an AND of literals (plus the 's). If is on inputs — e.g. the parity function , which is on exactly half of all inputs — then DNF has clauses of width , so size . This is a property of the generic DNF method, not of the function: parity actually has a circuit of size (a chain of XOR gates, each NANDs). DNF is a universality witness (every has a circuit), not an efficient compiler. The whole subject of circuit complexity is finding small circuits; information-theoretic counting (Shannon) shows most -bit functions need size — but the functions we care about are rarely "most."
Checkpoint
1. What makes a Turing machine deterministic, and what object enforces it?
The transition is a single-valued function: each (state, scanned symbol) pair maps to exactly one (next state, write symbol, move). Hence each configuration has a unique successor.
2. State the key difference between a Turing machine and a circuit.
A TM is uniform: one finite program handles inputs of all lengths. A circuit is fixed to one input length ; computing on all lengths needs a family , which is non-uniform unless we explicitly require a single TM to generate the .
3. Prove in one line that NAND gives you NOT.
. Feeding the same wire to both NAND inputs yields the inverter.
4. Why is $\{\land,\lor\}$ not functionally complete?
Both gates are monotone, so any circuit over them computes a monotone function; but is non-monotone (, ). Hence NOT is unreachable.
5. Distinguish the Church–Turing thesis from its Extended form.
CTT: every effectively computable function is Turing-computable (about computability). ECT: every physically realizable model is simulable by a (probabilistic) TM with only polynomial overhead (about efficiency). The ECT is what makes machine-independent.
6. Which thesis does efficient quantum computation challenge, and why not the other?
The Extended (efficiency) form: a quantum machine appears not to be polynomially simulable classically (Shor). The original CTT survives because a classical TM still can simulate a quantum computer — only with exponential overhead — so the computable functions are unchanged.
Further Reading
- [Sip §3.1, §3.3] Sipser — Turing machines, configurations, the Church–Turing thesis. The cleanest first source for the DTM formalism used here.
- [AB §1.2, §6.1–6.2] Arora & Barak — Turing machines, the circuit model, uniformity, and the ↔ uniform poly-size circuits equivalence.
- [NC §3.1] Nielsen & Chuang — Turing machines and the (Extended) Church–Turing thesis, framed toward quantum computation; sets up the same "which thesis does quantum break" question.
- [Aar] Aaronson — Chs. on computability and complexity for the intuition behind the ECT and .
← Prev: Discrete Fourier Transform · Up: Term 0 · Next: Complexity Classes →