Garbage Qubits and Uncomputation

A classical processor overwrites its scratch memory a thousand times a second without a second thought; a quantum processor cannot overwrite anything. Every quantum gate is unitary, hence a bijection on Hilbert space that preserves inner products, so no register is ever cleared — information written to an ancilla during a computation has nowhere to disappear to. When a reversible circuit UfU_f evaluates a function ff, the intermediate values scribbled onto the workspace survive at the end as a garbage register g(x)g(x): a deterministic, bulky, input-dependent record of everything the computation did along the way. The damage garbage does is invisible in the answer's statistics and fatal to its coherence. Quantum speedups live on interference — amplitudes for different computational branches xx must be allowed to add and cancel. But if the global state is ∑xαx ∣x⟩∣f(x)⟩∣g(x)⟩\sum_x \alpha_x\,|x\rangle|f(x)\rangle|g(x)\rangle with g(x)g(x) distinct for distinct xx, the garbage is a perfect which-path record; tracing it out leaves a decohered, classically mixed answer, exactly as if an environment had measured which branch was taken. The prism-and-slits intuition is literal here: mark the path and the fringes vanish. Charles Bennett's 1973 argument for reversible computation supplies the cure, distilled for quantum circuits into the compute–copy–uncompute pattern. Run UfU_f to produce the answer alongside its garbage, copy only the answer into a fresh register with CNOTs — legal because copying a fixed-basis label is not cloning an unknown state — and then run the entire computation backwards. The inverse Uf−1U_f^{-1} deterministically re-derives every intermediate scratch value from the still-present input and threads each garbage qubit back to ∣0⟩|0\rangle. The workspace disentangles and factors out, leaving a clean ∣x⟩∣f(x)⟩∣0⋯0⟩|x\rangle|f(x)\rangle|0\cdots0\rangle that interferes perfectly. Uncomputation is not an optimisation; it is a load-bearing primitive of the whole quantum circuit model, and it costs only a factor near two in time.

Key takeaways
  • A reversible evaluation of ff writes intermediate values onto scratch qubits that cannot vanish — they persist as garbage g(x)g(x), entangled with the answer and destroying the phase coherence interference needs.
  • The fix is Bennett's compute–copy–uncompute: run UfU_f, CNOT the answer into a clean output register, then apply Uf−1U_f^{-1} to return every scratch qubit to ∣0⟩|0\rangle.
  • After uncomputation the workspace factors out as ⊗ ∣0⟩⊗a\otimes\,|0\rangle^{\otimes a}, leaving (∑xαx∣x⟩∣f(x)⟩)⊗∣0⟩⊗a\big(\sum_x\alpha_x|x\rangle|f(x)\rangle\big)\otimes|0\rangle^{\otimes a} — a product across the scratch, so the answer can interfere in later steps like phase kickback, diffusion, or a QFT.
  • The price is a constant factor: gates →2G+m\to 2G+m, depth →2D+1\to 2D+1, with only the mm output qubits persisting while the aa scratch qubits are recycled.
  • Skipping the uncompute is a silent bug — the answer register still measures to the right distribution, yet Deutsch–Jozsa, Grover, and phase estimation all fail because the amplitudes no longer interfere.
  • Unconditional reset to ∣0⟩|0\rangle is forbidden: it is non-unitary (measure-and-discard) and decoheres the answer exactly as tracing out garbage would; only running the inverse on data still present is reversible.
  • Key idea: To remove garbage, do not erase it (irreversible, forbidden) — copy the answer out and run the computation in reverse. Unitarity guarantees Uf−1Uf=IU_f^{-1}U_f=I returns every scratch qubit exactly to ∣0⟩|0\rangle, disentangling the workspace so the answer regains coherence.
The core insight

To remove garbage, do not try to erase it (irreversible, forbidden); instead copy the answer out and run the computation in reverse. Unitarity guarantees Uf−1Uf=IU_f^{-1}U_f=I returns every scratch qubit exactly to ∣0⟩|0\rangle, disentangling the workspace so the answer register regains coherence.

Where this lives today

Uncomputation is not a historical footnote — it is compiled into essentially every serious quantum program. Shor's factoring algorithm spends the overwhelming majority of its qubits and gates on reversible modular arithmetic, and every adder, multiplier, and modular-reduction block is uncomputed the moment its result is consumed, both to recycle the scratch and to keep the period register coherent for the final quantum Fourier transform; leaving garbage in the arithmetic would entangle it with the exponent and prevent the QFT from ever resolving the period. Grover search and amplitude amplification return any multi-controlled marking ancilla to ∣0⟩|0\rangle before each diffusion step, because a marker left entangled makes successive iterations reflect about shifting axes and breaks the amplification recurrence. In modern compiler toolchains — Qiskit, Q#, Quipper, Cirq — automatic ancilla management and reversible-circuit synthesis are entire subsystems whose job is to schedule uncomputation and reuse qubits, and the reversible-pebbling literature (Meuli, Soeken, and others) is actively used to minimise qubit counts for fault-tolerant resource estimates, where every logical qubit costs thousands of physical ones. The open frontier is space–time optimality: given a target circuit and a hard cap on qubits, find the uncomputation schedule that minimises depth — a problem that is NP-hard in general and drives current work on measurement-based uncomputation and catalytic "borrowed" ancillas that need not start in ∣0⟩|0\rangle.

