Reversible arithmetic is a useful workload for studying quantum compilation. Addition and carry propagation have a regular logical structure, and there is a straightforward classical reference for the numerical result. Yet a quantum arithmetic circuit has an additional requirement: it must preserve the intended transformation of quantum amplitudes.
The difference becomes important when a compiler synthesizes operations such as the Toffoli gate using the native gates of a processor.
Carry propagation and circuit structure
An ordinary binary adder propagates a carry from one position to the next. A reversible ripple-carry construction must preserve enough information to undo temporary calculations. The carry operations typically act on a small number of qubits, while the carry itself creates a dependency across successive positions.
This combination makes placement important. A mapping that keeps successive carry operations near one another can reduce the distance over which information needs to move. The arrangement of neighboring reversible gates can also expose opportunities for cancellation during synthesis. A structured hand-written circuit is therefore a useful reference for a general compiler.
When a truth table is not enough
A Toffoli gate maps the computational basis state |a,b,c⟩ to |a,b,c⊕ ab⟩. Checking every basis input verifies the output bit labels. It does not by itself determine the phase attached to each output amplitude.
Suppose an alternative reversible operation performs the same permutation of basis states but attaches a minus sign to one of them. If each basis state is prepared and measured separately in the computational basis, the observed bit strings are identical to those of the ordinary Toffoli. On a superposition, however, the sign can change the interference pattern in later operations.
The following mathematical example represents both operations on the uniform superposition of the basis states. It is a simplified phase-sensitive verification example rather than a native gate decomposition. The two operators share the same permutation but differ by an input-dependent phase.
Illustration: standalone Python calculation.
from math import sqrt, isclose
N = 8
def permutation(i):
a,b,c = (i >> 2)&1, (i >> 1)&1, i&1
return 4*a + 2*b + (c ^ (a & b))
def apply(state, phase_variant=False):
out = [0.0]*N
for i, amplitude in enumerate(state):
sign = -1 if phase_variant and i == 6 else 1
out[permutation(i)] += sign*amplitude
return out
for i in range(N):
basis = [float(j == i) for j in range(N)]
assert [x*x for x in apply(basis)] == [x*x for x in apply(basis,True)]
plus = [1/sqrt(N)]*N
u,v = apply(plus),apply(plus,True)
overlap = abs(sum(a*b for a,b in zip(u,v)))
assert isclose(overlap, 0.75)
assert isclose(overlap**2, 9/16)
print('State overlap magnitude:', overlap) The resulting state overlap has magnitude 3/4, so the squared overlap (fidelity) is 9/16. They are distinguishable by an appropriate quantum measurement, even though the basis-state output labels agree. A phase shared by all amplitudes would have no such effect; the relative phase is what matters.
Compare complete arithmetic operations
Relative-phase reversible gates can be valuable building blocks. For example, when an intermediate calculation is followed by an appropriate inverse, phases introduced in the calculation can sometimes cancel. Whether this happens depends on the intervening operation and the full circuit identity. Substituting a lower native-gate-count implementation solely because it returns the same output bits can alter the computation.
A compiler benchmark should therefore compare equivalent complete operations with consistent input and output conventions. State how carry inputs, carry outputs and auxiliary qubits are handled. Include strong structured references, such as a layout designed around the carry chain and a reference that uses verified phase-canceling constructions where appropriate. Use the same available hardware connections and native gate set for all implementations.
Verification at different sizes
Small arithmetic circuits allow a direct matrix or statevector comparison. Larger ones may require a structural proof, verification of composable subcircuits or application-specific checks with clearly stated scope. Checking a selection of classical input-output pairs is useful regression testing, but the result should be described as such. The same is true for testing a few superpositions: it can identify errors without proving the equivalence of an arbitrary large circuit.
Gate count and scheduled depth become meaningful once the compared circuits implement the same arithmetic operation under the required assumptions. That is the basis for using arithmetic to investigate compiler quality.
Explore the 4colors Quantum Compiler with a circuit whose input, output and auxiliary-qubit conventions you can check independently.