Skip to main content
KetQat

Appearance

Topic · advanced

ZX Calculus

A graphical language in which qubit linear maps are drawn as networks of Z and X spiders and reasoned about by local rewrites. What the generators mean, which rules are sound, the completeness theorems, and how the calculus is used for circuit optimisation, extraction and lattice surgery.

ExpositionMachine-checkedUpdated 2026-12-01 · last verified 2026-12-01

AI-assisted text, machine-checked, not yet reviewed by a person. Citations resolve and an automated pass compared the statements with the cited sources. That is not peer review; check the sources for anything you depend on.

Overview

The ZX calculus, introduced by Coecke and Duncan, is a way of writing linear maps between qubit spaces as diagrams and proving equalities between them by local rewrites. A diagram is a tensor network with only three kinds of node: Z spiders (built from the computational basis), X spiders (built from the ∣±⟩\ket{\pm} basis) and Hadamard boxes. Each spider carries a phase. Every qubit circuit, state, measurement and post-selected operation can be drawn this way, and every linear map between qubit spaces has a diagram (universality).

The value of the calculus lies in its rules. A handful of identities, such as spider fusion, express the interaction of the two bases, and for suitable rule sets they are complete: if two diagrams denote the same map, the rules can rewrite one into the other. Circuit equalities that take pages of matrix algebra become short graph rewrites. The calculus is used for circuit optimisation, notably reducing the number of TT gates, for checking circuit equivalence, for describing measurement-based and lattice-surgery computations, and for teaching. The textbook is Coecke and Kissinger.

Intuition

A Z spider with phase α\alpha says "all my legs carry the same computational-basis value, and the value 1 picks up a phase eiαe^{i\alpha}". So a Z spider with one input and two outputs copies basis states (it is the control of a CNOT), and a Z spider with one input and one output is the phase gate diag⁡(1,eiα)\operatorname{diag}(1, e^{i\alpha}). An X spider says the same in the ∣±⟩\ket{\pm} basis; read in the computational basis, an X spider with two inputs and one output computes the parity of its inputs, so it is the target of a CNOT. The rules then become plausible: two Z spiders joined by a wire both insist on a shared value, so they are one spider and their phases add; a Hadamard swaps the two bases, so it swaps the colours.

What makes diagrams better than circuits for some tasks is that they forget the time order. Only connectivity matters, so a phase can be slid along a wire through any number of Z spiders. A circuit optimiser built on this can merge phases that a gate-by-gate optimiser never sees as adjacent.

Prerequisites

The circuit model, Pauli and Clifford gates, and the idea of a tensor contraction. For the graph-state material, graph states and local complementation. The categorical foundations are covered in category theory but are not needed for computation.

Mathematical Definitions

DefinitionZX diagramEstablished definition

A ZX diagram with mm inputs and nn outputs is a finite undirected multigraph whose internal vertices are generators and which has mm input and nn output boundary wires. The generators, with their interpretation [ ⁣[⋅] ⁣][\![\cdot]\!] as linear maps (C2)⊗a→(C2)⊗b(\C^2)^{\otimes a} \to (\C^2)^{\otimes b} for a generator with aa incoming and bb outgoing wires, are:

[ ⁣[Zαa,b] ⁣]=∣0⟩⊗b⟨0∣⊗a+eiα ∣1⟩⊗b⟨1∣⊗a,[ ⁣[Xαa,b] ⁣]=∣+⟩⊗b⟨+∣⊗a+eiα ∣−⟩⊗b⟨−∣⊗a,[\![Z^{a,b}_\alpha]\!] = \ket{0}^{\otimes b}\bra{0}^{\otimes a} + e^{i\alpha}\,\ket{1}^{\otimes b}\bra{1}^{\otimes a}, \qquad [\![X^{a,b}_\alpha]\!] = \ket{+}^{\otimes b}\bra{+}^{\otimes a} + e^{i\alpha}\,\ket{-}^{\otimes b}\bra{-}^{\otimes a},
[ ⁣[H] ⁣]=12(111−1),[\![H]\!] = \tfrac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix},

where ∣±⟩=(∣0⟩±∣1⟩)/2\ket{\pm} = (\ket{0} \pm \ket{1})/\sqrt{2} and a,b≥0a, b \ge 0 (an empty tensor power is the number 1). Zαa,bZ^{a,b}_\alpha is the Z spider (drawn green), Xαa,bX^{a,b}_\alpha the X spider (drawn red), HH the Hadamard box, and α\alpha the spider's phase; a phase of 0 is omitted. Plain wires denote the identity, and crossing wires the swap.