The physical picture

Think of the garbage register as a tiny camera bolted to the side of the computation, photographing which branch xx the machine took. As long as the photograph exists and differs from branch to branch, the universe knows the path, and paths that are known cannot interfere — this is exactly the double-slit experiment with the slits marked. Uncomputation does not delete the camera; it replays the entire computation backwards so that every photograph is un-taken, restoring the ignorance on which interference depends. The mechanism is completely deterministic: because the input register is never disturbed, the inverse circuit has all the data it needs to walk each garbage qubit back down the exact sequence of gates that wrote it, like rewinding a Turing machine through its own history tape. The first figure is the pattern itself — the three-column compute–copy–uncompute skeleton that every clean quantum oracle is built from. Notice what each column does to the workspace: UfU_f fills the scratch with ∣f(x)⟩∣g(x)⟩|f(x)\rangle|g(x)\rangle, the CNOT column siphons a copy of the answer into a spectator output register, and Uf−1U_f^{-1} empties the scratch back to ∣0⟩|0\rangle. The output wire is deliberately untouched by the inverse, which is the whole trick — the one bit of information worth keeping is quarantined before the rewind erases everything else.

Figure
Compute copy uncompute: U_f writes answer f(x) and garbage g(x) onto the scratch, CNOTs copy only the answer onto a spectator output wire, then the inverse U_f† empties the scratch back to all-zeros so it factors out — the output holds f(x) while the input x is returned untouched
The clean oracle Ũ_f = U_f⁻¹ ∘ COPY ∘ U_f (scratch out, answer kept) time → |x⟩ input |0⟩ᵃ scratch |0⟩ output U_f COPY (CNOTs) U_f⁻¹ |f(x)⟩|g(x)⟩ |0⟩ᵃ back holds f(x) x returned

Garbage matters because interference is fragile, and the cost of fixing it is startlingly small. The second figure makes the trade concrete for a representative subroutine — a reversible multiplier with G=120G=120 gates, depth D=45D=45, drawing on a=8a=8 scratch ancillas to produce an m=4m=4 bit answer. Bennett's construction runs it forward and back, so the gate count roughly doubles to 2G+m=2442G+m=244 and the depth to 2D+1=912D+1=91, but the peak width a+m=12a+m=12 collapses to just the m=4m=4 output qubits once the scratch is recycled. A factor of two in time buys back both the qubits and, far more importantly, the coherence.

Figure
Resource cost of Bennett clean uncomputation for a multiplier with G = 120 gates, depth D = 45, a = 8 scratch, m = 4 output: gates rise to 2G+m = 244 and depth to 2D+1 = 91 (roughly ×2), while persistent width drops from a+m = 12 held-dirty to m = 4 once the scratch is recycled
Bennett cost: gates ×2, depth ×2, but persistent qubits shrink to m count (gates · depth · qubits) 120 244 gates 45 91 depth 12 4 persistent width raw U_f (leaves garbage) Bennett clean Ũ_f

A clean mental ledger closes the picture. Before the uncompute the global state is ∑xαx∣x⟩ ∣f(x)⟩out ∣f(x)⟩∣g(x)⟩scratch\sum_x\alpha_x|x\rangle\,|f(x)\rangle_{\text{out}}\,|f(x)\rangle|g(x)\rangle_{\text{scratch}}; after Uf−1U_f^{-1} acts on input-plus-scratch it becomes (∑xαx∣x⟩∣f(x)⟩out)⊗∣0⋯0⟩\big(\sum_x\alpha_x|x\rangle|f(x)\rangle_{\text{out}}\big)\otimes|0\cdots0\rangle. The tensor factorisation of the ∣0⋯0⟩|0\cdots0\rangle — the same workspace state in every branch — is the signature of success. If instead the scratch still depends on xx, the factorisation fails and the answer stays decohered.

The core equations

The starting point is the honest picture of a real reversible circuit: it does not compute ff in a vacuum, it computes ff plus whatever bookkeeping the gates needed. That bookkeeping is the garbage, and equation (1) names it explicitly.

∣x⟩∣0⟩⊗a → Uf  ∣x⟩∣f(x)⟩∣g(x)⟩(1)|x\rangle|0\rangle^{\otimes a}\ \xrightarrow{\ U_f\ }\ |x\rangle|f(x)\rangle|g(x)\rangle \qquad (1)

