Tutorial › Part G · Semantics: which gate the pulses make › G5

Lean is loading

Stabilizer tableaux

Part G, lesson G5. You need lessons G1 to G4.

A matrix for n qubits has 4ⁿ entries; a BB[[144,12,12]] round has hundreds of qubits. So for a Clifford circuit (H, S, CNOT and the like), the semantic check, check_cert, never forms the matrix. It describes each side by its stabilizer tableau and compares those, with the library stim; this is how the Compilation page's Bell certificate was checked (its verdict there: "stabilizer tableau, composed from the emitted pulses, against the source QASM"). This lesson builds a tableau in Lean, small enough for the kernel at two qubits, checks its rules against the exact matrices, and proves the Bell circuit and the Bell programme's pulses have the same one.

*Lessons G1 to G4 are restated, unseen, above this line: the numbers, matrices with *, •, dagger and kron, PX, PY, PZ, I2, I4, and the pulse MS θ (angles in eighths of a turn).*

1. Pauli strings

A Pauli string is a phase iᵉ (e = 0 .. 3) times one Pauli per qubit: ⟨2, [.Z, .X]⟩ is −Z⊗X. One qubit's Paulis multiply by a table, XY = iZ and so on round the cycle, and a string multiplies qubit by qubit, the phases adding mod 4.

Each string is a matrix: a kron of the Paulis, times the phase. That is what ties the strings to lessons G1 to G4.

Exercise 1 ★ products_match open

Prove the table right: for each pair of the three Paulis, the string product's matrix is the product of the matrices.

2. Conjugating by a quarter turn

A Clifford gate U sends every Pauli string P to another one, U·P·U†, up to sign. For the native pulses there is one rule. Each of them, at a multiple of π/2, is a power of a quarter turn exp(−iπ/4·Q) = (1 − i·Q)/√2 about a Pauli string Q: R(π/2, 0) about X, R(π/2, π/2) about Y, R(π/2, π) about −X, MS(π/2) about X⊗X. A quarter turn leaves P alone if P commutes with Q, and sends it to −i·Q·P if they anticommute. Two strings anticommute when they differ at an odd number of qubits where neither is the identity.

Exercise 2 ★ quarter_rule open

Prove the rule against the exact matrices: for each of the six one-qubit axes ±X, ±Y, ±Z and each Pauli P, the rule's answer is U·P·U† for U the quarter turn.

Exercise 3 ★ ms_conjugates open

Two qubits: MS(π/2) is the quarter turn about X⊗X. Prove it sends Z⊗1 to −Y⊗X, by the rule and by the 4×4 matrices.

3. The tableau

A Clifford U is determined, up to a global phase, by where it sends the 2n strings X₀, Z₀, X₁, Z₁, ...: every string is a product of those. That list of images is its tableau (in stim, a Tableau, with x_output(k) and z_output(k)). Here a tableau is a list with one pair per qubit, the images of Xₖ and Zₖ.

To conjugate any string P by a tableau, write P as a product of the generators, Y = i·X·Z, and multiply their images in the same order. To compose, conjugate the first tableau's images by the second.

4. The pulses, and the circuit's gates

check_cert translates each native pulse into stim's gates (_emit_r, _emit_ms, and S for a VZ), for angles that are multiples of π/2 only: "R(theta, phi) = exp(-i theta/2 (cos phi X + sin phi Y)), for theta a multiple of pi/2", the axis read as "0 = X, 1 = Y, 2 = -X, 3 = -Y" quarter turns of φ. A T gate's phase π/4 is off that grid, and there check_cert falls back to the full matrix. In our terms, with angles in eighths of a turn: R θ φ is θ/2 quarter turns about the axis φ/2; VZ λ is λ/2 quarter turns about Z (diag(1, e^(iλ)) is that up to a phase); MS θ is θ/2 quarter turns about X⊗X.

