Shor's algorithm


Shor's algorithm is a polynomial-time quantum computer algorithm for integer factorization. Informally, it solves the following problem: Given an integer, find its prime factors. It was invented in 1994 by the American mathematician Peter Shor.
On a quantum computer, to factor an integer, Shor's algorithm runs in polynomial time. Specifically, it takes quantum gates of order using fast multiplication, thus demonstrating that the integer-factorization problem can be efficiently solved on a quantum computer and is consequently in the complexity class BQP. This is almost exponentially faster than the most efficient known classical factoring algorithm, the general number field sieve, which works in sub-exponential time —. The efficiency of Shor's algorithm is due to the efficiency of the quantum Fourier transform, and modular exponentiation by repeated squarings.
If a quantum computer with a sufficient number of qubits could operate without succumbing to quantum noise and other quantum-decoherence phenomena, then Shor's algorithm could be used to break public-key cryptography schemes, such as the widely used RSA scheme. RSA is based on the assumption that factoring large integers is computationally intractable. As far as is known, this assumption is valid for classical computers; no classical algorithm is known that can factor integers in polynomial time. However, Shor's algorithm shows that factoring integers is efficient on an ideal quantum computer, so it may be feasible to defeat RSA by constructing a large quantum computer. It was also a powerful motivator for the design and construction of quantum computers, and for the study of new quantum-computer algorithms. It has also facilitated research on new cryptosystems that are secure from quantum computers, collectively called post-quantum cryptography.
In 2001, Shor's algorithm was demonstrated by a group at IBM, who factored into, using an NMR implementation of a quantum computer with qubits. After IBM's implementation, two independent groups implemented Shor's algorithm using photonic qubits, emphasizing that multi-qubit entanglement was observed when running the Shor's algorithm circuits. In 2012, the factorization of was performed with solid-state qubits. Also, in 2012, the factorization of was achieved, setting the record for the largest integer factored with Shor's algorithm.

Procedure

The problem that we are trying to solve is, given a composite number, to find a non-trivial divisor of . Before attempting to find such a divisor, one can use relatively quick primality-testing algorithms to verify that is indeed composite.
We need to be odd and not to be any power of a prime, so we need to check that there are no integer roots for.
Hence we may assume that is the product of two coprime integers greater than. It follows from the Chinese remainder theorem that there are at least four distinct square roots of modulo . The aim of the algorithm is to find a square root of modulo that is different from and, because then
for a non-zero integer which gives us the non-trivial divisors and of.
This idea is similar to other factoring algorithms, like the quadratic sieve.
In turn, finding such a is reduced to finding an element of even period with a certain additional property. The quantum algorithm is used for finding the period of randomly chosen elements, as this is a hard problem on a classical computer.
Shor's algorithm consists of two parts:
  1. A reduction, which can be done on a classical computer, of the factoring problem to the problem of order-finding.
  2. A quantum algorithm to solve the order-finding problem.

    Classical part

For example: Given,, and, we have, where and. For that is a product of two distinct primes, and, the value of is just, which for is, and divides.

Quantum part: period-finding subroutine

The quantum circuits used for this algorithm are custom designed for each choice of and each choice of the random used in. Given such that, which implies that. The input and output qubit registers need to hold superpositions of values from to, and so have qubits each. Using what might appear to be twice as many qubits as necessary guarantees that there are at least different values of that produce the same, even as the period approaches.
Proceed as follows:

Explanation of the algorithm

The algorithm is composed of two parts. The first part of the algorithm turns the factoring problem into the problem of finding the period of a function and may be implemented classically. The second part finds the period using the quantum Fourier transform and is responsible for the quantum speedup.

Obtaining factors from period

The integers less than and coprime with form the multiplicative group of integers modulo, which is a finite abelian group. The size of this group is given by. By the end of step 3, we have an integer in this group. As the group is finite, must have a finite order, which is the smallest positive integer such that
Therefore, divides . Suppose that we are able to obtain and that it is even. Now is a square root of modulo that is different from. This is because is the order of modulo, so, or else the order of in this group would be. If, then by step 6, we have to restart the algorithm with a different random number.
Eventually, we must hit an of order in such that. This is because such a is a square root of modulo other than and, whose existence is guaranteed by the Chinese remainder theorem, as is not a prime power.
We claim that is a proper factor of, i.e.,. In fact, if, then divides, so that, which goes against the construction of. If, on the other hand,, then by Bézout's identity, there are integers such that
Multiplying both sides by, we obtain
As divides, we find that divides, so that, again contradicting the construction of.
Therefore, is the required proper factor of.

Finding the period

Shor's period-finding algorithm relies heavily on the ability of a quantum computer to be in many states simultaneously.
Physicists call this behavior a "superposition" of states. To compute the period of a function, we evaluate the function at all points simultaneously.
Quantum physics does not allow us to access all this information directly, though. A measurement will yield only one of all possible values, destroying all others. If not for the no cloning theorem, we could first measure without measuring, and then make a few copies of the resulting state. Measuring on these states would provide different values which give the same, leading to the period. Because we cannot make exact copies of a quantum state, this method does not work. Therefore, we have to carefully transform the superposition to another state that will return the correct answer with high probability. This is achieved by the quantum Fourier transform.
Shor thus had to solve three "implementation" problems. All of them had to be implemented "fast", which means that they can be implemented with a number of quantum gates that is polynomial in.
  1. Create a superposition of states. This can be done by applying Hadamard gates to all qubits in the input register. Another approach would be to use the quantum Fourier transform.
  2. Implement the function as a quantum transform. To achieve this, Shor used repeated squaring for his modular exponentiation transformation. It is important to note that this step is more difficult to implement than the quantum Fourier transform, in that it requires ancillary qubits and substantially more gates to accomplish.
  3. Perform a quantum Fourier transform. By using controlled rotation gates and Hadamard gates, Shor designed a circuit for the quantum Fourier transform that uses just gates.
After all these transformations a measurement will yield an approximation to the period. For simplicity assume that there is a such that is an integer. Then the probability to measure is. To see this, we notice that then
for all integers. Therefore, the sum whose square gives us the probability to measure will be, as takes roughly values and thus the probability is. There are possible values of such that is an integer, and also possibilities for, so the probabilities sum to.
Note: Another way to explain Shor's algorithm is by noting that it is just the quantum phase estimation algorithm in disguise.

The bottleneck

The runtime bottleneck of Shor's algorithm is quantum modular exponentiation, which is by far slower than the quantum Fourier transform and classical pre-/post-processing. There are several approaches to constructing and optimizing circuits for modular exponentiation. The simplest and most practical approach is to mimic conventional arithmetic circuits with reversible gates, starting with ripple-carry adders. Knowing the base and the modulus of exponentiation facilitates further optimizations. Reversible circuits typically use on the order of gates for qubits. Alternative techniques asymptotically improve gate counts by using quantum Fourier transforms, but are not competitive with fewer than 600 qubits due to high constants.

Discrete logarithms

Given a group with order and generator, suppose we know that, for some, and we wish to compute, which is the discrete logarithm:. Consider the abelian group, where each factor corresponds to modular addition of values. Now, consider the function
This gives us an abelian hidden subgroup problem, as corresponds to a group homomorphism. The kernel corresponds to the multiples of. So, if we can find the kernel, we can find.