where: ∣x⟩|x\rangle — the nn-qubit input register, basis label xx; ∣0⟩⊗a|0\rangle^{\otimes a} — aa ancilla/scratch qubits initialised to zero; f(x)f(x) — the desired output value; g(x)g(x) — garbage, the residual scratch, a deterministic function of xx; UfU_f — the reversible (unitary) circuit that evaluates ff in place. Reading: the workspace does not come back empty — it comes back full of g(x)g(x). On a superposition of inputs the garbage becomes an entangling agent. Because UfU_f is linear it acts on every branch at once, gluing each branch's answer to that branch's distinct garbage.

∣Ψ⟩=∑xαx ∣x⟩ ∣f(x)⟩ ∣g(x)⟩(2)|\Psi\rangle=\sum_x \alpha_x\,|x\rangle\,|f(x)\rangle\,|g(x)\rangle \qquad (2)

where: αx\alpha_x — the input amplitudes (all equal to 2−n/22^{-n/2} after a Hadamard layer); ∣g(x)⟩|g(x)\rangle — branch-distinct garbage acting as a which-path record. Reading: this state is entangled across the workspace boundary, and that entanglement is the disease uncomputation treats. The copy step is a fan-out of a computational-basis label, not a clone. Bitwise CNOTs, controlled on the answer bits and targeting a fresh output register, imprint f(x)f(x) where we can protect it.

∣x⟩∣f(x)⟩∣g(x)⟩∣0⟩out → CNOTs  ∣x⟩∣f(x)⟩∣g(x)⟩∣f(x)⟩out(3)|x\rangle|f(x)\rangle|g(x)\rangle|0\rangle_{\text{out}}\ \xrightarrow{\ \text{CNOTs}\ }\ |x\rangle|f(x)\rangle|g(x)\rangle|f(x)\rangle_{\text{out}} \qquad (3)

where: ∣0⟩out|0\rangle_{\text{out}} — a fresh output register, one qubit per output bit; CNOTs\text{CNOTs} — mm bitwise controlled-NOTs. Reading: on a basis label this is legal fan-out (unitary); on a superposition it makes a GHZ-type correlation, never two free copies, so no-cloning is untouched. Now the rewind. Applying the inverse circuit to input-plus-scratch undoes equation (1) branch by branch, and because the input is intact the scratch is driven back to exactly its initial value.

Uf−1 ∣x⟩∣f(x)⟩∣g(x)⟩=∣x⟩∣0⟩⊗a(4)U_f^{-1}\,|x\rangle|f(x)\rangle|g(x)\rangle=|x\rangle|0\rangle^{\otimes a} \qquad (4)

where: Uf−1U_f^{-1} — the inverse circuit, every gate of UfU_f daggered and applied in reverse order. Reading: Uf−1Uf=IU_f^{-1}U_f=I is not an approximation — the scratch returns to ∣0⟩⊗a|0\rangle^{\otimes a} identically, independent of xx. Composing the three columns defines the garbage-free oracle and its coherent output. The workspace enters and leaves in ∣0⟩⊗a|0\rangle^{\otimes a}, so it drops out of the sum as a tensor factor.

∣x⟩∣0⟩⊗a∣0⟩out → U~f  ∣x⟩∣0⟩⊗a∣f(x)⟩out,U~f=Uf−1∘COPY∘Uf(5)|x\rangle|0\rangle^{\otimes a}|0\rangle_{\text{out}}\ \xrightarrow{\ \widetilde U_f\ }\ |x\rangle|0\rangle^{\otimes a}|f(x)\rangle_{\text{out}},\qquad \widetilde U_f=U_f^{-1}\circ\text{COPY}\circ U_f \qquad (5)

where: U~f\widetilde U_f — the Bennett clean evaluator. Reading: on a superposition this produces (∑xαx∣x⟩∣f(x)⟩out)⊗∣0⟩⊗a\big(\sum_x\alpha_x|x\rangle|f(x)\rangle_{\text{out}}\big)\otimes|0\rangle^{\otimes a}, the coherent answer with the scratch factored off. For many algorithms the useful oracle is not "value into a clean target" but "phase onto the input". Storing the output XOR-style makes UfU_f its own inverse, and a ∣−⟩|-\rangle target converts the stored bit into a kicked-back sign.

Uf∣x⟩∣y⟩=∣x⟩∣y⊕f(x)⟩,Uf∣x⟩∣−⟩=(−1)f(x)∣x⟩∣−⟩(6)U_f|x\rangle|y\rangle=|x\rangle|y\oplus f(x)\rangle,\qquad U_f|x\rangle|-\rangle=(-1)^{f(x)}|x\rangle|-\rangle \qquad (6)

