shubz — ~/writing/zx-calculus.mdx — vim
~/home~/now~/work~/writing×~/contact
connected20:14 GMT
last updated· 26 may 2026
shubz@orion~/writing/zx-calculus%cat ./meta.json# essay header
ESSAY · QUANTUM COMPUTATION
no.06 · 11 min read
./zx-calculus.mdx

Two colours and a Hadamard.

ZX-calculus as a way of picturing — and actually proving things about — quantum circuits.

The thing that bothered me about quantum circuits — long before I had the vocabulary for what was bothering me — was that you could follow every gate and still not understand why the protocol worked.1 Quantum teleportation is the clearest example. Hadamard. CNOT. Measure. Classically communicate. Apply corrections. The sequence is correct. It is also almost entirely opaque: the circuit doesn't show you the structure that makes entanglement usable in that particular way. It shows you that it works. The reason lives somewhere behind the notation.1. I read mathematics at Oxford and picked up quantum mechanics from the side. The formalism was clear; the intuition took longer. ZX-calculus was the first notation that made me feel like the intuition and the formalism were pointing at the same thing.

ZX-calculus is a graphical language for quantum computation developed by Bob Coecke and Ross Duncan at Oxford, starting around 2008. The idea is to represent quantum maps not as sequences of matrix operations but as diagrams — coloured nodes connected by wires — and then to reason about those diagrams by applying rewrite rules. What makes it unusual is that the rewriting is complete: any true equation between quantum maps can be derived from a small set of local rewrites on diagrams. You stop computing and start reasoning with pictures.

I have been reading the ZX-calculus on and off for a while now, and the thing I want to do here is explain why the notation is interesting even before you use it for anything practical. The basic objects are worth understanding on their own terms.

§01What circuits hide

The standard quantum circuit diagram puts qubits on horizontal wires and gates on those wires, left-to-right in time. It is a good notation for computation: you can read off the gate sequence, verify unitarity, count resources. What it doesn't show you is causal structure — the reason a protocol works, as opposed to the sequence of operations that implements it.

Consider the CNOT gate: control qubit on the top wire, target qubit on the bottom wire. In the circuit picture it looks like a control dot connected by a vertical line to an XOR circle. It flips the target qubit if and only if the control is |1⟩, which is a correct description of what it does without saying anything about the symmetry between how it behaves in the computational basis (Z basis) and how it behaves in the Hadamard basis (X basis) — copying the control in one, copying the target in the other, a symmetry the circuit picture hides entirely.

The ZX-calculus makes that symmetry visible by construction. Each gate decomposes into coloured nodes — called spiders — that correspond directly to copying operations in specific bases. Once you draw the ZX diagram of CNOT, the Z/X symmetry is immediate: it's in the colours.

§02Spiders

There are two generators. The Z-spider (drawn green) with n input wires, m output wires, and a phase α represents the linear map:

|0⟩⊗m⟨0|⊗n + e|1⟩⊗m⟨1|⊗n

The X-spider (drawn red) is the same construction in the Hadamard-conjugate basis — |+⟩ and |−⟩ instead of |0⟩ and |1⟩. When the phase is zero, both spiders are classical copying maps: the Z-spider copies the computational basis; the X-spider copies the Hadamard basis. When the phase is π, the Z-spider becomes a Pauli-Z gate and the X-spider becomes Pauli-X (a NOT gate).22. More precisely: a Z-spider with one input, one output, and phase α is the gate diag(1, e) — the phase gate Rz(α). At α = 0 it's the identity. At α = π it's Z. The arity (number of wires) and the phase together determine which map you're describing.

Wires are qubits. Bending a wire backward turns an input into an output (the "cup" and "cap" morphisms from compact closed categories — ZX-calculus is a categorical object, not a diagrammatic convention someone made up). The language is compositional: you can stack diagrams side by side for tensor product and connect them end-to-end for sequential composition, just as with circuit diagrams.

The first rule to learn — and the one that everything else builds on — is spider fusion.

// pullTwo spiders of the same colour connected by a wire are one spider. Phases add.
~/shubzsharma.com/two.py
π/3π/2α = π/3β = π/2connecting wire
α = π/3
β = π/2
drag the sliders, then fuse
Two Z-spiders (green) connected by a wire. Set the phases α and β with the sliders, then click 'fuse' to see them collapse into a single spider with phase α + β. This is the spider fusion rule — the most-used rewrite in the calculus.

Fusion is both visually obvious (two nodes sharing a wire become one node) and algebraically correct — you can verify it by multiplying out the matrices if you need to, but after a while you just stop doing that, which is most of the point.

§03Three rules

Beyond fusion, there are two other rules that do most of the work in practice.

The Hadamard rule: a Hadamard gate on a wire converts a Z-spider into an X-spider and vice versa. Hadamard is depicted as a yellow square on a wire. Pushing a Hadamard through a spider changes its colour. This is why the Z/X symmetry of CNOT is visible in ZX: CNOT decomposes into a green spider controlling a red spider, and Hadamard at either end can swap which is which.