The interpretation of a whole diagram is the tensor contraction of its generators along the internal wires, with the boundary wires left open. Because each spider is symmetric in its inputs and in its outputs, and because bending a wire (turning an input into an output) is implemented by the cup ∣00⟩+∣11⟩=[ ⁣[Z00,2] ⁣]\ket{00} + \ket{11} = [\![Z^{0,2}_0]\!], the interpretation depends only on the graph, not on how it is drawn ("only connectivity matters").

Two diagrams are equal when their interpretations are equal; many papers instead work up to a nonzero scalar factor. The calculus was introduced by Coecke and Duncan; the textbook is Coecke and Kissinger. The definition uses Xαa,b=H⊗b Zαa,b H⊗aX^{a,b}_\alpha = H^{\otimes b}\, Z^{a,b}_\alpha\, H^{\otimes a}, which follows from H∣0⟩=∣+⟩H\ket{0} = \ket{+} and H∣1⟩=∣−⟩H\ket{1} = \ket{-}.

Holds when
  • Qubits only; phases α∈R\alpha \in \R taken modulo 2π2\pi.
  • Diagrams are read as tensor networks, so only connectivity matters, not the drawing.

Theorems

TheoremSpider fusion and the basic ZX rulesEstablished result

Write Zαa,bZ^{a,b}_\alpha and Xαa,bX^{a,b}_\alpha for the interpretations of the spiders. Then:

  1. Fusion. If k≥1k \ge 1 outputs of Zαa1,b1+kZ^{a_1, b_1 + k}_\alpha are connected to kk inputs of Zβa2+k,b2Z^{a_2 + k, b_2}_\beta, the result is Zα+βa1+a2, b1+b2Z^{a_1 + a_2,\, b_1 + b_2}_{\alpha + \beta}. A wire joining a spider to itself can be deleted. The same holds for X spiders.
  2. Identity. Z01,1=X01,1=IZ^{1,1}_0 = X^{1,1}_0 = I.
  3. Colour change. Xαa,b=H⊗b Zαa,b H⊗aX^{a,b}_\alpha = H^{\otimes b}\, Z^{a,b}_\alpha\, H^{\otimes a}, and HH=IH H = I.
  4. π\pi-copy. Zα1,b Xπ1,1=eiα (Xπ1,1)⊗b Z−α1,bZ^{1,b}_\alpha\, X^{1,1}_\pi = e^{i\alpha}\, (X^{1,1}_\pi)^{\otimes b}\, Z^{1,b}_{-\alpha}, where Xπ1,1X^{1,1}_\pi is the Pauli XX.
  5. Copy. Z01,b∣0⟩=∣0⟩⊗bZ^{1,b}_0 \ket{0} = \ket{0}^{\otimes b}, Z01,b∣1⟩=∣1⟩⊗bZ^{1,b}_0 \ket{1} = \ket{1}^{\otimes b}, and X00,1=2 ∣0⟩X^{0,1}_0 = \sqrt{2}\,\ket{0}.
  6. Bialgebra. Z01,2 X02,1=2 (X02,1⊗X02,1) (I⊗SWAP⊗I) (Z01,2⊗Z01,2)Z^{1,2}_0\, X^{2,1}_0 = \sqrt{2}\, \big(X^{2,1}_0 \otimes X^{2,1}_0\big)\, (I \otimes \mathrm{SWAP} \otimes I)\, \big(Z^{1,2}_0 \otimes Z^{1,2}_0\big).

Rules 1, 3 and 6 (each up to scalars) are among the original axioms of Coecke and Duncan, and rule 4 follows from their two π\pi rules (K1, K2) together with fusion; the textbook treatment with scalars is Coecke and Kissinger. By colour change, every rule has a version with the colours swapped.

Holds when
  • Interpretation of ZX diagrams as linear maps with the unnormalised spiders defined there; scalars are stated exactly, not dropped.
Proof · Proof of spider fusion and the basic ZX rules

Write Zαa,b=∑x∈{0,1}eiαx ∣x⟩⊗b⟨x∣⊗aZ^{a,b}_\alpha = \sum_{x \in \{0,1\}} e^{i\alpha x}\, \ket{x}^{\otimes b}\bra{x}^{\otimes a}.

1. Fusion. Contracting kk wires between the two spiders gives