where: ⊕\oplus — bitwise XOR, self-inverse so Uf2=IU_f^2=I; ∣−⟩=12(∣0⟩−∣1⟩)|-\rangle=\tfrac{1}{\sqrt2}(|0\rangle-|1\rangle) — the eigenstate that turns a bit-flip into the eigenphase (−1)f(x)(-1)^{f(x)}. Reading: phase kickback presumes a pure phase — any leftover garbage entangled with the branch spoils the eigenvalue relation and the kickback fails.

Derivation ACompute copy uncompute on a full superposition

The goal is to prove, register by register, that Bennett's three-column procedure converts a garbage-laden superposition into a coherent, factorised answer state — the exact guarantee every clean-oracle construction relies on. We start from an equal superposition over all inputs, carry all four registers (input, scratch, output) through compute, copy, and uncompute in turn, and show at the end that the scratch pulls out of the sum as a bare tensor factor, which is the definition of "the answer can interfere again".

Step 1. Begin with ∑xαx∣x⟩∣0⟩⊗a∣0⟩out\sum_x\alpha_x|x\rangle|0\rangle^{\otimes a}|0\rangle_{\text{out}} and apply UfU_f to input-plus-scratch, giving ∑xαx∣x⟩∣f(x)⟩∣g(x)⟩∣0⟩out\sum_x\alpha_x|x\rangle|f(x)\rangle|g(x)\rangle|0\rangle_{\text{out}}. Why: UfU_f is linear, so it processes every branch xx simultaneously and writes that branch's garbage g(x)g(x) — the superposition is now entangled with the workspace.

Step 2. Apply mm CNOTs controlled on the answer bits, targeting the output register: ∑xαx∣x⟩∣f(x)⟩∣g(x)⟩∣f(x)⟩out\sum_x\alpha_x|x\rangle|f(x)\rangle|g(x)\rangle|f(x)\rangle_{\text{out}}. Why: this copies a basis label, not an unknown state, so it is unitary and lawful; it quarantines the one quantity we intend to keep before the rewind destroys the rest.

Step 3. Apply Uf−1U_f^{-1} to input-plus-scratch only, leaving the output alone: ∑xαx∣x⟩∣0⟩⊗a∣f(x)⟩out\sum_x\alpha_x|x\rangle|0\rangle^{\otimes a}|f(x)\rangle_{\text{out}}. Why: by Uf−1Uf=IU_f^{-1}U_f=I each branch's scratch returns to ∣0⟩⊗a|0\rangle^{\otimes a} independent of xx, because the input that determined g(x)g(x) is still present to drive the inverse.

Step 4. Recognise that the scratch state ∣0⟩⊗a|0\rangle^{\otimes a} is now branch-independent, so it factors: (∑xαx∣x⟩∣f(x)⟩out)⊗∣0⟩⊗a\big(\sum_x\alpha_x|x\rangle|f(x)\rangle_{\text{out}}\big)\otimes|0\rangle^{\otimes a}. Why: a factor common to every term of a sum can be pulled outside it; the answer register is once again a pure coherent superposition, free to interfere under later Hadamards, diffusion, or a QFT.

Go deeper · Derivation B · 1 minWhy leftover garbage decoheres the answer
Derivation BWhy leftover garbage decoheres the answer

The goal is to make precise the claim that garbage is not a cosmetic nuisance but a genuine measurement performed by the workspace on the branch index, by computing the reduced state of the answer register when the garbage is distinct across branches. We form the density operator of the entangled state, trace out the garbage as an inaccessible environment, and watch the off-diagonal coherences — the very terms interference needs — get multiplied by the garbage overlap and then vanish when that overlap is a Kronecker delta.

Step 1. From ∣Ψ⟩=∑xαx∣x⟩∣f(x)⟩∣g(x)⟩|\Psi\rangle=\sum_x\alpha_x|x\rangle|f(x)\rangle|g(x)\rangle form ρ=∣Ψ⟩⟨Ψ∣=∑x,yαxαy∗ ∣x,f(x)⟩⟨y,f(y)∣⊗∣g(x)⟩⟨g(y)∣\rho=|\Psi\rangle\langle\Psi|=\sum_{x,y}\alpha_x\alpha_y^*\,|x,f(x)\rangle\langle y,f(y)|\otimes|g(x)\rangle\langle g(y)|. Why: writing the outer product over both branch indices x,yx,y isolates the garbage factor ∣g(x)⟩⟨g(y)∣|g(x)\rangle\langle g(y)|, which is the only place the workspace correlations live.

