Table of Contents

ZX-calculus

ZX-calculus is a graphical language for reasoning about quantum circuits, built from diagrams of green and red nodes connected by wires instead of matrix algebra. Each diagram represents a linear map, and two diagrams represent the same map if and only if one can be rewritten into the other using a small set of graphical rules. This turns circuit equivalence, normally a matter of multiplying unitary matrices, into diagram manipulation.

A green node represents a phase gate in the Z basis, a red node the same in the X basis, and a node's degree (how many wires connect to it) doesn't matter to its meaning, only its color and phase. Wires carry no direction and can be bent, crossed, or slid past each other freely, since ZX-calculus diagrams only encode connectivity, not circuit layout.

  Green spider (Z-phase):        Red spider (X-phase):
    |  |                            |  |
     \ /                             \ /
      o  --- angle α                 o  --- angle α
     / \                             / \
    |  |                            |  |

Rewrite rules

The core rewrite rules include spider fusion (two same-colored nodes connected by a wire merge into one, adding their phases), the bialgebra rule (how green and red spiders interact), and the identity rule (a phaseless two-legged spider is just a wire). These rules are complete for the Clifford fragment of quantum mechanics, meaning any true equation between Clifford circuits can be proven using only diagram rewrites, no matrices required.

Where it's used

ZX-calculus is the underlying representation in circuit optimizers like PyZX, which simplify circuits by fusing spiders and canceling redundant structure before converting back to gates. It's also used to design and verify error-correction codes, since stabilizer measurements and lattice surgery operations translate naturally into spider diagrams. Related graphical calculi include ZW-calculus and ZH-calculus, which extend the same idea to represent operations ZX-calculus alone handles awkwardly.