Fundamentals of Quantum Computation
Page 01 set up probabilistic computing as a vector of 2ⁿ non-negative probabilities pushed around by stochastic matrices. Page 03 gave the physics: amplitudes, the Born rule, entanglement. This page puts the two together into the circuit model that every later page assumes. If you can follow the matrices here, pages 05 and 06 are bookkeeping on top: Shor and chemistry are bigger interference patterns, and error correction is the engineering of keeping those patterns intact.
The state: one rule different from a randomized computer
A randomized machine with n bits is, at any moment, described by a probability vector p ∈ ℝ^(2ⁿ), entries non-negative, summing to 1. A step is a stochastic matrix M (non-negative entries, columns summing to 1), and p ← M p. The machine is only ever in one of the 2ⁿ configurations; the vector describes your ignorance.
A quantum machine with n qubits is described by an amplitude vector:
A step is a unitary U, a complex matrix with U†U = I, and |ψ⟩ ← U|ψ⟩. Unitaries are exactly the linear maps that preserve the L2 norm, the way stochastic matrices are the maps that preserve L1 norm and non-negativity. The vector is not a summary of ignorance here: it is the state, and there is no hidden local "real" configuration underneath it (that is what Bell experiments rule out, page 03).
| Randomized (page 01) | Quantum (this page) | |
|---|---|---|
| State | p ∈ ℝ^(2ⁿ), p_x ≥ 0 | a ∈ ℂ^(2ⁿ) |
| Norm kept | Σ p_x = 1 (L1) | Σ |a_x|² = 1 (L2) |
| Step | stochastic M | unitary U, U†U = I |
| Reversible? | generally no | always (U⁻¹ = U†) |
| Readout | x with prob p_x | x with prob |a_x|² |
| Paths combine by | adding probabilities | adding amplitudes, then squaring |
The last row is the difference that matters. In a randomized machine the probability of an outcome is a sum of non-negative path weights, so more paths can only make it more likely. In a quantum machine you add complex amplitudes along paths and square at the end, so two paths of equal size and opposite sign contribute zero. Nothing else on this page is as important.
Two housekeeping facts. A global phase is unobservable: e^{iγ}|ψ⟩ gives the same statistics as |ψ⟩, which is why one qubit has two real degrees of freedom, the Bloch angles in |ψ⟩ = cos(θ/2)|0⟩ + e^{iφ} sin(θ/2)|1⟩. Relative phases between basis states are observable, because a later gate can turn them into differences in magnitude.
Tensor products and entanglement, as linear algebra
Two systems combine by the tensor (Kronecker) product. For one qubit in (a, b) and another in (c, d), the joint state is
so the dimension multiplies, 2 · 2 = 4, and n qubits live in ℂ^(2ⁿ). In numpy this is np.kron, with the first qubit as the most significant bit of the index. A gate on one qubit of many is I ⊗ … ⊗ U ⊗ … ⊗ I; a simulator never builds that 2ⁿ×2ⁿ matrix, it reshapes the state into an n-dimensional 2×2×…×2 tensor and contracts U against one axis.
Most vectors in ℂ⁴ are not of the product form above. An easy test: reshape the four amplitudes into a 2×2 matrix [[a₀₀, a₀₁], [a₁₀, a₁₁]]. A product state has rank 1 (determinant zero). The Bell state
has rank 2, so it cannot be written as one qubit's state times the other's. That is all "entangled" means operationally: the joint vector does not factor. For n qubits the rank across each cut (the Schmidt rank) is what tensor-network simulators exploit; low entanglement means a compact representation, and a state that is highly entangled across every cut is where classical simulation runs out of road.
That road is short. A dense statevector of n qubits in complex128 needs 16 · 2ⁿ bytes: 16 GiB at n = 30, 16 TiB at n = 40, 16 PiB at n = 50. Every added qubit doubles it.
The gates, and the worked example
Single-qubit gates are 2×2 unitaries acting on (α, β). The ones you meet everywhere:
X is NOT. Z flips the sign of the |1⟩ amplitude, a pure relative phase. Y is iXZ. S and T are smaller phase turns, with T² = S and S² = Z. H is the workhorse: it maps |0⟩ → |+⟩ = (|0⟩+|1⟩)/√2 and |1⟩ → |−⟩ = (|0⟩−|1⟩)/√2, and is its own inverse.
The two-qubit gate is CNOT, which flips the target when the control is 1. In the basis order |00⟩, |01⟩, |10⟩, |11⟩ with the control first:
CNOT is a permutation, so it is the reversible classical XOR from page 01 and nothing more until its input is in superposition. Then CNOT (H ⊗ I)|00⟩ = (|00⟩ + |11⟩)/√2: a Hadamard and a classical gate make a Bell state. Toffoli (controlled-controlled-NOT) is also a permutation, which is why every classical reversible circuit is already a quantum circuit.
Worked example: H, then H again. Start at |0⟩ = (1, 0).
After one H, measuring gives 0 or 1 with probability ½ each, exactly like a fair coin. After two, you get 0 with certainty. Trace the paths: from |0⟩ there are two routes to |1⟩, via 0 (amplitude (1/√2)(1/√2) = +½) and via 1 (amplitude (1/√2)(−1/√2) = −½). They cancel. The two routes to |0⟩ are both +½ and add to 1.
Now do the classical version: the fair-coin stochastic matrix [[½, ½], [½, ½]] applied twice to (1, 0) gives (½, ½) and stays there. Randomness composed with randomness is more randomness. A Hadamard composed with a Hadamard is the identity. Same single-step statistics, opposite two-step behaviour, and the whole gap is the minus sign in the bottom-right of H.
Circuits and universality: Clifford is free, T is the price
A circuit is a sequence of gates on wires, read left to right, with measurements at the end. Its size is the gate count and its depth is the number of layers, the same measures as page 01. A gate set is universal if it can approximate any unitary on any number of qubits to any accuracy ε.
The set that matters for fault tolerance is Clifford + T: H, S and CNOT generate the Clifford group, and adding T makes it universal. One qubit gates plus CNOT are exactly universal (Barenco et al. 1995). A finite set can only be approximately universal, but the Solovay–Kitaev theorem says the approximation is cheap: any single-qubit unitary to accuracy ε needs only polylog(1/ε) gates, so going from 10⁻³ to 10⁻⁹ accuracy multiplies the gate count by a small factor, not by a million.
Now the surprise. The Gottesman–Knill theorem says a circuit built only from Clifford gates, starting in |0…0⟩ and measured in the computational basis, can be simulated efficiently on a classical computer, even though it can create highly entangled states. The trick is to track not the 2ⁿ amplitudes but the n Pauli operators the state is a +1 eigenvector of (its stabilizers), an n×2n binary tableau that each Clifford gate updates in O(n) bit operations. Aaronson and Gottesman's simulator handles thousands of qubits on a laptop.
So entanglement alone is not the resource, and neither is superposition. Clifford circuits have plenty of both and are classically easy. What they lack is a gate outside the Clifford group, and T is the standard choice. Known classical simulators of Clifford+T circuits scale exponentially in the number of T gates, not the number of qubits. Hence the industry habit of counting algorithms in T gates (or Toffolis) and calling them "magic": in a fault-tolerant machine Cliffords are comparatively cheap, while each T is made by consuming a specially prepared "magic state" T|+⟩ that has to be distilled from noisy copies (Bravyi and Kitaev, arXiv 2004). Page 06 prices that factory.
Measurement, and why you cannot read out 2ⁿ numbers
Measuring all n qubits returns one bitstring x with probability |a_x|² and leaves the register in |x⟩. The other 2ⁿ − 1 amplitudes are gone. Measuring one qubit of several returns a bit and renormalises the remaining amplitudes consistent with it. Measurement is the only non-unitary, irreversible step in the model, and it is usually pushed to the end of the circuit (the deferred-measurement principle says you lose nothing by doing so).
This is why "the computer tries all 2ⁿ inputs in parallel" is a misleading description. You can certainly prepare a state whose amplitudes encode f(x) for every x. You cannot get them out. Each run is one sample. To estimate one amplitude's magnitude to precision ε you need on the order of 1/ε² runs, exactly as with a classical Monte Carlo estimate.
The hard limit is the Holevo bound: n qubits, with no entanglement shared in advance with the receiver, can deliver at most n bits of classical information, however they were prepared. (With pre-shared entanglement, superdense coding gets 2 bits per qubit, and no more.) 2ⁿ amplitudes in, n bits out. The exponential state space is a workspace, not a storage medium. Page 05's warning about "loading big data into a quantum computer" follows directly: input costs you at least time linear in the data, and output costs you at most n bits per run.
Phase kickback, and interference doing real work
Quantum algorithms access a function f through an oracle, a unitary that computes f reversibly:
Put the target qubit in |−⟩ and something useful happens. If f(x) = 0 the target is unchanged; if f(x) = 1 it becomes (|1⟩ − |0⟩)/√2 = −|−⟩. Either way:
The target is untouched and the answer has been written as a sign on the control register. That is phase kickback: an oracle that "writes to the target" acts, in the right basis, as a phase on the input. Signs are exactly what interference needs, and the same trick, with controlled powers of a unitary instead of a Boolean oracle, is the engine of phase estimation and Shor's algorithm (page 05).
Bernstein–Vazirani is the cleanest example of interference doing work. A hidden string s ∈ {0,1}ⁿ defines f(x) = s·x mod 2. Classically each query returns one bit, so even a randomized algorithm needs n queries. The quantum algorithm uses one:
Step 3 is the key identity: H^⊗n|x⟩ = 2^(−n/2) Σ_z (−1)^(x·z)|z⟩, and a sum of ±1 over all x is zero unless every sign agrees. For n = 2 and s = 10 you can do it by hand: after the oracle the amplitudes on 00, 01, 10, 11 are ½(+1, +1, −1, −1), which is the product |−⟩ ⊗ |+⟩, and H ⊗ H sends it to |1⟩ ⊗ |0⟩ = |10⟩. Every wrong answer's amplitude cancels to exactly zero.
Deutsch–Jozsa is the same circuit asked a different question: is f constant or balanced (promised to be one or the other)? The amplitude on |0ⁿ⟩ at the end is 2^(−n) Σ_x (−1)^{f(x)}, which is ±1 for constant f and 0 for balanced f. One query, certain answer, against 2^(n−1) + 1 queries for a deterministic classical algorithm. Be honest about it, though: a randomized classical algorithm that tries a handful of random inputs gets the answer with high confidence, so Deutsch–Jozsa's exponential gap only holds against exact classical algorithms. Bernstein–Vazirani's n-to-1 gap survives randomization but is only polynomial. Both are teaching examples, not applications. The exponential separations that matter (Simon's problem, then Shor) use the same skeleton on a richer hidden structure: Simon keeps the Hadamard layers but hides an XOR period, and Shor replaces them with a quantum Fourier transform over ℤ_N to find a modular period.
The shape of every quantum algorithm
Strip the examples back and the template is always the same, and it is worth keeping as a checklist for anything a vendor calls a quantum algorithm:
| Step | What happens | Where it goes wrong |
|---|---|---|
| Prepare | make a structured superposition (often H^⊗n) | loading arbitrary data costs time ≥ its size |
| Compute | a reversible oracle or Hamiltonian evolution | needs ancillas and uncomputation; T-count is the cost |
| Kick back | results become phases on the input register | only works if the problem has the right structure |
| Interfere | H^⊗n, QFT, or a Grover reflection | no structure → only quadratic gain (Grover) |
| Measure | one sample, concentrated on the answer | n bits out per run, at most |
The question to ask of any proposal is: what is the interference pattern, and why does it concentrate on the answer? If the honest response is "we put all the data in superposition," there is no algorithm yet. Page 05 goes through the cases where there is one (period finding, simulation) and the cases where the answer is only quadratic or unknown (search, optimisation, machine learning). Page 06 is about what it costs to keep a 2ⁿ-dimensional vector from leaking into its environment for the billions of gates those algorithms need.
Sources and further reading, verified
- Quantum Computation and Quantum Information — Nielsen & Chuang (2010, 10th anniversary ed.) · the standard text; chapters 1, 2 and 4 cover everything on this page in more depth.
- Lecture notes for Physics 219/229: Quantum Information and Computation — John Preskill (Caltech, ongoing) · free, rigorous notes; the chapters on circuits and on the Holevo bound are the reference treatment.
- Introduction to Quantum Information Science, lecture notes — Scott Aaronson (2018) · written for computer scientists; the clearest account of amplitudes versus probabilities and of why "try every input" is wrong.
- Quantum Algorithms Revisited — Cleve, Ekert, Macchiavello & Mosca (1998) · introduced the phase-kickback view and recasts Deutsch–Jozsa and Shor in one interference framework.
- Elementary gates for quantum computation — Barenco et al. (1995) · proves one-qubit gates plus CNOT are universal, and builds Toffoli from them.
- The Solovay–Kitaev algorithm — Dawson & Nielsen (2005) · a readable proof and implementation of why a finite gate set approximates any unitary with polylog(1/ε) gates.
- The Heisenberg Representation of Quantum Computers — Gottesman (1998) · the stabilizer formalism and the Gottesman–Knill theorem.
- Improved Simulation of Stabilizer Circuits — Aaronson & Gottesman (2004) · the tableau simulator that makes Clifford circuits on thousands of qubits classically routine.
- Universal Quantum Computation with ideal Clifford gates and noisy ancillas — Bravyi & Kitaev (2004) · magic states and their distillation: why T is the expensive gate in a fault-tolerant machine.
Check yourself
- A 30-line statevector simulator code — In numpy, store n qubits as a complex array of shape (2,)*n. Write apply_1q(state, U, k) with np.tensordot plus np.moveaxis, and apply_cnot(state, c, t) by indexing. Check: H twice on |0⟩ returns |0⟩; H then CNOT on |00⟩ gives amplitude 1/√2 on 00 and 11 only; Bernstein–Vazirani with n = 8 and a random s returns s with probability 1 (implement the oracle as Z on each qubit where s_i = 1, which is phase kickback already applied). A good answer also notes where the memory goes at n = 30.
- Coin versus Hadamard — Apply the fair-coin stochastic matrix twice and H twice to (1, 0). Then show that no stochastic matrix that takes (1, 0) to (½, ½) can take (½, ½) back to (1, 0) (hint: the first column is fixed, then solve for the second). A good answer names the exact property (non-negativity, no cancellation) that makes the classical case irreversible here.
- Why is this one easy? — A circuit on 1,000 qubits uses only H, S and CNOT, with 10⁶ gates, then measures everything. Explain why a laptop can sample from it, what data structure it tracks, and what changes when you add 40 T gates, then 4,000. A good answer says the cost grows with T count, not qubit count, and connects that to why fault-tolerant resource estimates report T or Toffoli counts.
- Shots — A circuit's output bitstring 0110 has true probability 0.30. How many runs do you need so that the estimated frequency has a standard error of 0.005 (roughly ±0.01 at 95%)? (Answer: N ≥ 0.3·0.7 / 0.005² = 8,400.) Relate this to the Holevo bound: why does every quantum algorithm worth having end with an output distribution concentrated on few strings?