Step 2. Trace over the garbage: ρans=Trg ρ=∑x,yαxαy∗ ⟨g(y)∣g(x)⟩ ∣x,f(x)⟩⟨y,f(y)∣\rho_{\text{ans}}=\mathrm{Tr}_g\,\rho=\sum_{x,y}\alpha_x\alpha_y^*\,\langle g(y)|g(x)\rangle\,|x,f(x)\rangle\langle y,f(y)|. Why: the partial trace inserts the overlap ⟨g(y)∣g(x)⟩\langle g(y)|g(x)\rangle into every term, so each answer-coherence now carries a garbage-overlap weight — coherence survives only as far as the garbage fails to distinguish the branches.

Step 3. For injective garbage ⟨g(y)∣g(x)⟩=δxy\langle g(y)|g(x)\rangle=\delta_{xy}, leaving ρans=∑x∣αx∣2 ∣x,f(x)⟩⟨x,f(x)∣\rho_{\text{ans}}=\sum_x|\alpha_x|^2\,|x,f(x)\rangle\langle x,f(x)|. Why: every off-diagonal x≠yx\neq y term is annihilated, so the answer register is a classical probabilistic mixture with no relative phases — interference is impossible, and this is precisely the regime uncomputation exists to prevent.

Step 4. Compare with the uncomputed case, where the workspace is the branch-independent ∣0⟩⊗a|0\rangle^{\otimes a} so ⟨0a∣0a⟩=1\langle 0^a|0^a\rangle=1 for all x,yx,y and no coherence is lost. Why: replacing distinct g(x)g(x) by a common ∣0⟩⊗a|0\rangle^{\otimes a} turns the decohering δxy\delta_{xy} into a harmless 11 — the mathematical statement of "the camera has been un-taken".

Go deeper · Derivation C · 1 minCost accounting and reversible pebbling
Derivation CCost accounting and reversible pebbling

The goal is to pin down exactly what uncomputation costs — in gates, depth, and persistent qubits — and to show how Bennett's reversible pebble game trades a mild time blow-up for a dramatic space saving on long computations. We count resources for the straightforward compute–copy–uncompute schedule, identify which qubits survive the subroutine, and then sketch the recursive scheme that holds only logarithmically many checkpoints.

Step 1. Run UfU_f (GG gates, depth DD), one parallel layer of mm copy-CNOTs (depth 11), then Uf−1U_f^{-1} (GG gates, depth DD): the totals are gates=2G+m\text{gates}=2G+m and depth=2D+1\text{depth}=2D+1. Why: the forward and inverse passes each cost the full circuit, and the copy is a single depth-1 layer, so the whole clean oracle is barely more than twice the raw evaluator.

Step 2. After the inverse the aa scratch qubits are back in ∣0⟩|0\rangle and can be reused; only the mm output qubits persist beyond the subroutine, so ascratch→0a_{\text{scratch}}\to 0 and akept=ma_{\text{kept}}=m. Why: returning scratch to a known pure state is what makes qubits recyclable — dirty entangled qubits would have to be discarded, so uncomputation is also the engine of qubit economy.

Step 3. For a length-TT computation, Bennett's reversible pebble game uncomputes intermediate checkpoints recursively, holding S(n)=O(Slog⁡T)S(n)=O(S\log T) checkpoints at a time cost T(n)=O(T1+ϵ)T(n)=O(T^{1+\epsilon}) instead of storing all O(T)O(T) intermediate values. Why: naively keeping every intermediate result to enable a clean rewind costs linear space; the pebble game shows you can rewind with only logarithmically many live checkpoints if you accept slightly super-linear time.

Step 4. In practice one tunes the pebbling depth to the hardware: minimise persistent qubits aa while keeping 2D+12D+1 acceptable. Why: on width-limited devices (Shor arithmetic, Grover oracles) qubits are scarcer than gates, so the design knob is exactly this space–time trade the pebble game exposes.

Limiting cases

How uncomputation behaves depends entirely on how the garbage correlates with the branch and how much workspace is recycled.

CaseResultMeaning
Injective garbage (worst case)ρans=∑x∣αx∣2 ∣x,f(x)⟩⟨x,f(x)∣\rho_{\text{ans}}=\sum_x|\alpha_x|^2\,|x,f(x)\rangle\langle x,f(x)|Distinct g(x)g(x) for every xx: tracing out garbage fully decoheres the answer into a classical mixture, all interference lost. This is exactly the regime uncomputation must fix.
Constant garbage (already clean)g(x)=g0 ∀x ⇒ (∑xαx∣x⟩∣f(x)⟩)⊗∣g0⟩g(x)=g_0\ \forall x\ \Rightarrow\ \big(\sum_x\alpha_x|x\rangle|f(x)\rangle\big)\otimes|g_0\rangleIf the workspace ends the same in every branch it already factors out; no uncomputation needed. Bennett's trick forces this situation.
Self-inverse oracleUf∣x⟩∣y⟩=∣x⟩∣y⊕f(x)⟩U_f|x\rangle|y\rangle=|x\rangle|y\oplus f(x)\rangleAn XOR oracle is garbage-free by construction and its own inverse — no separate uncompute step, which is why textbook algorithms assume this form.
Cost overhead(G,D,a)→(2G+m, 2D+1, a+m)(G,D,a)\to(2G+m,\,2D+1,\,a+m)Compute (G,DG,D), copy (mm CNOTs, depth 11), uncompute (G,DG,D): a constant-factor time cost for unbounded coherence gain, with scratch recycled.
Space vs. time (pebbling)ancillas=O(log⁡T), time=O(T1+ϵ)\text{ancillas}=O(\log T),\ \text{time}=O(T^{1+\epsilon})Bennett's reversible-pebble tradeoff: recursively uncomputing checkpoints trades a slight super-linear slowdown for logarithmic persistent scratch instead of an O(T)O(T) history.