∑x,yeiαxeiβy ⟨y∣x⟩k  ∣x⟩⊗b1∣y⟩⊗b2 ⟨x∣⊗a1⟨y∣⊗a2=∑xei(α+β)x ∣x⟩⊗(b1+b2)⟨x∣⊗(a1+a2),\sum_{x, y} e^{i\alpha x} e^{i\beta y}\, \braket{y}{x}^{k}\; \ket{x}^{\otimes b_1}\ket{y}^{\otimes b_2}\, \bra{x}^{\otimes a_1}\bra{y}^{\otimes a_2} = \sum_x e^{i(\alpha+\beta)x}\, \ket{x}^{\otimes (b_1+b_2)} \bra{x}^{\otimes (a_1+a_2)},

since ⟨y∣x⟩k=δxy\braket{y}{x}^k = \delta_{xy} for k≥1k \ge 1. A self-loop contracts an output with an input of the same term, contributing ⟨x∣x⟩=1\braket{x}{x} = 1, so it can be removed. For X spiders conjugate by Hadamards (rule 3), which commute with contraction because HH is real and symmetric, so ∑jHijHjk=δik\sum_j H_{ij} H_{jk} = \delta_{ik} along each internal wire.

2. Identity. Z01,1=∣0⟩⟨0∣+∣1⟩⟨1∣=IZ^{1,1}_0 = \ketbra{0}{0} + \ketbra{1}{1} = I, and X01,1=∣+⟩⟨+∣+∣−⟩⟨−∣=IX^{1,1}_0 = \ketbra{+}{+} + \ketbra{-}{-} = I.

3. Colour change. H∣x⟩=∣±⟩H\ket{x} = \ket{\pm} for x=0,1x = 0, 1, so H⊗bZαa,bH⊗a=∣+⟩⊗b⟨+∣⊗a+eiα∣−⟩⊗b⟨−∣⊗aH^{\otimes b} Z^{a,b}_\alpha H^{\otimes a} = \ket{+}^{\otimes b}\bra{+}^{\otimes a} + e^{i\alpha}\ket{-}^{\otimes b}\bra{-}^{\otimes a}, using H†=HH\dagg = H. And H2=IH^2 = I by multiplying the matrices.

4. π\pi-copy. Xπ1,1=∣+⟩⟨+∣−∣−⟩⟨−∣X^{1,1}_\pi = \ketbra{+}{+} - \ketbra{-}{-} is the Pauli XX, which maps ∣x⟩↦∣1−x⟩\ket{x} \mapsto \ket{1-x}. Hence Zα1,bX=∑xeiαx∣x⟩⊗b⟨1−x∣=∑yeiα(1−y)∣1−y⟩⊗b⟨y∣=eiα X⊗b∑ye−iαy∣y⟩⊗b⟨y∣=eiαX⊗bZ−α1,bZ^{1,b}_\alpha X = \sum_x e^{i\alpha x} \ket{x}^{\otimes b} \bra{1-x} = \sum_y e^{i\alpha(1-y)} \ket{1-y}^{\otimes b}\bra{y} = e^{i\alpha}\, X^{\otimes b} \sum_y e^{-i\alpha y} \ket{y}^{\otimes b}\bra{y} = e^{i\alpha} X^{\otimes b} Z^{1,b}_{-\alpha}.

5. Copy. The first two identities are immediate from the definition. For the last, X00,1=∣+⟩+∣−⟩=2∣0⟩X^{0,1}_0 = \ket{+} + \ket{-} = \sqrt{2}\ket{0}.

6. Bialgebra. Both sides are maps from two qubits to two qubits; compare them on basis states. First, X02,1=∣+⟩(⟨+∣⟨+∣)+∣−⟩(⟨−∣⟨−∣)X^{2,1}_0 = \ket{+}(\bra{+}\bra{+}) + \ket{-}(\bra{-}\bra{-}) sends ∣x1x2⟩↦12[(∣+⟩+(−1)x1+x2∣−⟩)]=12∣x1⊕x2⟩\ket{x_1 x_2} \mapsto \tfrac{1}{2}\big[(\ket{+} + (-1)^{x_1+x_2}\ket{-})\big] = \tfrac{1}{\sqrt{2}}\ket{x_1 \oplus x_2}, since ⟨−∣x⟩=(−1)x/2\braket{-}{x} = (-1)^x/\sqrt{2}. So the left side sends ∣x1x2⟩↦12∣x1⊕x2⟩∣x1⊕x2⟩\ket{x_1 x_2} \mapsto \tfrac{1}{\sqrt{2}}\ket{x_1 \oplus x_2}\ket{x_1 \oplus x_2}. On the right side, Z01,2⊗Z01,2Z^{1,2}_0 \otimes Z^{1,2}_0 sends ∣x1x2⟩↦∣x1x1x2x2⟩\ket{x_1 x_2} \mapsto \ket{x_1 x_1 x_2 x_2}, the middle swap reorders this to ∣x1x2x1x2⟩\ket{x_1 x_2 x_1 x_2}, and X02,1⊗X02,1X^{2,1}_0 \otimes X^{2,1}_0 gives 12∣x1⊕x2⟩∣x1⊕x2⟩\tfrac{1}{2}\ket{x_1 \oplus x_2}\ket{x_1 \oplus x_2}. Multiplying by 2\sqrt{2} matches the left side.

