Skip to main content

Quantum information · institution-dependent · Interactive lesson

Unitary gates, circuits and 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.

UPV-20.06 · Lesson 6 of 9 in this unit. Position is not a completion score.
Starting model: Unitary gates, circuits and universalitySide view (x right, z up) and top view (x right, y up) of the Bloch sphere; the arrow is the Bloch vector after the block R_z(θ₂) H R_z(θ₁) H has acted n = 1 times on |0⟩. Each block is one rotation by Φ = 62.8 degrees about a fixed axis, so the tip has turned through nΦ = 62.8 degrees modulo 360.U = Rz(θ₂) H Rz(θ₁) H, n = 1side view (x, z)top view (x, y)Φ = 62.8° per block, nΦ mod 360° = 62.8°open dot: n − 1
Start with a picture. Change the model in the lab below.

Quantum information · institution-dependent. Your university determines the required depth of these quantum topics, including the use of operators, differential equations and computation. Institution-dependent does not automatically mean optional.

1

Build the model

A gate is a unitary matrix; a circuit is their product, read right to left.

The key idea

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, up to a global phase, 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.

The complete physical model and assumptions

A closed quantum system with a fixed Hamiltonian 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ⁿ) up to a global phase, 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.

1Why a gate must be unitary, and what that rules out

Between preparation and measurement a closed register evolves by the Schrödinger equation, and while the Hamiltonian is held fixed the solution is U = exp(−iĤt/ħ) with Ĥ Hermitian — a unitary, as is the time-ordered product of such factors when Ĥ varies. 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.

2Read 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.

3Build 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.

4Turn 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.

5Why {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, once controlled-NOTs along a Gray code make its two basis states differ in a single bit, 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; conjugating by H gives the same irrational rotation about a second, non-parallel axis, so with the Euler decomposition {H, T} generates rotations dense in SU(2), and with CNOT the products are dense in U(2ⁿ) up to a global phase. 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.

6What 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.

2

Key equations

Read the units, assumptions and limits before substituting.

Unitarity and reversibility

U†U = UU† = I ⇒ U⁻¹ = U†, ⟨Uψ|Uφ⟩ = ⟨ψ|φ⟩

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

One-qubit gate as a Bloch rotation

U = e(iα) Rₙ(θ), Rₙ(θ) = exp(−iθ n⋅σ/2) = cos(θ/2) I − i sin(θ/2) n⋅σ

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

The standard gates as rotations

X = i Rₓ(π)Z = i Rz(π)H = i Rₘ(π), m = (x + z)/√2S = e(iπ/4) Rz(π/2)T = e(iπ/8) Rz(π/4)

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

Kronecker product and local gates

(A ⊗ B)(|a⟩ ⊗ |b⟩) = A|a⟩ ⊗ B|b⟩, (A ⊗ B)(ij),(kl) = Aᵢₖ Bⱼₗ

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

CNOT as a controlled sum

CNOT = |0⟩⟨0| ⊗ I + |1⟩⟨1| ⊗ X = [[I, 0], [0, X]]

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

Solovay–Kitaev and the CNOT floor

N(ε) = O(logc(1/ε)), c ≈ 3.97CNOT count ≥ ⌈(4ⁿ − 3n − 1)/4⌉

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
3

Interactive lab

Predict first. Explore the model. Compare the result.

Explore the model

45 deg
0 to 360 deg; steps of 15.
45 deg
0 to 360 deg; steps of 15.
1
1 to 48; steps of 1.

Try this. 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.

Live results

TURN PER BLOCK Φ
62.8 deg
nΦ MOD 360
62.8 deg
BLOCH z = ⟨Z⟩
0.707
P(0) = (1 + z)/2
0.854

Results follow this lesson’s model and assumptions. Displayed values are rounded.

Interactive Physics V modelSide view (x right, z up) and top view (x right, y up) of the Bloch sphere; the arrow is the Bloch vector after the block R_z(θ₂) H R_z(θ₁) H has acted n = 1 times on |0⟩. Each block is one rotation by Φ = 62.8 degrees about a fixed axis, so the tip has turned through nΦ = 62.8 degrees modulo 360.U = Rz(θ₂) H Rz(θ₁) H, n = 1side view (x, z)top view (x, y)Φ = 62.8° per block, nΦ mod 360° = 62.8°open dot: n − 1
Side view (x right, z up) and top view (x right, y up) of the Bloch sphere; the arrow is the Bloch vector after the block Rz(θ₂) H Rz(θ₁) H has acted n = 1 times on |0⟩. Each block is one rotation by Φ = 62.8 degrees about a fixed axis, so the tip has turned through nΦ = 62.8 degrees modulo 360.

Predict → change one variable → check

Plan a change before running it. Every other input stays at the saved baseline.

Saved baseline. x-turn θ₁ from H Rz(θ₁) H: 45 deg; z-turn θ₂ from Rz(θ₂): 45 deg; Blocks applied n: 1

Baseline 45; choose 0 to 360, in steps of 15.
4. Compared with the saved baseline, this result will…

This experiment is kept only while this page is open. It does not change saved course progress.

4

Catch the common trap

Because H makes superpositions and CNOT makes entanglement, students infer that {H, S, CNOT} must already be universal and that T is a refinement. It is not. H, S and CNOT generate the Clifford group, which maps the Pauli group to itself and is therefore finite up to global phase — and a finite set cannot be dense in the continuum U(2ⁿ). The Bloch sphere shows it directly: Rz(π/2)Rₓ(π/2) is a 120° rotation and returns after three applications, while Rz(π/4)Rₓ(π/4) turns through 62.80°, an irrational fraction of a revolution, and never returns. The Gottesman–Knill theorem adds the sting: any circuit of Clifford gates with Pauli measurements, Bell states included, is simulable classically in polynomial time. Entanglement is necessary for a quantum advantage; it is not sufficient, and the cheap-looking T gate is the one that has to be paid for.

5

Practice & worked examples

3 authored examples. Make an attempt, then reveal the reasoning one step at a time.

EasyExample 1

Take 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.

Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.

0 of 4 steps revealed.

MediumExample 2

Write 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.

Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.

0 of 4 steps revealed.

HardExample 3

A 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⁻⁶.

Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.

0 of 5 steps revealed.

6

Quick check

Select an answer and explain it before checking.

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?
7

Review & continue

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, up to a global phase, to any chosen accuracy.

  • Explain the relationship without looking at the equation.
  • Check a sign, a unit and a model assumption in your working.
  • Return to the lab or worked example if a step is still unclear.

Extra challenging questions

Connect several ideas, explore supplied data, and compare your reasoning with a worked solution.