The circuit's side is the source QASM, read gate by gate (circuit_tableau), with stim's own tableaux for H (X ↔ Z) and CX (X꜀ ↦ X꜀Xₜ, Zₜ ↦ Z꜀Zₜ, the other two fixed).

The Hadamard's two pulses in the Bell certificate (lesson G3) were R(π/2, −π/2) then VZ(π).

Exercise 4 ★ h_pulses_tableau open

Prove their tableau is the Hadamard's.

5. The Bell pair, both ways

The Bell programme's seven pulses, in time order, with qubit 0 on ion q0 and qubit 1 on q1 (lesson G2's list):

Read it as four rows: X₀ ↦ Z⊗1, Z₀ ↦ X⊗X, X₁ ↦ 1⊗X, Z₁ ↦ Z⊗Z. The images of Z₀ and Z₁, X⊗X and Z⊗Z, are the two stabilizers of the Bell state the circuit prepares from |00⟩.

Exercise 5 ★ bell_tableaux open

Prove the programme's tableau is the circuit's. The measurements are left out on both sides: both are the last thing done to their qubit, and lesson G6 explains why that lets them go.

check_cert makes the same comparison with stim: it builds a stim.Circuit from the programme's pulses (tableau_from_program) and another from the QASM (circuit_tableau), turns each into a stim.Tableau, and tests got == want. That is a computation by a C++ library and a translation written in Python, trusted, not proved. The compiler's design notes say so: "The tableau itself is not proved — it is stim plus a translation". What you just did is the same comparison as a theorem, for one certificate.

6. What a tableau cannot see

Lesson G4 showed the CNOT's five pulses are e^(iπ/4)·CX, not CX. A tableau is built from U·P·U†, and a phase c with |c| = 1 cancels in (cU)·P·(cU)† = c·c̄·U·P·U†.

Exercise 6 ★ phase_blind open

Prove the five pulses have exactly the CNOT's tableau.

That is the right blindness for a whole programme, and the reason the compiler records each gate's phase itself (lesson G4). What a tableau does see is everything else: a gate on the wrong qubit, a wrong angle, a dropped pulse. If the compiler had exchanged the CNOT's operands, it would have emitted the same lowering with q1 as the control: R(π/2, π/2) on q1, the MS, the two beams, R(−π/2, π/2) on q1. (The Compilation page's swap certificate has exactly those pulses, as the second of its three CNOTs.)

Exercise 7 ★ swapped_differs open

Prove that programme's tableau is not the circuit's.

7. Commuting is symmetric

The quarter-turn rule asks whether Q and P commute. That had better not depend on the order of the question, for every pair of strings of every length, not only for the ones above.

Exercise 8 ★★★ anti_symm open

Prove the anticommuting count is symmetric. Induction on the first list, cases on the second; at one qubit, P1.anti p q = P1.anti q p is sixteen cases, cases p <;> cases q <;> rfl.

Exercise 9 ★★ commutes_symm open

Deduce it for strings: unfold commutes and rewrite with anti_symm.

8. What this lesson proved

For the Bell certificate, the stabilizer comparison check_cert runs with stim holds as a theorem: the programme's seven pulses and the circuit's two gates have one tableau. The tableau's rules were checked against the exact matrices of lessons G1 to G4, and its blindness to a global phase is the one lesson G4 wanted. Lesson G6 adds what neither a tableau nor a unitary has: measurements.

The Lean on this page is Lean 4 (Apache-2.0), compiled to WebAssembly by the cauli/lean4 browser build (Lean 4.33, Apache-2.0), hosted here byte for byte. The proved checker it loads is the repository's QCCDC.Cert, carried to that Lean by a mechanical port: module syntax, and two tail-recursive functions each proved equal to the one it replaces; it gives the repository checker's verdict on every published certificate. The first time a lesson in this part opens, your browser downloads Lean (about 58 MB, kept for next time); a desktop browser is needed.