The same calculation shows 2 (Z01,2⊗I)\sqrt{2}\,(Z^{1,2}_0 \otimes I) followed by (I⊗X02,1)(I \otimes X^{2,1}_0) is the CNOT gate with the Z spider on the control, ∣x1x2⟩↦∣x1⟩∣x1⊕x2⟩\ket{x_1 x_2} \mapsto \ket{x_1}\ket{x_1 \oplus x_2}. These computations are the standard ones of Coecke and Kissinger.

EquationEuler decomposition of the Hadamard gateEstablished result
H  =  e−iπ/4  Zπ/2 Xπ/2 Zπ/2H \;=\; e^{-i\pi/4}\; Z_{\pi/2}\, X_{\pi/2}\, Z_{\pi/2}
H  =  e−iπ/4  Zπ/2 Xπ/2 Zπ/2H \;=\; e^{-i\pi/4}\; Z_{\pi/2}\, X_{\pi/2}\, Z_{\pi/2}

Check. Zπ/2=diag⁡(1,i)Z_{\pi/2} = \operatorname{diag}(1, i) and Xπ/2=12(1+i1−i1−i1+i)X_{\pi/2} = \tfrac{1}{2}\begin{pmatrix} 1+i & 1-i \\ 1-i & 1+i \end{pmatrix}. Then Zπ/2Xπ/2Zπ/2=12(1+ii(1−i)i(1−i)−(1+i))=1+i2(111−1)=eiπ/4HZ_{\pi/2} X_{\pi/2} Z_{\pi/2} = \tfrac{1}{2}\begin{pmatrix} 1+i & i(1-i) \\ i(1-i) & -(1+i) \end{pmatrix} = \tfrac{1+i}{2}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = e^{i\pi/4} H, using i(1−i)=1+ii(1-i) = 1+i and (1+i)/2=eiπ/4/2(1+i)/2 = e^{i\pi/4}/\sqrt{2}.

Use. Read as a diagram rewrite, this lets a Hadamard box be replaced by three spiders, so diagrams can be written with spiders alone. Duncan and Perdrix showed that this equation is not derivable from the original rules of the calculus and is needed to reason about graph states; it is part of the rule set that Backens proved complete for stabilizer diagrams.

Holds when
  • Zα=diag⁡(1,eiα)Z_\alpha = \operatorname{diag}(1, e^{i\alpha}) and Xα=HZαHX_\alpha = H Z_\alpha H are the one-input, one-output spiders of the ZX calculus.
TheoremUniversality of ZX diagramsEstablished result

For all m,n≥0m, n \ge 0 and every linear map M:(C2)⊗m→(C2)⊗nM : (\C^2)^{\otimes m} \to (\C^2)^{\otimes n} there is a ZX diagram DD with [ ⁣[D] ⁣]=M[\![D]\!] = M (Coecke and Duncan; Coecke and Kissinger).

Restricting phases gives the familiar fragments: diagrams with all phases in π2Z\tfrac{\pi}{2}\Z denote, up to nonzero scalars, exactly the stabilizer maps (the setting of Backens), and phases in π4Z\tfrac{\pi}{4}\Z give the Clifford+T fragment (Jeandel, Perdrix and Vilmart). The proof below covers the universality statement only.

Holds when
  • Arbitrary real phases are allowed for the universality statement; the fragment statements restrict phases and are taken up to nonzero scalars.
Proof · Proof of universality of ZX diagrams

Composition and tensor product of diagrams correspond to composition and tensor product of maps, so it suffices to build a generating set.

