Computing Library › Quantum Logic Gates
Quantum Logic Gates

Gate Identities and Circuit Equivalences

The algebraic rewrite rules that let compilers transform one circuit into an equivalent, cheaper one.

Why identities matter

Two circuits are equivalent if they implement the same unitary, possibly up to a global phase. Compilers use a library of small provable identities as rewrite rules, repeatedly substituting a cheaper subcircuit for an equal one until the circuit stops shrinking. Every optimization pass rests on these identities being exactly true.

Fundamental single-qubit identities

Kronos motion — thermal gate

Two-qubit identities

Commutation rules

A control commutes with any Z-diagonal gate on the control line; a target commutes with any X-basis gate on the target line. Two gates that act on disjoint qubits always commute. These rules let a compiler slide gates past one another to expose cancellations.

CNOT (for reference)
1000010000010010
python
import numpy as np
H=np.array([[1,1],[1,-1]])/np.sqrt(2)
X=np.array([[0,1],[1,0]]); Z=np.array([[1,0],[0,-1]])
print(np.allclose(H@X@H, Z))  # HXH = Z

Up to global phase

Many identities hold only up to a global phase, which is harmless in isolation but matters under control. A rewrite engine must therefore track phase where a subcircuit may later be controlled. See global phase and transpilation.