Circuit Identities and Simplification
Once a circuit has been decomposed into a native gate set it is rarely optimal. The same unitary can be written in many ways, and a transpiler's optimization stage rewrites the gate list into a cheaper equivalent without changing the unitary it implements. The rewrites are driven by a catalogue of circuit identities — small, provable equivalences applied repeatedly until no more fire.
Three families of identity
Cancellation. A gate adjacent to its own inverse vanishes. Since , , , and CNOT are self-inverse,
and , . Spotting and deleting such pairs is the single most productive optimization.
Merging. Rotations about the same axis add their angles:
A run of -rotations collapses to one. If the total is a multiple of it disappears entirely.
Conjugation / basis change. Gates can be transformed into one another by surrounding gates:
These let the optimizer slide an awkward gate past a Hadamard into a friendlier form.
Commutation enables the others
Identities only fire when the gates involved are adjacent. Most rewriting power therefore comes from commutation rules that let the optimizer reorder gates to bring an inverse pair together. Two gates commute when they act on disjoint qubits, and many that share qubits commute too — for example, two CNOTs that share a control commute, as do two that share a target. The optimizer repeatedly commutes gates and then cancels or merges, a loop that is the core of peephole circuit optimization.
Correctness is unitary equivalence
Two circuits are interchangeable precisely when they implement the same unitary (up to global phase). That is the contract every simplification must honour, and it is exactly what the grader enforces by comparing full matrices — a smaller gate count is worthless if the operation changed.
Try it
Realize using only CNOTs — no swap(). The grader compares
the complete two-qubit unitary, so an incorrect rewrite will fail even if it is
shorter.
Sign in on the full site to ask questions and join the discussion.