Pieces. (a) By the basic rules, 2 (I⊗X02,1)(Z01,2⊗I)\sqrt{2}\,(I \otimes X^{2,1}_0)(Z^{1,2}_0 \otimes I) is CNOT. (b) Single-qubit unitaries: every U∈U(2)U \in U(2) is eiφRz(β)Ry(γ)Rz(δ)e^{i\varphi} R_z(\beta) R_y(\gamma) R_z(\delta) by the ZYZ decomposition. Since Ry(γ)=SRx(γ)S†R_y(\gamma) = S R_x(\gamma) S\dagg with S=diag⁡(1,i)S = \operatorname{diag}(1, i), and Rz(θ)=e−iθ/2Zθ1,1R_z(\theta) = e^{-i\theta/2} Z^{1,1}_\theta, Rx(θ)=e−iθ/2Xθ1,1R_x(\theta) = e^{-i\theta/2} X^{1,1}_\theta, S=Zπ/21,1S = Z^{1,1}_{\pi/2}, every UU is a scalar times a product of one-input, one-output spiders. (c) States and effects: X00,1=2∣0⟩X^{0,1}_0 = \sqrt{2}\ket{0} and X01,0=2⟨0∣X^{1,0}_0 = \sqrt{2}\bra{0}. (d) Scalars: the spider with no wires is the number Zα0,0=1+eiα=2cos⁡(α/2) eiα/2Z^{0,0}_\alpha = 1 + e^{i\alpha} = 2\cos(\alpha/2)\, e^{i\alpha/2}. For ∣θ∣<π\abs{\theta} < \pi, the product Zθ+2δ0,0Zθ−2δ0,0=2(cos⁡θ+cos⁡2δ) eiθZ^{0,0}_{\theta + 2\delta} Z^{0,0}_{\theta - 2\delta} = 2(\cos\theta + \cos 2\delta)\, e^{i\theta} takes every modulus in (0,2+2cos⁡θ](0, 2 + 2\cos\theta] as δ\delta varies over [0,π/2)[0, \pi/2); multiplying by copies of Z00,0=2Z^{0,0}_0 = 2 reaches every positive modulus with phase θ\theta. Phase π\pi is the square of phase π/2\pi/2, and 0=Zπ0,00 = Z^{0,0}_\pi. So any scalar multiple of a diagram is a diagram.

Square, contractive case. Let AA act on NN qubits with operator norm ∥A∥≤1\norm{A} \le 1. The block matrix

U=(A(I−AA†)1/2(I−A†A)1/2−A†)U = \begin{pmatrix} A & (I - A A\dagg)^{1/2} \\ (I - A\dagg A)^{1/2} & -A\dagg \end{pmatrix}

on N+1N+1 qubits (first qubit selecting the block) is unitary (a standard unitary dilation of a contraction), as one checks by multiplying out U†UU\dagg U and using A†(I−AA†)1/2=(I−A†A)1/2A†A\dagg (I - A A\dagg)^{1/2} = (I - A\dagg A)^{1/2} A\dagg, which holds because A†f(AA†)=f(A†A)A†A\dagg f(A A\dagg) = f(A\dagg A) A\dagg for every polynomial ff and hence for the square root. Then A=(⟨0∣⊗I) U (∣0⟩⊗I)A = (\bra{0} \otimes I)\, U\, (\ket{0} \otimes I). By exact universality of CNOT and single-qubit gates (Nielsen and Chuang, section 4.5), UU is a finite circuit of pieces (a) and (b), and the state and effect are pieces (c), so AA is a scalar times a diagram, hence a diagram by (d).

General case. Let M:2m→2nM : 2^m \to 2^n be nonzero (the zero map is 00 times any diagram) and N=max⁡(m,n)N = \max(m, n). Put s=1/∥M∥s = 1/\norm{M} and A=(∣0⟩⊗(N−n)⊗sM)(⟨0∣⊗(N−m)⊗I2m)A = (\ket{0}^{\otimes (N - n)} \otimes sM)(\bra{0}^{\otimes (N-m)} \otimes I_{2^m}), a contraction on NN qubits. Then sM=(⟨0∣⊗(N−n)⊗I) A (∣0⟩⊗(N−m)⊗I)sM = (\bra{0}^{\otimes(N-n)} \otimes I)\, A\, (\ket{0}^{\otimes(N-m)} \otimes I), and MM is the scalar ∥M∥\norm{M} times a diagram built from AA and pieces (c).

TheoremCompleteness of the ZX calculusPeer-reviewed result

