Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 37

QFT's Role in Period Finding

Recommended resources

Welcome back! In our last lesson, we established the crucial connection in Shor's algorithm: the classically hard problem of factoring a number N can be transformed into finding the period r of the function . We saw that while the setup is classical, finding this period for large numbers is where a quantum computer's power is needed.

This lesson dives into that quantum core. We will explore the role of the Quantum Fourier Transform (QFT), the engine that powers the period-finding subroutine. You'll learn how this remarkable tool takes a carefully prepared quantum state and extracts the hidden period, making the entire factoring process possible. Given your background in electrical engineering, you'll find the core concept of the Fourier transform—analyzing frequency components—to be a familiar and powerful starting point.


1. The State of Affairs: A Periodic Superposition

Let's quickly recall the state of our quantum computer just before the QFT steps in. The full period-finding routine works as follows:

  1. Prepare Superposition: We start with two registers of qubits. The first, or "input" register, is put into an equal superposition of all possible numbers it can hold, from to , where .
  2. Apply the Function: We apply a complex unitary gate, , that calculates . This entangles the input register with a second "output" register, creating a state that is a superposition of all |x, f(x)> pairs.
  3. Measure the Output: We measure the second (output) register. This measurement yields some random value, let's call it .

Because of how measurement works, the first register instantly collapses. It is no longer a superposition of all possible inputs. Instead, it becomes a superposition of only the inputs that could have produced the output . Since is periodic with period , this means the first register is now in a state like:

where is the first input that gives the result , and is the number of terms in the sum.

The information we need, the period r, is now encoded in the physical state of the qubits. But we have a problem: if we simply measure this register, we'll get one of the values (, , etc.) at random. This doesn't directly tell us what r is. We need a way to "see" the periodic structure of the state itself.

The following video explains this setup and highlights why we are stuck at this point without a new tool.

Quantum Computing: How Period Finding Algorithm Works? (Part 1/2)

The video "How Period Finding Algorithm Works?" from the Advanced Maths channel sets up the problem perfectly.

Watch from the measurement step. Focus on how measuring the second register creates a periodic superposition in the first, and why simply re-measuring this register doesn't help us find the period efficiently. The key takeaway is the realization that the resulting states have a "linear shift" of r, which hints at the solution.

As the video concludes, we need a tool that can analyze a state with this periodic, "linearly shifted" structure and extract the period. That tool is the Quantum Fourier Transform.



2. The Quantum Fourier Transform: A "Rhythm Detector"

In your electrical engineering studies, you know the classical Fourier Transform is used to decompose a signal from the time domain into its constituent frequencies. It tells you "what frequencies are in this signal, and how strong are they?"

The Quantum Fourier Transform does something conceptually analogous for a quantum state. It transforms a state from the computational basis (states like |0>, |1>, etc.) into the Fourier basis, which is a basis of states defined by their phase.

For a deeper intuition, watch this explanation from the Qiskit team.

7. Shor's Algorithm I: Understanding Quantum Fourier Transform, Quantum Phase Estimation - Part 1

This video from Qiskit provides a clear, conceptual definition of the QFT.

Watch the section that defines the QFT as a change of basis. It shows how for a single qubit, this is just the Hadamard gate transforming between the Z-axis (|0>, |1>) and the X-axis (|+>, |->). Then, watch the next segment showing a multi-qubit QFT. Notice how the computational basis states (all qubits pointing up or down) are transformed into states where all qubits are on the equator, distinguished only by their relative phases.

The QFT is essentially a phase-encoding machine. It takes a number represented in the computational basis and maps it onto a superposition of states where the original number is encoded in the phases of the qubits.

Quantum Fourier Transform (QFT) Visualization with Spinners
This animation shows the effect of the QFT. An input state is transformed into a set of "spinners" on the Bloch sphere's equator. The QFT converts information from the computational basis (up/down) into the phases of these spinners.

Now, how does this help us find the period r? Let's use an analogy.

Shor's Algorithm: The Period-Finding Machine

This article provides a fantastic analogy for what the QFT does in Shor's algorithm.

Read the short section titled "Where quantum kicks in – the period-finding machine," focusing on the analogy of the drums in a dark room.

As the article beautifully explains, the QFT acts as a "rhythm detector." Our periodic state is like a complex jumble of sounds. The QFT performs an analysis on this state. Through quantum interference:

  • The amplitudes corresponding to "frequencies" (or periods) that don't match our r will cancel each other out.
  • The amplitudes corresponding to the correct "frequency" (which is related to 1/r) will constructively interfere and be amplified.


3. How QFT Reveals the Period

Let's put this all together. The quantum period-finding routine looks like this:

  1. Preparation: Create the periodic superposition state in the first register.
  2. Transformation: Apply the Inverse Quantum Fourier Transform (IQFT) to this register. The IQFT is simply the QFT run in reverse. It transforms from the Fourier (phase) basis back to the computational basis.
  3. Measurement: Measure the first register.

The magic is in what happens after the IQFT. Because our state was periodic with period r, the IQFT transforms it into a new state where the measurement outcome is highly likely to be an integer multiple of , where is the size of our register.

So, when we measure, we get a value m such that:

for some integer k.

Let's formalize this with the help of a lecture slide that introduces the concept of phase estimation.

Lecture 6: Application: Quantum Phase Estimation

This resource explains Quantum Phase Estimation (QPE), the formal name for the subroutine that uses the QFT to find properties like periodicity.

Read sections 3.10 "Application: Quantum Phase Estimation (QPE)" and the subsequent part explaining the circuit. Don't worry about the detailed math of the phase kickback. Focus on the high-level idea: Controlled operations encode the information (the period) into the phases of an auxiliary register. The Inverse QFT is then used to "decode" this phase information into a bitstring that we can measure. The diagram in Figure 8 shows this clearly: the IQFT is the final step before measurement.

Once we measure m, we have the equation . Since we know m and N, we can use a classical algorithm called the continued fractions algorithm to find the fraction and from it, the period r. We won't delve into the classical continued fractions algorithm, but the key is that once we have m, the rest is straightforward classical post-processing.



Conclusion

In this lesson, we've uncovered the pivotal role of the Quantum Fourier Transform in Shor's algorithm. You saw that it's not just abstract mathematics, but a practical tool for extracting hidden periodic information from a quantum state.

Key Takeaways:

  • After preparing the quantum system, the period r is encoded in a periodic superposition of states in an input register.
  • Directly measuring this state is not useful, as it just returns a random term from the superposition.
  • The Quantum Fourier Transform (QFT) is a tool that transforms a state from the computational basis to a phase-encoded "Fourier" basis. It acts like a "rhythm detector."
  • In the period-finding routine, an Inverse QFT is applied to the periodic state. This causes constructive interference for states related to the period r.
  • A final measurement then yields a value m that is approximately a multiple of , from which the period r can be classically determined.

Preview of the Next Lesson:

We now understand what the QFT does conceptually and why it's essential for period-finding. But how is this powerful transform actually built? In our next lesson, we will get practical and implement the QFT circuit for a small number of qubits in Qiskit, constructing it from the basic Hadamard and controlled-rotation gates you've already seen.