Worked examples

1 · The cost of cleaning a modular multiplier (fully worked)

A reversible modular multiplier used inside Shor's algorithm uses G=120G=120 elementary gates at depth D=45D=45, consumes a=8a=8 scratch ancillas, and produces an m=4m=4 bit result. You must hand the next stage a clean answer with the scratch returned to ∣0⟩|0\rangle. Find the gate count, depth, persistent qubit count, and peak width of the Bennett clean oracle, and state the time overhead factor.

Step 1. Gate count. The clean oracle runs UfU_f forward, one layer of mm copy-CNOTs, then Uf−1U_f^{-1}: gates=2G+m=2(120)+4=244\text{gates}=2G+m=2(120)+4=\mathbf{244}. The copy adds only m=4m=4 gates on top of the doubled body.

Step 2. Depth. Forward and inverse each contribute DD, the copy layer contributes 11: depth=2D+1=2(45)+1=91\text{depth}=2D+1=2(45)+1=\mathbf{91}. The overhead factor in time is 91/45≈2.02×91/45\approx\mathbf{2.02}\times — essentially the promised factor of two.

Step 3. Persistent qubits. After Uf−1U_f^{-1} the a=8a=8 scratch ancillas are back in ∣0⟩|0\rangle and are recycled, so only the mm output qubits survive the subroutine: akept=m=4a_{\text{kept}}=m=\mathbf{4}. The peak width during the subroutine is still n+a+mn+a+m (all registers live at once mid-circuit), but the width charged to the caller afterwards is just 4\mathbf{4}.

Step 4. Interpretation. Had you skipped the uncompute you would have paid only G=120G=120 gates and depth 4545, but you would have handed the QFT stage a+m=12a+m=12 dirty qubits entangled with the period register — and the period-finding interference would have collapsed. Clean oracle: 244 gates, depth 91 (≈ 2× time), 4 persistent qubits; the 8 scratch ancillas are recovered.

2 · Garbage kills a two-bit Deutsch–Jozsa oracle

Consider a one-qubit-input balanced function with f(0)=0, f(1)=1f(0)=0,\ f(1)=1, queried in the phase-kickback style on the equal superposition 12(∣0⟩+∣1⟩)\tfrac{1}{\sqrt2}(|0\rangle+|1\rangle). Compare a clean XOR oracle against a "dirty" oracle that leaves distinct garbage g(0)≠g(1)g(0)\neq g(1), and show the algorithm's outcome in each case.

Step 1. Clean oracle. With a ∣−⟩|-\rangle target the kickback gives 12((−1)f(0)∣0⟩+(−1)f(1)∣1⟩)=12(∣0⟩−∣1⟩)=∣−⟩\tfrac{1}{\sqrt2}\big((-1)^{f(0)}|0\rangle+(-1)^{f(1)}|1\rangle\big)=\tfrac{1}{\sqrt2}(|0\rangle-|1\rangle)=|-\rangle. A final Hadamard maps ∣−⟩→∣1⟩|-\rangle\to|1\rangle, so the input qubit reads 1\mathbf{1} with certainty — the deterministic Deutsch signature of a balanced function.

Step 2. Dirty oracle. The same kickback now yields 12((−1)f(0)∣0⟩∣g(0)⟩+(−1)f(1)∣1⟩∣g(1)⟩)\tfrac{1}{\sqrt2}\big((-1)^{f(0)}|0\rangle|g(0)\rangle+(-1)^{f(1)}|1\rangle|g(1)\rangle\big), with the sign entangled to distinct garbage. Tracing out the garbage gives ρin=∑x∣12∣2∣x⟩⟨x∣=12(∣0⟩⟨0∣+∣1⟩⟨1∣)\rho_{\text{in}}=\sum_{x}|\tfrac{1}{\sqrt2}|^2|x\rangle\langle x|=\tfrac12(|0\rangle\langle0|+|1\rangle\langle1|) because ⟨g(1)∣g(0)⟩=0\langle g(1)|g(0)\rangle=0 kills the cross term.