A set of rewrite rules for ZX diagrams is sound if every rule preserves the interpretation, and complete for a class of diagrams if, whenever two diagrams D1,D2D_1, D_2 in the class satisfy [ ⁣[D1] ⁣]=[ ⁣[D2] ⁣][\![D_1]\!] = [\![D_2]\!], D1D_1 can be transformed into D2D_2 by finitely many applications of the rules. The following are proved.

  1. Stabilizer fragment. With all phases multiples of π/2\pi/2, the rules of the calculus, including the Euler decomposition of the Hadamard gate, are complete (Backens). The proof rewrites every diagram to a normal form made of a graph state and local Clifford operations.
  2. The original rules are not complete in general. With arbitrary phases the rule set of Coecke and Duncan, even with the Euler decomposition added, is incomplete (Schröder de Witt and Zamdzhiev).
  3. Clifford+T fragment. With phases multiples of π/4\pi/4, adding two new axioms gives a complete rule set (Jeandel, Perdrix and Vilmart); the proof goes through a translation to the ZW calculus, a graphical calculus for integer matrices.
  4. All pure-qubit diagrams. Complete axiomatisations for diagrams with arbitrary phases were given by Hadzihasanovic, Ng and Wang, and an axiomatisation in which every rule has a physical reading and all but two are proved necessary by Vilmart.

Completeness is an existence statement: it says a rewrite sequence exists, not that one can be found efficiently. Deciding equality of general diagrams is at least as hard as deciding equality of quantum circuits.

Holds when
  • Each statement refers to a specific rule set given in the cited paper; completeness is relative to that rule set and to the stated fragment of phases.
  • Equalities in the stabilizer result are stated with the scalar conventions of that paper; later results handle scalars exactly.
TheoremHardness of circuit extraction from ZX diagramsPeer-reviewed result

Given a ZX diagram promised to denote a unitary map, producing a quantum circuit of polynomially related size that implements it is #P\#\mathsf{P}-hard, and hence at least as hard as strong simulation of quantum circuits (de Beaudrap, Kissinger and van de Wetering). The same paper gives a second result that does not depend on the output being a circuit: an oracle that takes such a diagram and samples from the output distribution of the computation it describes would solve NP\mathsf{NP}-complete problems with efficient randomised algorithms.

The positive side: if the diagram's underlying graph has a generalised flow, a deterministic extraction algorithm exists (Duncan, Kissinger, Perdrix and van de Wetering), and Backens et al. extend extraction to further classes of diagrams. Rewrite strategies that preserve such a flow therefore always return a circuit.

Holds when
  • Input is an arbitrary ZX diagram promised to denote a unitary; the output must be a circuit of size polynomial in the diagram.
  • Worst case; restricted classes of diagrams (for example those with generalised flow) have efficient extraction.

Worked Examples

Two CNOTs cancel

By the basic rules, CNOT=2 D\mathrm{CNOT} = \sqrt{2}\, D, where DD is a Z spider Z01,2Z^{1,2}_0 on the control joined by one wire to an X spider X02,1X^{2,1}_0 on the target. So CNOT2=2D′\mathrm{CNOT}^2 = 2 D', where D′D' is DD followed by DD. Fuse the two Z spiders on the control (they share the control wire) into one Z spider with an input, an output and two side legs; fuse the two X spiders on the target likewise. The fused spiders are joined by two parallel wires. Compute the resulting map directly: for control value xx, the X spider receives ∣x⟩∣x⟩\ket{x}\ket{x} on its side legs, and

(∣+⟩⟨+∣⊗⟨+∣⟨+∣+∣−⟩⟨−∣⊗⟨−∣⟨−∣) ∣x⟩∣x⟩=12(∣+⟩⟨+∣+∣−⟩⟨−∣)=12I,\big(\ket{+}\bra{+} \otimes \bra{+}\bra{+} + \ket{-}\bra{-} \otimes \bra{-}\bra{-}\big)\,\ket{x}\ket{x} = \tfrac{1}{2}\big(\ketbra{+}{+} + \ketbra{-}{-}\big) = \tfrac{1}{2} I ,

because ⟨±∣x⟩2=12\braket{\pm}{x}^2 = \tfrac{1}{2}. The control side is then ∑x∣x⟩⟨x∣=I\sum_x \ketbra{x}{x} = I, so D′=12I⊗ID' = \tfrac{1}{2} I \otimes I and CNOT2=I\mathrm{CNOT}^2 = I. The step "two parallel wires between spiders of different colours can be cut, at the cost of a scalar" is the Hopf rule; here the scalar is 12\tfrac{1}{2}.

Merging TT gates through a CNOT

