B10 · Methods that workWorks, and here’s how it scales
Shor’s algorithm, simulated classically
step by step for N = 15 and 21: the table of powers, the collapse, the Fourier peaks, the , the . A simulation, and why it stops at toy size.
The idea
Pick a, and look at a, a², a³ … mod N. They cycle with some period r. If r is even, then (a^{r/2} − 1)(a^{r/2} + 1) is a multiple of N, and gcds with N give the factors. The quantum part finds r: put every x in superposition, compute aˣ mod N, measure it, and a of what is left has peaks near multiples of Q/r.
Watch it
The test
Exact success probability for each a at N = 15 and 21, from the simulated , against the textbook value φ(r)/r. Then simulation time as the number grows.
Fig. B10.2Time to simulate the quantum Fourier step (an FFT of 2²ⁿ amplitudes) against the bits n of the number being factored
Measuring…