9.9
The idea behind Shor’s algorithm
Factoring → period finding → reading the period with the QFT: every leg of the triple jump hand-computed on N = 15; the gap between polynomial and sub-exponential, hanging over RSA.
Recommended first
After this section you should be able to
- Recount the full chain: factoring N ⇒ finding the period r of a^x mod N ⇒ extracting factors via gcd(a^{r/2} ± 1, N)
- Hand-compute the entire pipeline for N = 15, a = 7, verifying every link
- Explain why the QFT turns a "period" into a "measurable peak": periodic superposition → interference concentration
- Compare quantum O((log N)³) against classical sub-exponential complexity, and lay out the real threat to RSA and its likely timeline
Grover’s ending pointed the way: for exponential speedup, find a problem with structure. In 1994 Peter Shor found that problem — factoring large integers. Its structure is a hidden periodicity, and “finding periods with interference” has been quantum mechanics’ signature trade since the double-slit experiment. This section does not dive into number-theoretic proofs, but it works the full logical chain and the quantum part all the way through.
The problem at the door: multiplication is easy, division is deadly
— mental arithmetic. The reverse, “15 = ? × ?”, is not hard either. But make the number 617 digits long (2048 bits): multiplying two thousand-digit primes takes a computer milliseconds; recovering the two factors from the product, using the fastest known classical algorithm (the number field sieve), takes time on the order of
— sub-exponential: far worse than polynomial. For a 2048-bit , all the computing power on Earth combined would need millennia. The security of RSA public-key cryptography is staked on exactly this one-way street: the public key displays in plain sight, and whoever can factor it can read every ciphertext.
First leg: factoring ⇒ period finding (classical number theory, results only)
Shor’s first move is to rewrite the problem. Pick any coprime to and look at the modular exponential
It is necessarily periodic: , and the smallest positive period is called the order of . Number theory provides a bridge (stated without proof):
If is even and , then and yield nontrivial factors of .
The intuition in one line: means — divides the product yet (under the stated conditions) divides neither factor, so ‘s prime factors have been split between the two sides, and (the Euclidean algorithm — blazingly fast) collects one from each. For a random the conditions hold with probability at least ; if they fail, pick another and try again.
Hand-compute with :
The period is — even, and . Therefore
— success. The only hard step left in the entire algorithm is finding the period . Classically, period finding is no cheaper than factoring outright (you would have to grind through trillions of steps before seeing a single cycle); this is precisely the step quantum mechanics takes over.
Second leg: loading the period into a superposition
Open with the DJ recipe: hit the first register ( qubits, ) with a row of ‘s, compute the modular exponential for every in parallel, and write it into the second register:
Now measure the second register (you don’t actually have to — it just makes the story easier to tell), obtaining some value . The first register thereupon collapses to the equal-weight superposition of all the that produce that value — and these form exactly an arithmetic progression :
The period is now etched into the state, but a direct measurement would just spit out one random — the random starting point scrambles the period information (each rerun gives a different ). The old problem: the information went in but won’t come out. The old answer: interference. This time the interference machine is the quantum Fourier transform.
Third leg: the QFT turns the period into peaks
The quantum Fourier transform (QFT) is the deluxe version of DJ’s row of ‘s — upgrading “bitwise phases” to “continuous phases”:
(The phases of are only ; the QFT’s phases take ticks around the unit circle. It can be built from gates — ‘s plus controlled phase rotations; we skip the circuit here.)
Measuring after the QFT: why the peaks land on integer multiples of Q/radvanced~9 min
Step 1: apply the QFT to the periodic state. Substitute into the definition:
Step 2: factor out the random start. Pull out the factor — it contributes only a phase and vanishes in the modulus squared: the pesky exits the stage right here. The probability of measuring is
Step 3: see when the geometric series adds up. The bracket is a geometric series with ratio .
- If is exactly an integer, i.e. : every term equals 1, the sum is , and — a sharp peak;
- otherwise the phases march around the unit circle, closing on themselves and nearly cancelling: .
sharp peaks stand evenly spaced at , carrying total probability about 1. (When does not divide the peaks acquire a slight width and sit at the nearest integers, but the conclusion stands — this is exactly why we demanded : peak width much smaller than peak spacing.)
Step 4: recover from the readout. Measuring some means
The left side is the known readout; the right side is the fraction we want. A continued-fraction expansion finds the best rational approximation with denominator at most , giving a candidate for (if and share a factor you get a divisor of ; a rerun or two and a least common multiple fixes that). Feed it back into the first leg’s , and the factorization is done.
Mini worked check (, with ): the peaks should sit at . Say we measure : , the continued fraction gives , so . ✓
The picture
Why this is interference’s victory. Compare the trilogy’s three cases of “it went in but won’t come out”: the parallel function values couldn’t be read out (DJ used interference to extract the parity), the target amplitude was too small to be read out (Grover used repeated interference to snowball it), and the period was masked by a random starting point (Shor uses QFT interference to filter out the start and amplify the period). What the QFT does is exactly diffraction through a grating: slits arranged with period , bright fringes appearing at integer multiples of the reciprocal point in the far field — Shor’s algorithm is a diffraction experiment performed in number theory.
The mathematics
The complexity ledger ( is the bit length):
: quantum, on the order of gate operations (at the logical level); classical, about operations. Polynomial versus sub-exponential — this is not a speedup; it is a different species.
Key formulas
The reduction chain
Factoring → period finding → gcd; only the middle step needs a quantum computer
QFT
The continuous-phase version of H^{⊗n}; realizable with O(t²) gates
Peak positions
Periodic superposition through QFT interference; the random start x₀ survives only as a phase, never entering the probability
Complexity comparison
Polynomial vs sub-exponential: a threat to RSA in principle
Self-check4 questions
- 1.
N = 21, with a = 2. What is the period r of the function 2^x mod 21? (Square repeatedly: 2, 4, 8, 16, …)
0% relative tolerance - 2.
In Shor’s algorithm, which step is the quantum computer actually responsible for?
- 3.
If you measured the first register directly before the QFT (while it holds the periodic superposition Σ∣x₀ + jr⟩), what would you get?
- 4.
Which statements about Shor’s algorithm’s impact on cryptography are correct? (Select all that apply.)
Select all that apply
What comes next
Shor needs trillions of gate operations to run back-to-back without a slip, and real qubits are delicate creatures: a one-percent gate error counts as excellent, and even left alone they quietly drift. Classical computers correct errors with redundant backups — but quantum states cannot be cloned (Section 9.5), and a measurement collapses them (Section 9.1) — so how do you back up, and how do you even notice an error? The next section is this chapter’s finale: quantum error correction. Its answer is unexpectedly beautiful, and it is a grand reunion of everything this chapter has built — entanglement, measurement, stable correlations.
Section 73 of 106 · use ← → to turn the page