Hello! Welcome to the next lesson in our series on foundational quantum algorithms.
In the previous lesson, we delved into the Quantum Phase Estimation (QPE) algorithm. We saw how it brilliantly uses the Inverse Quantum Fourier Transform to estimate the phase of an eigenvalue of a unitary operator. We concluded by noting that QPE's most famous application is Shor's algorithm, and that the first step is to connect the problem of factoring to a problem that QPE can solve.
Today, we will build that connection. Our goal is to derive the reduction of integer factoring to period-finding by proving that the order of a mod N yields a factor of N with high probability. This is the crucial, purely classical, number-theoretic foundation upon which Shor's quantum algorithm is built. We will see that the classically hard problem of factoring an integer N can be transformed into another classically hard problem: finding the period (or order) of a specific function. This reduction perfectly motivates the need for a quantum subroutine to solve the period-finding part efficiently.
1. The Overall Strategy
The core idea of Shor's algorithm is to transform the factoring problem into a period-finding problem. Let's first get a high-level overview of the classical steps involved in this reduction.
The following video provides a clear, step-by-step walkthrough of the classical protocol. It outlines how choosing a random number, finding its order, and checking a few simple conditions can lead to the factors of N.
Shor's Factoring Algorithm, Reducing Prime Factorization to an Order-Finding Problem
This video from the Elucyda channel explains the classical part of Shor's algorithm. It breaks down the process into manageable steps and provides the mathematical reasoning for why the method works.
Please watch the following segments: Step 1 (04:28 - 07:19): Understand the initial step of picking a random integer a and the 'lucky' case where the GCD check immediately yields a factor. Step 2 (07:19 - 09:11): Focus on the definition of the order-finding problem, which is the heart of the algorithm. Step 3 (09:11 - 12:22): Pay close attention to the two crucial conditions the order r must satisfy (r is even, and a^(r/2) ≠ -1 mod N). Derivation (19:26 - 25:05): This part explains why these conditions allow us to find the factors, using the difference of squares factorization.
To summarize the strategy from the video:
- Given a composite number to factor, pick a random integer such that .
- Compute . If , you have found a non-trivial factor of , and you are done.
- If (i.e., and are coprime), find the order of modulo . The order is the smallest positive integer such that . This is the computationally hard step that will later be handled by a quantum computer.
- If is odd, or if , the method fails for this choice of . Go back to step 1 and pick a new .
- If is even and , then you can find the factors of by computing and . At least one of these will be a non-trivial factor of .
Now, let's formalize this and prove why it works with high probability.
2. The Key Insight: Non-Trivial Square Roots of Unity
The entire reduction hinges on a clever piece of number theory. If we can find a number that is a "non-trivial" square root of 1 modulo , we can efficiently factor .
A non-trivial square root of 1 modulo N is an integer such that:
- and
The following lemma establishes the connection between such an and the factors of .
Shor’s Factoring Algorithm Lecture 9
This excerpt from lecture notes by Prof. Umesh Vazirani at UC Berkeley provides a concise and formal proof of how a non-trivial square root of 1 modulo N can be used to find a factor of N.
Please read 'Lemma 9.1' and its short proof on page 2. It's a very direct argument that you should be able to follow easily.
Let's walk through the proof from the notes.
The condition means that is a multiple of . We can write this as:
Factoring the left side gives us the difference of squares:
This equation tells us that divides the product .
Now, we use the "non-trivial" conditions:
- Since , is not a multiple of .
- Since , is not a multiple of .
Since divides the product but does not divide either term individually, must share a non-trivial factor with both and . We can find these factors efficiently using the Euclidean algorithm:
factor_1 = gcd(x - 1, N)factor_2 = gcd(x + 1, N)
At least one of these factors will be a non-trivial factor of .
3. Finding the Non-Trivial Root via Order-Finding
The question now is: how do we find such a non-trivial root ? This is where the order-finding procedure comes in.
If we pick a random coprime to and find its order , we have . If happens to be even, we can define . This is a natural candidate for a square root of 1, since:
Now we must check if it's non-trivial:
- Is ? No, because if , then the order of would be or smaller, which contradicts the definition of as the smallest such positive integer.
- Is ? This is possible, and it represents a failure case for our method.
So, the reduction is successful if, for a randomly chosen , its order is even and . The final step is to prove that this happens with a reasonably high probability.
4. The High-Probability Guarantee
We now arrive at the core of today's learning outcome: proving that the conditions for success are met with high probability. We will assume is the product of two distinct odd primes, which is the most relevant case for cryptography.
The proof relies on the Chinese Remainder Theorem (CRT). The CRT implies that choosing an integer modulo is equivalent to independently choosing an integer and an integer . The order of modulo , which we call , is then related to the orders of modulo () and modulo () by .
The following reading provides the proof that our desired conditions hold with high probability.
Shor’s Factoring Algorithm Lecture 9
This final section from Vazirani's notes proves that for a random x (our a), its order r is even and x^(r/2) is non-trivial with a good probability.
Read 'Lemma 9.2' and 'Lemma 9.3' on page 2. The proofs are very dense, so focus on grasping the main line of argument, which I will break down for you below.
Let's dissect the argument in Lemma 9.3. We need to show that with high probability, (1) is even, and (2) .
1. Probability that is even
- The order is odd if and only if both and are odd.
- The probability that the order of a random element modulo a prime is odd can be shown to be at most . (This is related to the structure of the multiplicative group , which is cyclic).
- Since and are chosen independently, the probability that both and are odd is .
- Therefore, the probability that is odd is at most . This means the probability that is even is at least .
2. Probability that
- Let's assume is even. We have found a square root of unity, .
- We know . We fail if .
- Using the CRT, is equivalent to the system of congruences:
- The successful cases are when is a non-trivial root, which corresponds to:
- Case A: and
- Case B: and
- A more detailed analysis (as found in standard texts like Nielsen & Chuang) shows that at least two of the four possible combinations for are "good" cases. This leads to the conclusion that given is even, the probability of success (i.e., ) is at least .
Combining the probabilities:
The probability of success is .
Using the bounds we just discussed, this is at least .
(Note: Most sources, including Nielsen & Chuang, arrive at a tighter lower bound of for the total success probability when has two prime factors. The logic is slightly different but the conclusion is stronger. For our purposes, showing the probability is a constant significantly greater than zero is sufficient.)
This proves that by picking a random and finding its order , we have a constant, high probability of finding a non-trivial factor of . If we fail, we simply pick another and try again. A few attempts are very likely to succeed.
Conclusion
In this lesson, we have established the classical number-theoretic backbone of Shor's algorithm.
Key Takeaways:
- Factoring via Non-Trivial Roots: The problem of factoring can be solved if we can find a non-trivial square root of 1 modulo , i.e., an such that but . The factors are then given by .
- Reduction to Order-Finding: Such a non-trivial root can be found by picking a random integer , computing its order modulo , and setting .
- Conditions for Success: This procedure works provided that (1) the order is even, and (2) .
- High-Probability Guarantee: For a composite number , these conditions are met for a randomly chosen with a probability of at least . This ensures that the reduction from factoring to order-finding is not just a theoretical curiosity but a practical and efficient classical reduction.
We have successfully reduced the problem of factoring to the problem of finding the order of an element. The order-finding problem is still computationally hard for classical computers. In our next lessons, we will see how to construct the specific unitary operator for modular exponentiation and then use the Quantum Phase Estimation algorithm to solve the order-finding problem efficiently, completing our construction of Shor's algorithm.