Why do Grover's and Shor's algorithms actually work?

One mechanism, applied four times, is the actual engine behind Deutsch-Jozsa, Grover's search, and Shor's factoring. It has a name, phase kickback, and this site never said it out loud until now.

You'll be able to say why one mechanism, phase kickback, runs Deutsch-Jozsa, Simon and Shor.

The answer in four lines

Apply a controlled gate where the target qubit is already sitting in one of that gate's own eigenstates, and something backwards happens: the target doesn't change at all (it can't, an eigenstate just gets multiplied by a number), but that number's phase has to go somewhere, and it lands on the control qubit instead, as a twist between its |0⟩ and |1⟩. That misdirected phase is phase kickback, and it is the entire mechanism behind quantum algorithms that look, on the surface, unrelated: Grover's oracle marking an answer, and quantum phase estimation, which is quite literally named after this effect and is the engine inside Shor's algorithm.

A quantum circuit diagram: Hadamard gates on every wire, then a boxed oracle and a diffusion operator that repeat, ending in measurements.
Grover's algorithm as a circuit: Hadamard gates spread the amplitude evenly, then the oracle Uω and a diffusion step repeat about (π/4)√N times, then a measurement. Diagram by Fawly, CC BY-SA 4.0, source.
Plain

The trick: aim at something that can't move, and watch the recoil

Picture a locked door with a combination dial, and a rule: turning the dial to the right number does nothing visible to the door: it was already unlocked, so "unlocking" it again just leaves it exactly as unlocked as before. But the person turning the dial isn't left unaffected. Their hand picks up a small, specific twist depending on whether the combination they tried was right or wrong: a twist you can't see by looking at the door, only by looking at the hand.

Now do this in superposition: instead of trying combinations one at a time, hold every combination in your hand at once, and touch the dial once. The door, silent throughout, never changing, has left a different twist onto each of your simultaneously-held combinations. Nothing about the door tells you which twist went where. But if you now let all those twisted possibilities interfere with each other, the twisted-right combination reinforcing itself and the twisted-wrong ones cancelling out, the answer falls out.

That is phase kickback, stated without a single equation. The "door" is a target qubit prepared so that touching it can never change it. The "twist" is a phase. And "letting them interfere" is exactly what a Hadamard gate, or the more elaborate Fourier transform used in Shor's algorithm, is for. The mechanism, with the equation: Working: keep going ↓

Check yourself · 1 of 3

In the locked-door picture, the door never changes. Where does the answer show up?

The door is a target that touching can never change, so the information has to go somewhere else. It lands on the control as a phase, a twist you see only when the possibilities interfere afterwards.

The tempting wrong answers.

  • “As a visible change in the door whenever the combination is right.” Picking this expects the target to change, when an eigenstate cannot.
  • “In how quickly the door swings open.” Picking this treats the effect as a speed or a signal in the target.
  • “Nowhere: the door has to be read afterwards to learn anything.” Picking this believes only the target can be inspected.
Working

The mechanism: eigenstates don't move, so the phase has nowhere else to go

An eigenstate of a gate U is a state that U leaves pointing the same direction: U only ever multiplies it by a number, U|u⟩ = λ|u⟩, called the eigenvalue. For any gate used in quantum computing, λ is a pure phase, λ = eiφ, since gates preserve length.

The cleanest possible case: the gate Z flips the sign of |1⟩ and leaves |0⟩ alone, so |1⟩ is an eigenstate of Z with eigenvalue −1. Take the controlled version, CZ, wired so a control qubit decides whether Z is applied to a target held fixed at |1⟩, and put the control in an equal superposition |+⟩ = (|0⟩+|1⟩)/√2:

CZ ( |+⟩ ⊗ |1⟩ ) = (|0⟩|1⟩ − |1⟩|1⟩) / √2 = |−⟩ ⊗ |1⟩

Read that literally: the target started at |1⟩ and ends at |1⟩, untouched every single time, because |1⟩ is exactly what Z can't change. But the control started at |+⟩ and ended at |−⟩ = (|0⟩−|1⟩)/√2, a real, measurable flip, purely from being wired to a gate that, by every other measure, "did nothing."

Try it below with a general phase, not just Z's −1.

Watch the phase kick back

The target (left) is fixed at |1⟩ throughout, an eigenstate of every phase gate below, so it is mathematically incapable of moving. Set how much phase each application carries, then apply it a few times and watch the control (right) accumulate it instead.

Two qubits, one that can't move

Target stays exactly at |1⟩, and cannot move, by construction
Control accumulates the phase the target should have kept
π/2

Total kicked back onto the control: 0 · applications: 0

Scope: this shows the cleanest case, a controlled-phase gate acting on a target already fixed at a computational-basis eigenstate. The general statement (any unitary U, any of its eigenstates) is exactly what powers Deutsch's algorithm, proven in full, numerical verification included, at The Machinery, topic f08. It exists to make the mechanism visible before the proof.

Check yourself · 2 of 3 · a new case

A controlled-Z acts on a control in |+⟩ and a target in |0⟩, which is an eigenstate of Z with eigenvalue +1. What happens to the control?

With the target at |0⟩, Z multiplies it by +1 on either branch of the control, so the two branches stay equal and the control stays at |+⟩. The kick carried by the eigenvalue −1 is what turned |+⟩ into |−⟩ in the example above.

The tempting wrong answers.

  • “It flips to |−⟩, as it does when the target is |1⟩.” Picking this forgets that the kick is the eigenvalue itself, and only |1⟩ has the eigenvalue −1.
  • “The target flips to |1⟩ to carry the phase.” Picking this lets the target move, though an eigenstate cannot change.
  • “Control and target become entangled with each other, as any controlled gate does.” Picking this assumes any controlled gate entangles; on an eigenstate it cannot.
Formal

Where this mechanism runs, and where the proofs already live

This page does not re-derive what The Machinery has already proven and independently referee-verified. It exists to name the mechanism plainly and point at exactly where each proof lives.

Deutsch's algorithm and Deutsch-Jozsa are the smallest complete instance: an oracle Uf|x⟩|y⟩ = |x⟩|y⊕f(x)⟩, with the answer register prepared in |−⟩, kicks back (−1)f(x) onto the query register instead of ever writing to the answer register, proven on topic f08 and f09 (Deutsch, Proc. R. Soc. Lond. A 400, 97 (1985); Deutsch & Jozsa, Proc. R. Soc. Lond. A 439, 553 (1992); the exact one-query version: Cleve, Ekert, Macchiavello & Mosca, Proc. R. Soc. Lond. A 454, 339 (1998)), and numerically checked two different ways: exhaustively at f08's n=1 (all four possible one-bit functions), and by sampling at f09's n=4 (both constant functions, plus 20 of the 12,870 possible balanced ones); worth knowing which is which before quoting either as a full proof by enumeration.

Grover's algorithm uses the identical trick in its phase-oracle form: instead of writing "is this the answer?" to a separate register, the oracle multiplies the marked state by −1 directly, exactly the kickback pattern above with the marked state playing the role of the fixed eigenstate. Grover, arXiv quant-ph/9605043 (Proc. 28th STOC, 212 (1996)), proved the O(√N) query bound this buys; play the mechanism yourself at Grover's Escape, where over-rotating past the answer is a failure mode this site's games are built to show rather than hide.

Quantum phase estimation generalises the widget above from a fixed ±1 to an arbitrary eigenvalue e2πiθ of any unitary U, using repeated controlled applications of increasing powers of U to read θ out bit by bit, proven (with its "sharply peaked, not exact" limit stated plainly) on topic f12. Shor's algorithm is one specific choice of U, modular multiplication, that turns phase estimation's output into the period behind factoring, worked through with a 2,000-trial numerical verification on topic f13. It is the mechanism the Bitcoin page's qubit counts run on, though not the counts themselves: those come from separate resource-estimation papers cited there, since bitcoin.html is upfront that it asserts those numbers rather than deriving them.

References

• Deutsch's algorithm: Deutsch, Proc. R. Soc. Lond. A 400, 97 (1985); exact one-query version: Cleve, Ekert, Macchiavello & Mosca, Proc. R. Soc. Lond. A 454, 339 (1998)
• Deutsch-Jozsa: Deutsch & Jozsa, Proc. R. Soc. Lond. A 439, 553 (1992)
• Grover's algorithm: Grover, arXiv quant-ph/9605043 (Proc. 28th STOC, 212 (1996))
• Phase estimation and period-finding: proved in full on The Machinery, f12 and f13, citations there

Check yourself · 3 of 3 · from What is a qubit?

Z is applied to three separate qubits, at |0⟩, at |1⟩ and at |+⟩. For which could a later H and a measurement show that Z was applied?

An arrow at a pole does not move under Z, so only an overall sign changes and no measurement can see it. On the equator Z swings the arrow to the opposite side, and a following H turns that into a different result.

The tempting wrong answers.

  • “All three: Z was applied to each, so each changes.” Picking this counts the gate as an event rather than asking whether any measurement can tell.
  • “The |1⟩ one only: Z flips its sign, and a sign is a visible change.” Picking this takes the overall sign on |1⟩ for something measurable; a global phase never is.
  • “None: Z never changes what a measurement reads.” Picking this over-generalises "Z cannot change a 0" to every state, missing H, Z, H.

Go deeper

The full proofs

Every claim on this page, derived from scratch and numerically verified: Deutsch's, Deutsch-Jozsa, phase estimation, and Shor's period-finding.

The Machinery →

🎯 Play the oracle

Grover's algorithm's phase kickback, as a game: tilt the odds, look once, and see why looking twice loses it.

Grover's Escape →

₿ Where this ends up

The qubit counts this mechanism produces when pointed at Bitcoin's elliptic curve, not just at toy examples.

Can quantum break Bitcoin? →
Next in this trackThe Machinery: Deutsch's algorithmProve itCircuit Golf: reach the target in the fewest gatesJudge a claimCan quantum computers break Bitcoin?