Synthesis algorithms —
Every NCT gate is self-inverse:
Cancellation only fires on adjacent pairs, so the second tool creates adjacency: rules for when two neighbouring gates may swap places without changing the circuit. The classification is a pleasant exercise in thinking about who reads and who writes each wire:
| Situation | Commute? | Why |
|---|---|---|
| disjoint wires | always | they touch different bits entirely |
| shared wire is a control of both | yes | both only read it, neither writes it |
| shared wire is the target of both | yes | two XORs onto the same bit — XOR is commutative |
| target of one is a control of the other | no (in general) | one writes what the other reads — order changes what is read |
The classic counterexample for the last row: NOT on wire
The heavyweight tool: a template is a known circuit identity — a short gate sequence
equal to a cheaper one. An optimizer slides a small window (a "peephole") along the cascade, matches
templates (using commutation to herd the participating gates together), and rewrites. Here is a
classic, worth working through because the algebra is two lines. Take the window: Toffoli
Four gates — two of them expensive Toffolis — equal one CNOT
A template library full of identities like this (and their mirror images, and their control-permuted variants) is the core of production reversible-circuit optimizers. Each rewrite can expose fresh cancellations, so the passes loop until nothing fires — a fixpoint.
The simplest possible optimizer — cancel adjacent identical gates, repeat until stable — is a dozen lines. Watch how removing one pair brings another pair together:
The first pass removes the CNOT pair and the NOT pair; only then do the two Toffolis become adjacent and cancel on the second pass. Six gates, net effect: nothing at all. Real optimizers interleave commutation and template passes in the same loop — but the fixpoint skeleton is exactly this.
How do you know your optimizer is any good? The field's shared yardstick is RevLib — a public library of reversible benchmark functions and circuits (adders, cipher pieces, hidden-weight-bit functions…) with the best known costs on record. Publishing a synthesis paper without RevLib numbers is like claiming a sprint record without a stopwatch. And which metric should the optimizer chase? Increasingly, the one downstream: on fault-tolerant quantum hardware the crushing expense is the T gate, with a Toffoli costing about 7 of them — so a rewrite that trades one Toffoli for three CNOTs is an excellent deal there, even though the raw gate count went up. Optimization is always toward a cost model; change the price list and the best circuit changes too.
Why settle for peephole nibbling — why not compute the true minimum-cost circuit? Because optimal
reversible synthesis hits a combinatorial wall: the space of cascades grows exponentially with gate
count, and on
Two identical CNOTs with a stranger between them do not automatically cancel — first ask whether the stranger commutes past one of them. If the middle gate shares only controls with them, fine: slide it out, cancel the pair. But if it writes a wire the pair reads (its target is their control), the swap is illegal and the pair genuinely cannot meet — deleting them changes the function. The order of operations matters even for the optimizer itself: cancel first and you may miss rewrites; commute blindly and you corrupt the circuit. Every rewrite must cite its rule.