Hello! Welcome back to our deep dive into foundational quantum algorithms.
In our last lesson, we constructed the reversible quantum circuit for modular exponentiation, . This circuit, based on the classical repeated squaring algorithm, is the computational engine at the heart of Shor's algorithm.
Today, we will integrate this engine into a larger framework to achieve our goal: finding the period of modulo . Our learning outcome is to integrate the modular exponentiation oracle into the Quantum Phase Estimation framework to construct the complete circuit for the period-finding subroutine. This lesson will connect all the pieces—the number theory, the quantum circuit design, and the Quantum Fourier Transform—into a single, powerful quantum procedure.
1. The Quantum Phase Estimation (QPE) Algorithm
The core quantum primitive we will use is Quantum Phase Estimation (QPE). Its purpose is to determine the eigenvalue of a unitary operator.
The problem is as follows: Given a unitary operator and one of its eigenvectors such that , the goal is to find the phase .
The QPE algorithm uses two quantum registers:
- A counting register of qubits, initialized to . The number of qubits determines the precision of our phase estimate.
- A state register of qubits, which holds the eigenvector .
The general procedure is a beautiful application of phase kickback and the Quantum Fourier Transform. The following video provides a detailed and clear explanation of the QPE algorithm.
Phase Estimation and Factoring | Understanding Quantum Information & Computation | Lesson 07
Let's begin with a thorough review of the Quantum Phase Estimation (QPE) algorithm. This video from the Qiskit YouTube channel provides an excellent walkthrough, starting from the basic problem definition and building up to the general procedure.
Please watch the following segments: 'Phase Estimation Problem Definition and Warm-up' (05:43 - 17:17) to understand the core problem. 'Generalizing Phase Estimation with Multiple Control Qubits and QFT' (17:17 - 32:21) to see how precision is increased. 'Generalized Phase Estimation Procedure and Cost Analysis' (41:45 - 48:22) for the complete, general algorithm. Focus on the structure of the circuit: the two registers, the sequence of controlled-U powers, and the crucial role of the inverse Quantum Fourier Transform (QFT⁻¹).
2. Applying QPE to the Order-Finding Problem
Now, let's specialize this general QPE framework for our specific task of finding the order . This requires us to define the unitary operator , its eigenvectors, and the initial state we will use.
The Unitary Operator
The unitary operator whose eigenvalues encode the period is not the full modular exponentiation circuit from last lesson, but rather the simpler modular multiplication operator:
where is an integer with and . This operator is unitary because it simply permutes the basis states .
Eigenstates and Eigenvalues
The eigenstates of this operator are Fourier-type states. For integers where , the states are defined as:
Applying our unitary to such a state reveals its eigenvalue:
The phase of the eigenvalue is . This is exactly what we need! If we can estimate these phases, we can find the period .
Preparing the Input State
A challenge arises here: to prepare an eigenstate , we need to know , which is the very quantity we are trying to find. The solution is a remarkably elegant trick. Instead of preparing a single eigenstate, we prepare a state that is an equal superposition of all of them. As it turns out, the simple state is exactly this superposition:
The following reading from your alma mater's lecture notes provides a concise derivation of these facts.
Quantum Computing (CST Part II) - Lecture 10
Let's formalize the connection between QPE and order-finding. These lecture notes from the University of Cambridge CST Part II course provide a rigorous mapping.
Please read the following sections: 'Order finding using quantum phase estimation' (page 7): This defines the specific unitary operator U whose eigenvalues encode the period. 'The eigenvalues of U' and 'A superposition of eigenstates of U' (pages 11-12): These sections derive the eigenstates and eigenvalues of U, and crucially, show why the simple state |1⟩ is the correct input for the state register. Pay close attention to the form of the eigenvalues, e^{2πis/r}, as this is the phase we aim to estimate.
By using as the input to the state register, the linearity of quantum mechanics ensures that the QPE circuit will simultaneously estimate the phase for each eigenstate in the superposition. A measurement of the counting register will then yield an estimate for for a randomly chosen .
3. Constructing the Complete Period-Finding Circuit
We are now ready to assemble the full circuit. The QPE algorithm requires us to implement a sequence of controlled unitaries: C-, C-, C-, ..., C-.
This is precisely where the modular exponentiation circuit from our previous lesson comes into play. Note that . This is just modular multiplication by the constant .
The "trick" is that instead of applying the gate times, we can classically compute (using exponentiation by squaring) and then implement a single controlled-multiplication by . This is exponentially faster.
The modular exponentiation circuit we built last lesson, which maps , is exactly the implementation of this entire sequence of controlled operations, where the qubits of are the control qubits for QPE.
This is the central point of integration.
Quantum Computing (CST Part II) - Lecture 10
The QPE algorithm requires a series of controlled gates: C-U, C-U², C-U⁴, and so on. A naive implementation would be exponentially costly. This is the key integration point with our previous lesson.
Please read 'Implementing the series of controlled-U^2j gates' and 'Complexity of implementing the controlled-U^2j gates' (pages 9-10). This section explicitly details how classical pre-computation of a^{2^j} mod N allows for an efficient construction of the required controlled unitaries. This is the 'modular exponentiation oracle' in action.
The complete circuit for the period-finding subroutine is therefore a direct implementation of QPE tailored for this problem.

4. From Phase to Period: Classical Post-Processing
After running the circuit and measuring the -qubit counting register, we obtain a measurement result, an integer . This gives us the approximation:
for some random .
Our final task is to recover from this approximation. This is a classic problem in number theory that can be solved efficiently using the continued fractions algorithm. This algorithm takes a real number (our ) and finds the "best" rational approximation with a denominator below a certain bound.
If we choose large enough (typically ), the approximation will be close enough to for the continued fractions algorithm to recover the fraction exactly (in lowest terms).
The denominator of the resulting fraction is our candidate for the period . If , the denominator will be a factor of . By repeating the entire quantum procedure a few times and taking the least common multiple of the resulting denominators, we can determine with very high probability.
The final part of the Qiskit video explains this post-processing step.
Phase Estimation and Factoring | Understanding Quantum Information & Computation | Lesson 07
After measuring the counting register, we get an integer that gives us a binary approximation of a fraction s/r. To recover the period r, we need a classical algorithm to find this fraction. The Qiskit video explains this final step.
Please watch the segment from 57:50 to 1:04:40 within the 'Order Finding Problem and Connection to Phase Estimation' part. This section explains how the measurement result is used with the continued fraction algorithm to find the period r, even when we only get s/r for a random s.
Conclusion
We have now assembled the complete quantum subroutine for period-finding, the core of Shor's algorithm.
Key Takeaways:
- The period-finding algorithm is a specific application of the Quantum Phase Estimation (QPE) framework.
- The relevant unitary is the modular multiplication operator , whose eigenvalues encode the period .
- The required input eigenstate is prepared by using the simple state , which is an equal superposition of all the necessary eigenstates.
- The sequence of controlled unitaries (C-) required by QPE is implemented efficiently by the modular exponentiation circuit we constructed in the previous lesson. This is the "oracle".
- The final measurement from QPE gives an estimate of the phase , which is then processed by the classical continued fractions algorithm to find the period .
In our next lesson, we will analyze the computational complexity of this entire procedure, comparing it to the best classical factoring algorithms like the General Number Field Sieve, to fully appreciate the source and magnitude of the quantum speedup.