Pricing…Open Lab
Chapter 09 of 13 · ~30 min

Uncomputation

Uncomputation runs the reverse of the gates that made a temporary value, in reverse order. This puts helper qubits back to |0⟩. Then they are no longer entangled with the data you care about. Resetting them is not the same thing. Reset can't be undone, and it destroys the phase links that later interference needs.

What problem does uncomputation solve?

Real circuits use scratch space. An ancilla is a helper qubit. It starts in |0⟩, holds a temporary value partway through, and should end in |0⟩ so it can be used again. The trap is what happens in between.

Say a controlled gate writes a temporary value onto an ancilla. The ancilla usually becomes entangled with the data qubits. That means the qubits are linked so tightly that neither can be described on its own any more. An ancilla left like that is called garbage. It is a leftover record of which path, or branch, of the computation made it.

Why does garbage matter? Quantum programs get their power from interference. That is amplitudes from different branches adding together or cancelling out.

Branches can only interfere if they match in every qubit. Amplitudes add only when they flow into the same final answer. Two branches that differ on even one helper qubit lead to different answers, so their amplitudes never meet. A garbage qubit that remembers "branch A" versus "branch B" makes the branches different. Then the interference quietly stops working.

Think of two people walking into a room from two doors. If one leaves muddy footprints, you can always tell which door they used. Clean the footprints and the two paths look the same again. The example has a limit: here, "cleaning" must be done by running gates backwards, not by wiping.

You can't just overwrite the ancilla. The previous lesson, Reversible Computation, showed that no gate erases information. The fix is uncomputation. Run the inverse of the gates that made the temporary value, in reverse order. Then the ancilla goes back to |0⟩ smoothly, without breaking the rest of the state.

What the rest of this chapter covers
  1. Worked example: what do the real amplitudes do?
  2. Run it: compute, use, uncomputeINTERACTIVE
  3. Compare: what if I skip the uncompute step?INTERACTIVE
  4. Try this: what if I remove the workload?INTERACTIVE
  5. Why isn't reset good enough?
  6. Run it: compute, copy out, uncomputeINTERACTIVE
  7. What should a developer remember?
Keep learning with Pro

You’ve read the opening of chapter 9. Pro unlocks the other 7 sections — plus every chapter of every course, with circuits you can run right on the page. That’s $11.99 a month, about the price of a coffee, or $99.99 a year (save 30%). The first chapter of every course, and the whole math course, stay free.

Start learning with ProSee plansRead chapter 1 free
Uncomputation · QPU137