Step 3. Outcome. The dirty input state is the maximally mixed qubit; the final Hadamard maps a maximally mixed state to a maximally mixed state, so measurement gives 00 or 11 with probability 12\tfrac12 each. The clean oracle answers "balanced" deterministically; the dirty oracle returns a coin flip that reveals nothing about ff — the relative phase (−1)f(x)(-1)^{f(x)} was carried off by the garbage.

Physics of the portrait

Uncomputation is one of those rare primitives whose entire modern theory traces to a single person asking a stubborn question: must computation dissipate heat? The answer reshaped both thermodynamics and quantum algorithm design.

Origins · 1 minCharles Bennett and how this was discovered
CB
Charles Bennett
born 1943 · reversible computation and the thermodynamics of information

Charles H. Bennett is the physicist who turned "can computation be reversible?" from a curiosity into a foundation. Building on Rolf Landauer's 1961 insight that only logically irreversible operations — erasing a bit — must dissipate at least kBTln⁡2k_B T\ln 2 of heat, Bennett proved in 1973 that any computation can be rearranged into a fully reversible one by keeping a history of intermediate steps and then running the machine backwards after copying out the answer. That "copy the answer, reverse the history" manoeuvre is precisely the compute–copy–uncompute pattern this article is about, transplanted from classical Turing machines to quantum circuits, where reversibility is not optional but forced by unitarity. In 1989 he sharpened the idea into the reversible pebble game, showing a length-TT computation can be run reversibly in O(log⁡T)O(\log T) extra space at T1+ϵT^{1+\epsilon} time — the space–time tradeoff every ancilla-starved quantum architecture now negotiates. Bennett went on to co-invent quantum key distribution (BB84, with Gilles Brassard, 1984) and quantum teleportation (1993), and to co-author the BBBV analysis (1997) bounding what oracle-based quantum algorithms can achieve. The through-line of his career is a single conviction: information is physical, and the cost of forgetting it is the deepest currency linking computation, thermodynamics, and the quantum world.

History
1961
— Landauer shows erasing one bit must dissipate at least k_B T ln 2 of heat
1973
— Bennett proves logical reversibility of computation via the history-and-uncompute trick
1982
— Fredkin and Toffoli give universal reversible logic gates
1989
— Bennett's reversible pebble game: O(log T) space at T^(1+ε) time
1997
— Bennett, Bernstein, Brassard, Vazirani bound oracle-based quantum speedups

Going further

Texts. Nielsen & Chuang, Quantum Computation and Quantum Information, §3.2.5 (reversible computation) and §1.4.2 · C. H. Bennett, "Logical Reversibility of Computation", IBM J. Res. Dev. 17, 525 (1973) · C. H. Bennett, "Time/Space Trade-offs for Reversible Computation", SIAM J. Comput. 18, 766 (1989) · Preskill, Lecture Notes on Quantum Computation, Ch. 6 (algorithms and oracles) · Kitaev, Shen & Vyalyi, Classical and Quantum Computation, §7 (reversible circuits and garbage) · Mermin, Quantum Computer Science, Ch. 2 · Watrous, The Theory of Quantum Information (channels and partial trace). Three results anchor the article's claims. First, inserting ⟨g(y)∣g(x)⟩=δxy\langle g(y)|g(x)\rangle=\delta_{xy} into the partial trace annihilates all off-diagonal coherences, leaving ρans=∑x∣αx∣2∣x,f(x)⟩⟨x,f(x)∣\rho_{\text{ans}}=\sum_x|\alpha_x|^2|x,f(x)\rangle\langle x,f(x)|. Second, Uf−1Uf=IU_f^{-1}U_f=I restores the scratch to ∣0⟩⊗a|0\rangle^{\otimes a}, and the copy step is a basis fan-out CNOT rather than cloning. Third, the cost figures (2G+m, 2D+1, a+m)(2G+m,\,2D+1,\,a+m) are exact gate counts — evaluated at G=120, D=45, a=8, m=4G=120,\,D=45,\,a=8,\,m=4 they give 244244 gates, depth 9191, peak width 1212, and 44 persistent qubits. The O(log⁡T)O(\log T)-space, O(T1+ϵ)O(T^{1+\epsilon})-time pebbling result is Bennett (1989). Every factor is an exact gate-count integer or a Kronecker-delta consequence.

Builds on. Quantum Circuit Model · CNOT Gate · Controlled-U Gates · Circuit Identities and Equivalences. Leads to. Controlled-U Gates · SWAP Gate · Circuit Identities and Equivalences.

Ask the tutor: Ask me to walk through uncomputing a specific reversible subroutine — a Toffoli-built AND, a ripple-carry adder, or a Grover marking oracle — and watch the scratch return to zero step by step.

