intermediate · Programming · Shor's Algorithm & Period Finding
Checkpoint: Period Finding
This checkpoint consolidates the entire Shor module. You will simulate the decisive quantum step
of period finding: starting from the periodic superposition that emerges after measuring the
output register, you apply the inverse Quantum Fourier Transform and observe that the
measurement probabilities concentrate at integer multiples of Q/r, directly revealing the
period r.
The setup
In a full execution of the period-finding subroutine (§4 of the prior lesson) the circuit
produces, after measuring the ancilla register, an equally-spaced superposition in the input
register. For a function with period r=2 on an n=3-qubit (Q=23=8) register the
surviving states are those x with ax≡v(modN), spaced by r=2:
41(∣0⟩+∣2⟩+∣4⟩+∣6⟩).
In binary (qubit 0 most significant): states ∣000⟩,∣010⟩,∣100⟩,∣110⟩.
Qubit 2 is always 0; qubits 0 and 1 range over all combinations. This is exactly the state
produced by H⊗H⊗I applied to ∣000⟩.
Why the inverse QFT reveals the period
The inverse QFT maps the equally-spaced superposition to a new superposition concentrated at
integer multiples of Q/r. For a uniform superposition over M=Q/r equally-spaced inputs
{0,r,2r,…,(M−1)r}:
QFT†(M1k=0∑M−1∣kr⟩)=r1j=0∑r−1rj⋅Q⟩.
For r=2 and Q=8 the two peaks are at j⋅8/2=0 and 4. Each has probability
1/r=1/2, so measuring the input register returns 0 or 4 with equal probability.
Dividing by Q=8 gives the fraction j/r∈{0,1/2}; continued-fraction expansion
of 1/2 immediately yields the denominator r=2.
The 3-qubit inverse QFT circuit
The forward 3-qubit QFT (as built in the module 2 checkpoint) is:
Reading the circuit in application order (first to last):
SWAP(0,2)
H(2)
CP(−π/2,2,1)
H(1)
CP(−π/4,2,0)
CP(−π/2,1,0)
H(0)
Try it
The starter code already prepares the periodic superposition. Add the seven inverse-QFT gates.
The grader checks the output distribution — it must place probability 1/2 on state
∣000⟩ (index 0) and 1/2 on state ∣100⟩ (index 4), exactly as the period-finding
theory predicts.
Run your code to see the quantum state.
Sign in on the full site to ask questions and join the discussion.