The bialgebra rule: a green spider copying a red spider is equal — as a linear map — to a red spider copying a green spider. This rule is what gives the calculus its power for reasoning about entanglement. It underlies why CNOT has the Z/X symmetry I described earlier, and it's the key step in the ZX proof of quantum teleportation.33. "Bialgebra" is the name because it encodes the coherence between two Frobenius algebras — one for each colour. The Frobenius algebra structure is why spiders behave like "copying and deleting" operations, which is exactly the structure that classical information processing uses. The bialgebra rule says the two Frobenius algebras interact coherently — and that coherence is what makes them quantum rather than classical.

~/shubzsharma.com/three.py
|0⟩|0⟩H|Φ+⟩(Bell)HadamardCNOTStandard circuit: |Φ+⟩ = (H ⊗ I) · CNOT · |00⟩
The standard quantum circuit: Hadamard puts qubit 1 into superposition; CNOT entangles it with qubit 2. You can follow every gate — and still not see why entanglement is happening.
Three views of the Bell state preparation (H + CNOT on |00⟩). The circuit view shows the gate sequence. The ZX view shows why it creates entanglement: a Z-spider copied into an X-spider. The bialgebra view shows the key rewrite rule underlying both the CNOT symmetry and the teleportation proof.

These three rules — fusion, Hadamard colour-change, and bialgebra — plus some smaller tidying rules cover all equations between Clifford quantum circuits: circuits built from only Hadamard, CNOT, and the phase gate S. The Clifford group is the stabiliser formalism, and ZX is complete for it.

§04Why teleportation is obvious

The circuit picture of quantum teleportation gives you a sequence — share a Bell pair, Alice applies CNOT and Hadamard, measure, send two classical bits, Bob applies corrections — and if you follow every step correctly you arrive at the right answer without quite understanding why the corrections work, because the circuit doesn't tell you; it just tells you they do.

The ZX proof is essentially one rewrite. You draw the protocol as a diagram — the Bell pair preparation, the entangled measurements, the classical corrections — and then you apply the bialgebra rule to the middle of the diagram. The measurement nodes and the correction nodes cancel. What remains is a single wire connecting Alice's input state to Bob's output: the teleportation has happened, and the diagram makes clear that it was always going to happen because the structure of the Bell pair and the structure of the measurement were designed to be each other's adjoint.

This is the sense in which ZX makes the reason visible, not just the sequence. The circuit told you that teleportation works. The diagram tells you why: it's because the measurement in the entangled basis is, up to local operations, the inverse of the Bell pair preparation. The protocol cancels with its own adjoint. No state is sent. The quantum channel is already there; the measurement wires it up.

// pullThe circuit tells you teleportation works. The diagram tells you why: it cancels with its own adjoint.

§05Completeness and what comes after

Completeness for Clifford circuits was proved around 2014. Full completeness — any equation between arbitrary quantum circuits, provable from ZX rewrites — came in 2017-18, with contributions from Jeandel, Perdrix, Vilmart and others. That means ZX-calculus is not a convenient shorthand for a subset of quantum mechanics but a complete formal language for all of it.44. Full completeness required adding the Euler decomposition of the Hadamard as an explicit axiom, and handling the scalar factors (global phases and normalisations) carefully. The scalar-free version is cleaner; the scalar-tracked version is more pedantic but necessary for proving that two circuits implement exactly the same unitary, not just the same unitary up to phase.

The most direct application is circuit optimisation. The most expensive non-Clifford gate in near-term quantum computers is the T gate (a π/8 phase rotation). Fewer T gates means a smaller error budget. PyZX, the software library Kissinger and van de Wetering built around ZX, automates T-count reduction by applying rewrites that simplify the diagram without changing what it computes. Circuits that look irreducible in gate-model notation often collapse dramatically when you draw them in ZX.

ZX has also found a home in measurement-based quantum computation, where resource states and measurement patterns translate directly into diagrams; in quantum error correction, where the stabiliser codes are Clifford objects and ZX is complete; and in Coecke's broader categorical quantum mechanics programme, which has spun off into natural language processing (DisCoCat) and quantum gravity. It travels well.

I don't yet reach for ZX-calculus as a working tool. But reading it changed how I think about circuit diagrams — which is probably the point. A protocol you can follow step-by-step and a protocol you understand are not the same thing. ZX makes that gap visible, which is most of what a good notation is supposed to do.

— written between sessions reading Coecke and Kissinger's textbook, on a Thursday evening in London.

shubz@orion~/writing/zx-calculus%ls ../related/# 2 essays

Related essays

← PREVIOUS
Tracing a kill chain through the course
NEXT →
JAYA, improved
connected · zsh 5.9Made in London.© Shubz Sharma · /essay