T=diag⁡(1,eiπ/4)=Zπ/41,1T = \operatorname{diag}(1, e^{i\pi/4}) = Z^{1,1}_{\pi/4} exactly. Consider the circuit Tc  CNOT  TcT_{\mathrm{c}}\; \mathrm{CNOT}\; T_{\mathrm{c}} with both TT gates on the control. The control of the CNOT is a Z spider, so all three Z spiders on the control wire fuse into one, with phase π/4+0+π/4=π/2\pi/4 + 0 + \pi/4 = \pi/2. Unfusing gives CNOT  Sc\mathrm{CNOT}\; S_{\mathrm{c}} with S=Zπ/21,1S = Z^{1,1}_{\pi/2}: the TT-count drops from 2 to 0. This is the simplest case of what phase teleportation does globally.

Algorithms and Implementations

Graph-theoretic simplification. Duncan, Kissinger, Perdrix and van de Wetering convert a circuit to a diagram of Z spiders joined by Hadamard edges and remove Clifford spiders using rewrites derived from local complementation and pivoting. They prove that the simplified diagrams always have a generalised flow, so a circuit can be extracted deterministically; for Clifford circuits this gives a new normal form, asymptotically optimal in size.

TT-count reduction. Kissinger and van de Wetering add phase teleportation: run the simplification only to discover which non-Clifford phases can be merged, then apply those mergers to the original circuit, leaving all other gates in place. On the ancilla-free benchmark circuits they report matching or improving on earlier TT-count methods for most circuits, by up to 50% on some. Both methods are implemented in the open-source PyZX library.

Extraction in general. Extraction is #P-hard for arbitrary diagrams of unitaries, so practical rewrite strategies keep diagrams inside classes with known extraction procedures (Backens et al.).

Applications

  • Measurement-based computation. Graph states are diagrams of Z spiders joined by Hadamard edges, single-qubit measurements are spiders with one leg, and the flow conditions that make a measurement pattern deterministic (see measurement flow) are the same conditions that make circuit extraction possible. See measurement-based quantum computing.
  • Lattice surgery. de Beaudrap and Horsman show that the merge and split operations of lattice surgery on surface codes are described exactly by Z and X spiders, so lattice-surgery procedures can be designed and verified as diagrams.
  • Fault tolerance. Bombin et al. use ZX diagrams to describe circuit-based, measurement-based and fusion-based fault-tolerant protocols in one framework.
  • Equivalence checking. Rewriting the composite of one circuit with the inverse of another towards the identity proves equivalence when it succeeds; completeness guarantees a rewrite exists, though not that a given strategy finds it.

Computational Complexity

Interpreting a diagram is a tensor contraction, so evaluating a diagram exactly is as hard as strong simulation of circuits in general. Extracting a circuit from an arbitrary diagram of a unitary is #P-hard.

Limitations and Common Pitfalls

  • Scalars. Many papers draw diagrams "up to a nonzero scalar". That is harmless for unitaries but wrong for probabilities, postselection and sums of diagrams; keep scalars (as in the worked examples) whenever they matter.
  • Which rule set. "The ZX calculus is complete" refers to a particular axiomatisation and phase fragment. The original rules of Coecke and Duncan needed the Euler decomposition added even to reason about graph states (Duncan and Perdrix), and they are incomplete once arbitrary phases are allowed.
  • Completeness is not an algorithm. A complete rule set guarantees that a rewrite sequence exists but gives no bound on its length or a way to find it.
  • Simplified diagrams are not circuits. After aggressive rewriting a diagram may have no efficient extraction; optimisers must preserve a flow-like invariant.
  • Two-qubit gate counts. TT-count reductions can come with more CNOTs after extraction; report both counts.

The categorical setting of the calculus (dagger-compact categories and interacting Frobenius algebras) is developed in Coecke and Duncan and Coecke and Kissinger; see also category theory. For complete axiomatisations with arbitrary phases see Hadzihasanovic, Ng and Wang and Vilmart; for the Clifford+T fragment, Jeandel, Perdrix and Vilmart.

Builds on

Open in the knowledge graph

Contributions about this record

Nobody has published a contribution about it yet.

Publish a result, reproduction or commentPropose a correction to this page

