Borrow a busy qubit: toggle twice
A product of three bits, x ^= a·b·c, needs a scratch qubit to hold a·b on the way. At the circuit's widest point there is no clean qubit left to give it.
Use any busy qubit l instead, whatever it holds. Write a·b onto it, read it into x, write a·b again, read again. The two reads see d and d XOR a·b, so the unknown value d cancels and only the product arrives in x. The busy qubit ends as it started.
Before: A clean scratch qubit, erased by measurement, 2. After: A busy qubit, toggled twice, 4 (toffolis per product · clean qubits 1 → 0).
- Toffolis: Higher. 2 → 4 per three-way product.
- Qubits: Lower. One clean qubit fewer.
- Toffoli × qubit scores: Depends. Pays only where that clean qubit sets the peak width.
- Q² × Toffoli (DQI): Depends. Same test, and a peak qubit is worth twice as much.
from qiskit import QuantumCircuit
def before(): # x ^= a b c with a clean scratch t
a, b, c, x, loan, t = range(6)
qc = QuantumCircuit(6, 1)
qc.ccx(a, b, t)
qc.ccx(t, c, x)
qc.h(t); qc.measure(t, 0); qc.reset(t)
with qc.if_test((qc.clbits[0], 1)):
qc.cz(a, b)
return qcdef after(): # no clean qubit: borrow a busy one
a, b, c, x, loan, t = range(6)
qc = QuantumCircuit(6)
qc.ccx(a, b, loan) # loan holds d XOR ab
qc.ccx(loan, c, x)
qc.ccx(a, b, loan) # loan holds d again
qc.ccx(loan, c, x) # the two reads differ by ab
return qc- NEEDS
- l is none of a, b, c, x, and nothing else touches l during the four gates
- SEEN IN
- Barenco et al. (1995). In ecdsa.fail, nasqret's 654-qubit step rewrites every clean product of three this way by matching the emitted gate list; odinfree's 824-qubit row uses the phase form to drop the one clean lane that set the peak
- PROOF
- QCP.P27.toggle_twice and .phase_toggle_twice, any wires