Using the QFT to Find Periods
In Shor's algorithm the quantum computer does not measure a period directly. Instead it produces a counting register whose amplitudes concentrate at integer multiples of , where is the register size and is the unknown period. The inverse QFT maps those frequency peaks back into a pattern from which can be read.
From frequency peaks to period
After the oracle and the forward QFT, the counting register holds a superposition over the frequency values . For a period-2 function in an space the two peaks are at and :
Applying the inverse QFT to reverses the transform and recovers the original time-domain periodicity. The calculation proceeds as follows. The 3-qubit IQFT maps each basis state as
so
The factor equals 2 for even and 0 for odd , so all probability collapses onto the even outcomes:
Measuring yields each of with probability . Every result is even — the GCD of any non-zero result and is at least 2, immediately revealing the period.
The period-extraction recipe
In a complete Shor's-algorithm run the classical post-processing step applies continued fractions to a single measurement outcome : the best rational approximation to with denominator at most gives for some coprime pair , from which is extracted. For the case above, the QFT output state is , so the only non-trivial measurement outcome is : , giving directly in a single shot. For general the QFT peaks are at for ; continued fractions applied to each non-trivial outcome yields a candidate denominator, and taking the LCM of all candidates across several shots recovers the true period with high probability.
The 3-qubit inverse QFT circuit
Recall that the 3-qubit forward QFT (qubit 0 most significant) ends with a bit-reversal SWAP. Its inverse therefore begins with that same SWAP, then applies the reversed-and-conjugated rotation sequence:
| Step | Gate | Purpose | |------|------|---------| | 1 | | undo the bit-reversal of the forward QFT | | 2 | | undo coarsest Hadamard | | 3 | | negate and reverse phase rotation | | 4 | | undo middle Hadamard | | 5 | | negate and reverse | | 6 | | negate and reverse | | 7 | | undo finest Hadamard |
Try it
The starter code prepares the frequency-domain state with a single Hadamard on qubit 0. Apply the 3-qubit inverse QFT and measure. The grader checks the output distribution, which should show equal probability on each even outcome .
After running, open the Probabilities tab. You should see four equal bars at positions 0, 2, 4, and 6 — every outcome is even, and the uniform spacing of is directly readable from the measurement results. This is the moment where the inverse QFT converts an abstract frequency superposition into actionable period information.
Sign in on the full site to ask questions and join the discussion.