References

  1. Bob Coecke, Ross Duncan (2011). Interacting quantum observables: categorical algebra and diagrammatics. New Journal of Physics 13, 043016. doi:10.1088/1367-2630/13/4/043016arXiv:0906.4725
  2. Bob Coecke, Aleks Kissinger (2017). Picturing Quantum Processes. Cambridge University Press. doi:10.1017/9781316219317
  3. Miriam Backens (2014). The ZX-calculus is complete for stabilizer quantum mechanics. New Journal of Physics 16, 093021. doi:10.1088/1367-2630/16/9/093021arXiv:1307.7025
  4. Christian Schröder de Witt, Vladimir Zamdzhiev (2014). The ZX-calculus is incomplete for quantum mechanics. Electronic Proceedings in Theoretical Computer Science 172, 285-292. doi:10.4204/EPTCS.172.20arXiv:1404.3633
  5. Emmanuel Jeandel, Simon Perdrix, Renaud Vilmart (2018). A complete axiomatisation of the ZX-calculus for Clifford+T quantum mechanics. Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 2018), 559-568. doi:10.1145/3209108.3209131arXiv:1705.11151
  6. Amar Hadzihasanovic, Kang Feng Ng, Quanlong Wang (2018). Two complete axiomatisations of pure-state qubit quantum computing. Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 2018), 502-511. doi:10.1145/3209108.3209128
  7. Renaud Vilmart (2019). A near-minimal axiomatisation of ZX-calculus for pure qubit quantum mechanics. 34th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 2019), 1-10. doi:10.1109/LICS.2019.8785765arXiv:1812.09114
  8. Ross Duncan, Simon Perdrix (2009). Graph states and the necessity of Euler decomposition. Mathematical Theory and Computational Practice (CiE 2009), Lecture Notes in Computer Science 5635, 167-177. doi:10.1007/978-3-642-03073-4_18arXiv:0902.0500
  9. Ross Duncan, Aleks Kissinger, Simon Perdrix, John van de Wetering (2020). Graph-theoretic simplification of quantum circuits with the ZX-calculus. Quantum 4, 279. doi:10.22331/q-2020-06-04-279arXiv:1902.03178
  10. Aleks Kissinger, John van de Wetering (2020). Reducing the number of non-Clifford gates in quantum circuits. Physical Review A 102, 022406. doi:10.1103/PhysRevA.102.022406arXiv:1903.10477
  11. Miriam Backens, Hector Miller-Bakewell, Giovanni de Felice, … John van de Wetering (2021). There and back again: A circuit extraction tale. Quantum 5, 421. doi:10.22331/q-2021-03-25-421arXiv:2003.01664
  12. Niel de Beaudrap, Aleks Kissinger, John van de Wetering (2022). Circuit extraction for ZX-diagrams can be #P-hard. 49th International Colloquium on Automata, Languages, and Programming (ICALP 2022), LIPIcs 229, 119:1-119:19. doi:10.4230/LIPIcs.ICALP.2022.119arXiv:2202.09194
  13. Niel de Beaudrap, Dominic Horsman (2020). The ZX calculus is a language for surface code lattice surgery. Quantum 4, 218. doi:10.22331/q-2020-01-09-218arXiv:1704.08670
  14. Hector Bombin, Daniel Litinski, Naomi Nickerson, … Sam Roberts (2024). Unifying flavors of fault tolerance with the ZX calculus. Quantum 8, 1379. doi:10.22331/q-2024-06-18-1379arXiv:2303.08829
  15. Michael A. Nielsen, Isaac L. Chuang (2010). Quantum Computation and Quantum Information (10th Anniversary Edition). Cambridge University Press. doi:10.1017/CBO9780511976667

Contributors

  • KetQat maintainers · @ketqatConceptualization; Supervision (CRediT roles)
  • Claude (AI drafting assistant)Writing, original draft (CRediT roles)

Review history

  1. Automated source check · Pass · 2026-12-01 · Independent automated verification pass (AI, not the drafting session)

    Topic body only; embedded records carry their own review states. Worked examples checked numerically (numpy): CNOT = sqrt2 D, D.D = I/2 (so CNOT^2 = I with Hopf scalar 1/2), and T_c CNOT T_c = CNOT S_c. Claims compared with: Coecke and Duncan, arXiv 0906.4725 (introduction of the calculus, universality); Duncan et al., arXiv 1902.03178 abstract (graph-theoretic simplification, gflow, Clifford normal form); Kissinger and van de Wetering, arXiv 1903.10477 abstract and Section 1 (phase teleportation, ancilla-free benchmarks, matches or beats earlier methods on most circuits, up to 50%); de Beaudrap and Horsman, arXiv 1704.08670 abstract; Bombin et al., arXiv 2303.08829 abstract; Duncan and Perdrix, arXiv 0902.0500; Schröder de Witt and Zamdzhiev, arXiv 1404.3633; de Beaudrap, Kissinger and van de Wetering, arXiv 2202.09194. Crossref metadata of the cited references matched.

Revision history

  1. 2026-12-01Content release 2.1.0: 35 more topics, an independent source check of every record, intake hardening (#17)80537b7e

Current revision 5f922913ab6922a7. Source file knowledge/records/topic/zx-calculus.md in the content repository (readable there once it is public).