Why can't I just reset the garbage qubits to zero and move on?

Because an unconditional reset is not a unitary gate — it is a measure-and-discard, physically equivalent to letting the environment read the qubit and throwing away the record. That destroys the correlation between garbage and branch by decohering it, which is exactly the failure you were trying to avoid: the answer register ends up in the same classical mixture that tracing out the garbage produces. Running Uf−1U_f^{-1} instead is reversible: it threads each garbage qubit back to ∣0⟩|0\rangle using the input data still present, so no coherence is lost. The rule of thumb is that you may only send a qubit to ∣0⟩|0\rangle for free if you can derive its current value from information you still hold — and the inverse circuit is precisely that derivation.

Doesn't the copy step violate the no-cloning theorem?

No. No-cloning forbids a unitary that maps an unknown arbitrary state ∣ψ⟩∣0⟩→∣ψ⟩∣ψ⟩|\psi\rangle|0\rangle\to|\psi\rangle|\psi\rangle for all ∣ψ⟩|\psi\rangle. The copy step does something weaker and entirely legal: it fans out a computational-basis label, ∣f(x)⟩∣0⟩→∣f(x)⟩∣f(x)⟩|f(x)\rangle|0\rangle\to|f(x)\rangle|f(x)\rangle, using CNOTs. Applied to a superposition it does not produce two independent copies — it produces an entangled, GHZ-like correlation ∑xαx∣f(x)⟩∣f(x)⟩\sum_x\alpha_x|f(x)\rangle|f(x)\rangle, which is exactly what we want, since we are trying to record which answer goes with which branch, not to duplicate an unknown qubit. No-cloning is about the impossibility of a universal copier; fixed-basis fan-out is not universal, so there is no conflict.

How can I tell from the final state that the uncomputation worked?

The workspace register must factor out as ⊗ ∣0⟩⊗a\otimes\,|0\rangle^{\otimes a}, the same state in every branch, independent of xx. Equivalently, the reduced state of the answer register is pure (or as pure as it was before the oracle), and the mutual information between the answer and the workspace is zero. A quick operational test: the garbage carries no which-path information, so an interference experiment on the answer register — a Hadamard test, or the algorithm's own final interference step — recovers full-visibility fringes. If instead the scratch still depends on xx, the factorisation fails, the answer's reduced state is mixed, and the fringes are washed out in proportion to how distinguishable the garbage is.

My oracle's answer register measures to the right distribution but the algorithm still fails — why?

This is the classic garbage bug. Marginal measurement statistics on the answer register are completely insensitive to entanglement with a garbage register: the reduced state ρans\rho_{\text{ans}} and the fully entangled global state agree on every local observable. But the algorithm around your oracle — Deutsch–Jozsa's final Hadamards, Grover's diffusion, phase estimation's inverse QFT — extracts its result from interference among amplitudes, which the garbage has decohered. So each isolated oracle call "looks" correct while the composed algorithm produces noise. The fix is to insert the uncompute step (Uf−1U_f^{-1} after copying the answer out) so the answer register regains its off-diagonal coherences before it re-enters the interference.

What is the actual overhead of uncomputation, and can I avoid the factor of two?

The straightforward schedule costs 2G+m2G+m gates and 2D+12D+1 depth — close to twice the raw evaluator — while returning all aa scratch qubits so only the mm output qubits persist. You can sometimes dodge the doubling: an XOR-style oracle ∣x⟩∣y⟩→∣x⟩∣y⊕f(x)⟩|x\rangle|y\rangle\to|x\rangle|y\oplus f(x)\rangle is garbage-free and self-inverse by construction, needing no separate uncompute; and measurement-based uncomputation can clear certain ancillas with a measurement and classically-controlled correction instead of a full inverse. What you cannot do is skip the concept: if a circuit generates branch-dependent garbage and you want interference, that garbage must be removed by some reversible or measurement-based means. The space–time knob (Bennett's pebble game) lets you push the cost between time and qubits, but not to zero.

Is uncomputation the same idea as Landauer's principle?

They are two sides of one coin. Landauer's principle says logically irreversible operations — erasing a bit unconditionally — must dissipate at least kBTln⁡2k_B T\ln 2 of heat, because information cannot simply vanish. Uncomputation is what you do instead of erasing: rather than pay Landauer's cost (impossible anyway inside a unitary quantum circuit), you reversibly return the scratch to ∣0⟩|0\rangle by undoing the computation that wrote it, dissipating nothing and — crucially in the quantum case — preserving coherence. Bennett's 1973 reversible-computation construction is precisely the demonstration that Landauer's floor can be dodged for any computation by keeping information around long enough to un-write it. In a quantum circuit the point is sharper still: irreversible erasure is not merely costly, it is not a valid operation, so uncomputation is the only game in town.

Before this

Where this leads