University Physics V · Introduction to Quantum Information · 20.6
Unitary Gates, Circuits & Universality
Every operation on a closed register is a unitary matrix, and that fact fixes what a gate can be: reversible, norm-preserving, and for one qubit a rotation of the Bloch sphere. Learn to build two-qubit gates by Kronecker product, to turn a circuit diagram into one matrix, and to say why H, T and CNOT build anything — and at what price.
Build the model
Connect the measurement to the mechanism.
A closed quantum system evolves by U = exp(−iĤt/ħ), and a gate is one such U, run for a chosen time. Unitarity, U†U = I, is therefore the whole content of the word gate: it preserves inner products, so probabilities stay normalised; it has the inverse U†, so every gate can be undone; and it is linear, so it can neither copy nor erase. For one qubit, U(2) is a global phase times SU(2), and SU(2) covers the rotations of the Bloch sphere twice, so every one-qubit gate is a rotation Rₙ(θ) = exp(−iθ n⋅σ/2) about some axis: X, Y and Z are half-turns about their own axes, H a half-turn about (x + z)/√2, S and T quarter- and eighth-turns about z.
Two qubits live in C² ⊗ C², where a gate on one qubit alone is a Kronecker product A ⊗ I, and CNOT is deliberately not of that form — it is |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ X, a sum, which is why it can raise Schmidt rank and entangle. A circuit is the matrix product of its gates in reverse reading order. Universality is then a density statement: {H, T, CNOT} generates a subgroup dense in U(2ⁿ), because T and HTH are eighth-turns about perpendicular axes whose composite turns through an irrational fraction of a revolution, while CNOTs plus one-qubit gates reach every two-level unitary.
The price is twofold: Solovay–Kitaev approximates a target to ε only with O(logc(1/ε)) gates, and a generic n-qubit unitary needs Θ(4ⁿ) CNOTs, whatever the compiler.
- Simple definition
- A quantum gate is a unitary operator on the state space of a qubit register — U†U = I — so it is linear, reversible and norm-preserving; a circuit is the product of its gates, and a gate set is universal when finite products of its members approximate every unitary to any chosen accuracy.
- Example
- H = (1/√2)[[1, 1], [1, −1]] is unitary since H†H = I, and H² = I; acting on the first of two qubits it is the 4 × 4 Kronecker product H ⊗ I, and CNOT⋅(H ⊗ I) sends |00⟩ to (|00⟩ + |11⟩)/√2.
Every gate is undone by its own adjoint, so any circuit runs backwards; measurement, erasure and copying are not gates.
U ∈ U(2ⁿ) for n qubits; entries are dimensionless complex numbers and the columns are orthonormal
The half-angle is the SU(2) double cover: Rₙ(2π) = −I, invisible on the sphere but a real sign inside a controlled gate.
θ in radians on the Bloch sphere, n a unit vector, σ = (X, Y, Z); α is an unobservable global phase
Conjugating by H swaps the x and z axes, so HTH is an eighth-turn about x — the second axis universality needs.
T = diag(1, e(iπ/4)); T² = S, S² = Z, HXH = Z, HZH = X; T is the only non-Clifford gate in the list
A gate on qubit 1 alone is A ⊗ I, on qubit 2 alone I ⊗ A; any A ⊗ B leaves Schmidt rank unchanged, so it cannot entangle.
2×2 ⊗ 2×2 = 4×4 in the basis |00⟩, |01⟩, |10⟩, |11⟩; np.kron(A, B) puts A on the left-hand qubit
A sum of two products, not a product — that is what lets CNOT(H ⊗ I)|00⟩ reach the Bell state (|00⟩ + |11⟩)/√2.
control on the left-hand qubit, target on the right; a real 4×4 matrix that is its own inverse
Accuracy is cheap — polylogarithmic — but a generic n-qubit unitary is exponentially expensive: universality is not efficiency.
ε is the operator-norm error of the approximation, n the qubit count; a z-rotation costs ≈ 3 log₂(1/ε) T gates
Why a gate must be unitary, and what that rules out
Between preparation and measurement a closed register evolves by the Schrödinger equation, and the solution over any interval is U = exp(−iĤt/ħ) with Ĥ Hermitian — a unitary. A gate is one such U, produced by switching a chosen Hamiltonian on for a chosen time, so whatever else it does it obeys U†U = I. Three consequences follow, and they are the rules of circuit design. Norms are preserved, so ⟨ψ|ψ⟩ = 1 stays 1 and the Born rule keeps working. The inverse exists and is U†, so every gate is reversible: a classical NAND, which maps two bits to one, cannot be a quantum gate, and its reversible replacement is the three-bit Toffoli. And U is linear, so it cannot clone an unknown state or reset a qubit; measurement, which is a projector Pₖ rather than a unitary, is not a gate either and sits outside the circuit box. The check is mechanical: np.allclose(U.conj().T @ U, np.eye(U.shape[0])) — the columns must form an orthonormal set.
Read every one-qubit gate as a rotation of the Bloch sphere
Any U in U(2) is e(iα) times an element of SU(2), and the global phase changes no probability, so what a one-qubit gate does is fixed by an SU(2) matrix. Every such matrix is Rₙ(θ) = exp(−iθ n⋅σ/2) = cos(θ/2) I − i sin(θ/2) n⋅σ, which rotates the Bloch vector by θ about the unit vector n. The half-angle is the double cover at work: θ = 2π gives −I, the same point on the sphere but a sign that a control qubit can detect. Now read the gate list. X = iRₓ(π) is a half-turn about x, swapping the poles. Z = iRz(π) fixes the poles and flips |+⟩ to |−⟩. H = iRₘ(π) with m = (x + z)/√2 exchanges the x and z axes, which is why HXH = Z. S = e(iπ/4)Rz(π/2) and T = e(iπ/8)Rz(π/4) turn the equator by 90° and 45°: T takes |+⟩, Bloch vector (1, 0, 0), to (|0⟩ + e(iπ/4)|1⟩)/√2, Bloch vector (0.707, 0.707, 0). Because H swaps axes, HTH = e(iπ/8)Rₓ(π/4) is an eighth-turn about x — two rotation axes from two gates.
Build two-qubit gates with the Kronecker product
Two qubits share C² ⊗ C², a four-dimensional space with basis |00⟩, |01⟩, |10⟩, |11⟩ in that order, so a two-qubit gate is a 4 × 4 unitary. If gate A acts on the left qubit and B on the right, the combined operator is the Kronecker product A ⊗ B, whose entries are (A ⊗ B)_(ij),(kl) = Aᵢₖ Bⱼₗ — every entry of A multiplied by the whole of B. In NumPy that is np.kron(A, B), and the argument order is the qubit order. A gate on the left qubit alone is A ⊗ I; on the right alone, I ⊗ A; and H ⊗ I, written out, is (1/√2) times the block matrix [[I, I], [I, −I]]. CNOT is not built this way. It is |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ X — do nothing if the control is |0⟩, apply X if it is |1⟩ — giving the block-diagonal matrix [[I, 0], [0, X]] that swaps the |10⟩ and |11⟩ columns. The distinction is physical. A product gate A ⊗ B maps a Schmidt-rank-1 state to a Schmidt-rank-1 state, so it can never entangle; CNOT, a sum of two products, can, and does.
Turn a circuit diagram into one matrix
A circuit is read left to right in time, but operators act on the ket nearest to them first, so the matrix is the product in reverse: gates G₁ then G₂ then G₃ give U = G₃G₂G₁. Take the Bell circuit — H on the left qubit, then CNOT with that qubit as control. U = CNOT⋅(H ⊗ I). Applied to |00⟩ = (1, 0, 0, 0)ᵀ: H ⊗ I gives (1, 0, 1, 0)ᵀ/√2, then CNOT swaps the last two entries, (1, 0, 0, 1)ᵀ/√2 = (|00⟩ + |11⟩)/√2. The input had Schmidt rank 1, the output rank 2 — the CNOT did the entangling. Gates on different qubits in the same time step are Kronecker-multiplied, so one layer of H on both qubits is H ⊗ H; the depth of a circuit is its number of layers and the size its number of gates. Two conventions bite in software: whether the left-most ket is qubit 0 (this lesson, and np.kron) or qubit n − 1 (Qiskit's little-endian ordering), and which qubit is the control — CNOT with control on the right is I ⊗ |0⟩⟨0| + X ⊗ |1⟩⟨1|, a different matrix.
Why {H, T, CNOT} generates everything
Universality is proved in three steps. First, any unitary on 2ⁿ dimensions is a product of two-level unitaries, acting on only two basis states, and each of those is a multiply-controlled one-qubit gate, which decomposes exactly into CNOTs and single-qubit gates. Second, any single-qubit gate is e(iα)Rz(β)Ry(γ)Rz(δ) — three Euler rotations about two axes. Third, and this is where T earns its place, Rz(π/4) = T and Rₓ(π/4) = HTH (both up to phase) compose to a single rotation Rₖ(Φ) with cos(Φ/2) = cos²(π/8) = (2 + √2)/4 = 0.8536, so Φ = 62.80°, and Φ/2π is irrational. Powers of an irrational rotation never repeat and come arbitrarily close to any angle about k, so {H, T} generates rotations dense in SU(2), and with CNOT the products are dense in U(2ⁿ). Replace T by S and the composite Rz(π/2)Rₓ(π/2) is a 120° rotation about (1, 1, 1)/√3: three applications return to the start. That is the Clifford group {H, S, CNOT}, finite up to phase and, by Gottesman–Knill, classically simulable in polynomial time. Superposition and entanglement it can make; universality it cannot.
What universality costs: precision, and the CNOT floor
Dense is not cheap, and two bills arrive. The first is precision. A finite set never hits a generic rotation exactly, so a target is approximated to within ε in operator norm; the Solovay–Kitaev theorem guarantees this with O(logc(1/ε)) gates, c ≈ 3.97, and number-theoretic synthesis brings a z-rotation down to about 3 log₂(1/ε) T gates. Errors add at worst linearly: if each of m gates is within ε of its ideal, the whole circuit is within mε, because unitaries preserve norms. So a 2,000-rotation circuit that must be good to 10⁻³ needs each rotation good to 5 × 10⁻⁷, costing about 3 log₂(2 × 10⁶) ≈ 63 T gates apiece — and tightening the tolerance a thousandfold to 10⁻⁶ raises that only to about 93. The second bill is not logarithmic. A generic n-qubit unitary needs at least ⌈(4ⁿ − 3n − 1)/4⌉ CNOTs: three for n = 2, and 262,137 for n = 10. Universality says every unitary is reachable; it says nothing about reaching it in polynomial time, which is why useful quantum algorithms are the rare structured unitaries — Grover's iterate, the QFT — with polynomial-size circuits.
Change one variable at a time
Make the relationship visible.
Set both turns to 90° (S and HSH) and step n: the tip visits three points and is back on the north pole at n = 3, because the Clifford group closes. Now set both to 45° (T and HTH): Φ = 62.8°, nΦ mod 360 never returns to zero, and the tip keeps finding new points — that non-closure is universality.
TURN PER BLOCK Φ62.8 deg
nΦ MOD 36062.8 deg
BLOCH z = ⟨Z⟩0.707
P(0) = (1 + z)/20.854
Live interpretationTURN PER BLOCK Φ: 62.8 deg. nΦ MOD 360: 62.8 deg. BLOCH z = ⟨Z⟩: 0.707. P(0) = (1 + z)/2: 0.854
Catch the common trap
Explain before calculating.
A two-qubit circuit applies H to qubit 0 (the left-hand ket), then CNOT with qubit 0 as control and qubit 1 as target. In the basis |00⟩, |01⟩, |10⟩, |11⟩, which single matrix represents the whole circuit?
Choose an answer to test the model.
Practice & worked examples
Reason from the model, then test the result.
EasyTake T = diag(1, e(iπ/4)). Show that T is unitary, that T² = S and S² = Z, and find where T sends the Bloch vector of |+⟩ = (|0⟩ + |1⟩)/√2.
- Unitarity: T† = diag(1, e(−iπ/4)), so T†T = diag(1 × 1, e(−iπ/4) e(iπ/4)) = diag(1, 1) = I. A diagonal matrix is unitary exactly when every entry has modulus 1.
- Powers of a diagonal matrix act entry by entry: T² = diag(1, e(iπ/2)) = diag(1, i) = S, and S² = diag(1, i²) = diag(1, −1) = Z. So T is a fourth root of Z, and Z² = I closes the chain.
- Act on |+⟩: T|+⟩ = (|0⟩ + e(iπ/4)|1⟩)/√2. A state (|0⟩ + e(iφ)|1⟩)/√2 has Bloch vector (cos φ, sin φ, 0), so the tip moves from (1, 0, 0) to (cos 45°, sin 45°, 0) = (0.707, 0.707, 0).
- That is a rotation by π/4 about z, as T = e(iπ/8) Rz(π/4) says: the relative phase e(iπ/4) is the physics and the global e(iπ/8) is invisible. P(0) = |1/√2|² = 0.5 before and after, because a z-rotation moves nothing along z.
AnswerT†T = I; T² = S and S² = Z; T rotates the Bloch vector of |+⟩ by 45° about z, from (1, 0, 0) to (0.707, 0.707, 0), leaving P(0) = 0.5.
MediumWrite the Bell circuit U = CNOT⋅(H ⊗ I) as a single 4 × 4 matrix in the basis |00⟩, |01⟩, |10⟩, |11⟩, apply it to |00⟩ and to |10⟩, and confirm from two of its columns that it is unitary.
- H ⊗ I: every entry of H = (1/√2)[[1, 1], [1, −1]] multiplies the 2 × 2 identity, giving (1/√2) × [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, −1, 0], [0, 1, 0, −1]].
- CNOT = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]] swaps the third and fourth rows of whatever it left-multiplies, so U = CNOT⋅(H ⊗ I) = (1/√2) × [[1, 0, 1, 0], [0, 1, 0, 1], [0, 1, 0, −1], [1, 0, −1, 0]].
- U|00⟩ is the first column: (1, 0, 0, 1)/√2 = (|00⟩ + |11⟩)/√2 = |Φ⁺⟩. U|10⟩ is the third column: (1, 0, 0, −1)/√2 = (|00⟩ − |11⟩)/√2 = |Φ⁻⟩.
- Both inputs had Schmidt rank 1 and both outputs have rank 2, so U cannot be any A ⊗ B — the CNOT term does the entangling. Unitarity on those columns: each has norm √((1 + 1)/2) = 1 and their inner product is (1 × 1 + 1 × (−1))/2 = 0. Orthonormal columns are exactly the condition U†U = I.
AnswerU = (1/√2)[[1, 0, 1, 0], [0, 1, 0, 1], [0, 1, 0, −1], [1, 0, −1, 0]]; |00⟩ → (|00⟩ + |11⟩)/√2 and |10⟩ → (|00⟩ − |11⟩)/√2; the columns are orthonormal, as unitarity requires.
HardA circuit contains 2,000 arbitrary z-rotations and must match its target unitary to within 1.0 × 10⁻³ in operator norm using only H, T and CNOT. Find the accuracy each rotation must reach, estimate the total T count if a z-rotation costs about 3 log₂(1/ε) T gates, and say how the count changes when the tolerance tightens to 1.0 × 10⁻⁶.
- Errors in a product of unitaries add at worst linearly: ‖Uₘ⋯U₁ − Vₘ⋯V₁‖ ≤ Σ‖Uₖ − Vₖ‖, because inserting and subtracting one exact factor at a time telescopes, and unitaries preserve norms. With m = 2,000 rotations each within ε, the circuit is within 2,000 ε.
- Set 2,000 ε = 1.0 × 10⁻³: ε = 5.0 × 10⁻⁷ per rotation. H and CNOT are exact members of the set and add nothing to this budget.
- T count per rotation: log₂(1/ε) = log₂(2 × 10⁶) = 1 + 6 log₂ 10 = 1 + 6 × 3.322 = 20.93, so 3 × 20.93 ≈ 63 T gates, interleaved with H and S gates that cost nothing in this accounting.
- Total: 2,000 × 63 ≈ 1.3 × 10⁵ T gates for the rotations alone, on top of the circuit's own CNOTs.
- Tolerance 1.0 × 10⁻⁶: ε = 5.0 × 10⁻¹⁰, log₂(2 × 10⁹) = 1 + 9 × 3.322 = 30.90, so about 93 T gates per rotation and 1.9 × 10⁵ in total. A thousandfold tighter tolerance cost a factor of 93/63 = 1.48 in gates — the polylogarithmic scaling Solovay–Kitaev promises.
Answerε = 5.0 × 10⁻⁷ per rotation; ≈ 63 T gates each, ≈ 1.3 × 10⁵ in total; at 10⁻⁶ overall, ≈ 93 each and ≈ 1.9 × 10⁵ in total — a factor of 1.48 for a factor of 1,000 in precision.