Shor's algorithm

1

Shor's algorithm is a quantum algorithm for finding the prime factors of an integer. It was developed in 1994 by the American mathematician Peter Shor. It is one of the few known quantum algorithms with compelling potential applications and strong evidence of superpolynomial speedup compared to best known classical (non-quantum) algorithms. On the other hand, factoring numbers of practical significance requires far more qubits than available in the near future. Another concern is that noise in quantum circuits may undermine results, requiring additional qubits for quantum error correction. Shor proposed multiple similar algorithms for solving the factoring problem, the discrete logarithm problem, and the period-finding problem. "Shor's algorithm" usually refers to the factoring algorithm, but may refer to any of the three algorithms. The discrete logarithm algorithm and the factoring algorithm are instances of the period-finding algorithm, and all three are instances of the hidden subgroup problem. On a quantum computer, to factor an integer N, Shor's algorithm runs in polynomial time, meaning the time taken is polynomial in \log N. It takes quantum gates of order using fast multiplication, or even utilizing the asymptotically fastest multiplication algorithm currently known due to Harvey and Van Der Hoven,<ref name="Integer multiplication in time.

Feasibility and impact

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 RSA can be broken if factoring large integers is computationally feasible. As far as is known, this is not possible using classical (non-quantum) 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.

Physical implementation

Given the high error rates of contemporary quantum computers and too few qubits to use quantum error correction, laboratory demonstrations obtain correct results only in a fraction of attempts. In 2001, Shor's algorithm was demonstrated by a group at IBM, who factored 15 into 3 \times 5, using an NMR implementation of a quantum computer with seven 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 15 was performed with solid-state qubits. Later, in 2012, the factorization of 21 was achieved. In 2016, the factorization of 15 was performed again using trapped-ion qubits with a recycling technique. In 2019, an attempt was made to factor the number 35 using Shor's algorithm on an IBM Q System One, but the algorithm failed because of accumulating errors. However, all these demonstrations have compiled the algorithm by making use of prior knowledge of the answer, and some have even oversimplified the algorithm in a way that makes it equivalent to coin flipping. Furthermore, attempts using quantum computers with other algorithms have been made. However, these algorithms are similar to classical brute-force checking of factors, so unlike Shor's algorithm, they are not expected to ever perform better than classical factoring algorithms. Theoretical analyses of Shor's algorithm assume a quantum computer free of noise and errors. However, near-term practical implementations will have to deal with such undesired phenomena (when more qubits are available, Quantum error correction can help). In 2023, Jin-Yi Cai showed that in the presence of noise, Shor's algorithm fails asymptotically almost surely for large semiprimes that are products of two primes in. These primes p have the property that p-1 has a prime factor larger than p^{2/3}, and have a positive density in the set of all primes. Hence error-correction will be needed to be able to factor all numbers with Shor's algorithm.

Algorithm

The problem that we are trying to solve is: given an odd composite number N, find its integer factors. To achieve this, Shor's algorithm consists of two parts:

Classical reduction

A complete factoring algorithm is possible if we're able to efficiently factor arbitrary N into just two integers p and q greater than 1, since if either p or q are not prime then the factoring algorithm can in turn be run on those until only primes remain. A basic observation is that, using Euclid's algorithm, we can always compute the GCD between two integers efficiently. In particular, this means we can check efficiently whether N is even, in which case 2 is trivially a factor. Let us thus assume that N is odd for the remainder of this discussion. Afterwards, we can use efficient classical algorithms to check if N is a prime power. For prime powers, efficient classical factorization algorithms exist, hence the rest of the quantum algorithm may assume that N is not a prime power. If those easy cases do not produce a nontrivial factor of N, the algorithm proceeds to handle the remaining case. We pick a random integer. A possible nontrivial divisor of N can be found by computing \gcd(a, N), which can be done classically and efficiently using the Euclidean algorithm. If this produces a nontrivial factor (meaning ), the algorithm is finished, and the other nontrivial factor is. If a nontrivial factor was not identified, then that means that N and the choice of a are coprime, so a is contained in the multiplicative group of integers modulo N, having a multiplicative inverse modulo N. Thus, a has a multiplicative order r modulo N, meaning and r is the smallest positive integer satisfying this congruence. The quantum subroutine finds r. It can be seen from the congruence that N divides a^{r} - 1, written. This can be factored using difference of squares: Since we have factored the expression in this way, the algorithm doesn't work for odd r (because a^{r/2} must be an integer), meaning the algorithm would have to restart with a new a. Hereafter we can therefore assume r is even. It cannot be the case that, since this would imply , which would contradictorily imply that \frac{r}{2} would be the order of a, which was already r. At this point, it may or may not be the case that. If it is not true that, then that means we are able to find a nontrivial factor of N. We computeIf d = 1, then that means was true, and a nontrivial factor of N cannot be achieved from a, and the algorithm must restart with a new a. Otherwise, we have found a nontrivial factor of N, with the other being \frac{N}{d}, and the algorithm is finished. For this step, it is also equivalent to compute ; it will produce a nontrivial factor if is nontrivial, and will not if it's trivial (where ). The algorithm restated shortly follows: let N be odd, and not a prime power. We want to output two nontrivial factors of N. 1. Pick a random number 1 < a < N. 2. If K \neq 1, then K is a nontrivial factor of N, with the other factor being \frac{N}{K} and we are done. 3. Otherwise, use the quantum subroutine to find the order r of a. 4. If r is odd, then go back to step 1. 5. Compute. If g is nontrivial, the other factor is \frac{N}{g}, and we're done. Otherwise, go back to step 1. It has been shown that this will be likely to succeed after a few runs. In practice, a single call to the quantum order-finding subroutine is enough to completely factor N with very high probability of success if one uses a more advanced reduction.

Quantum order-finding subroutine

The goal of the quantum subroutine of Shor's algorithm is, given coprime integers N and 1< a<N, to find the order r of a modulo N, which is the smallest positive integer such that. To achieve this, Shor's algorithm uses a quantum circuit involving two registers. The second register uses n qubits, where n is the smallest integer such that N\le 2^n, i.e.,. The size of the first register determines how accurate of an approximation the circuit produces. It can be shown that using 2n qubits gives sufficient accuracy to find r. The exact quantum circuit depends on the parameters a and N, which define the problem. The following description of the algorithm uses bra–ket notation to denote quantum states, and \otimes to denote the tensor product, rather than logical AND. The algorithm consists of two main steps: The connection with quantum phase estimation was not discussed in the original formulation of Shor's algorithm, but was later proposed by Kitaev.

Quantum phase estimation

In general the quantum phase estimation algorithm, for any unitary U and eigenstate such that, sends input states to output states close to , where \phi is an integer close to. In other words, it sends each eigenstate of U to a state close to the associated eigenvalue. For the purposes of quantum order-finding, we employ this strategy using the unitary defined by the actionThe action of U on states |k\rangle with is not crucial to the functioning of the algorithm, but needs to be included to ensure the overall transformation is a well-defined quantum gate. Implementing the circuit for quantum phase estimation with U requires being able to efficiently implement the gates U^{2^j}. This can be accomplished via modular exponentiation, which is the slowest part of the algorithm. The gate thus defined satisfies U^r=I, which immediately implies that its eigenvalues are the r-th roots of unity. Furthermore, each eigenvalue \omega_r^j has an eigenvector of the form, and these eigenvectors are such that where the last identity follows from the geometric series formula, which implies. Using quantum phase estimation on an input state would then return the integer 2^{2n} j/r with high probability. More precisely, the quantum phase estimation circuit sends to such that the resulting probability distribution is peaked around, with. This probability can be made arbitrarily close to 1 using extra qubits. Applying the above reasoning to the input, quantum phase estimation thus results in the evolutionMeasuring the first register, we now have a balanced probability 1/r to find each , each one giving an integer approximation to 2^{2 n} j/r, which can be divided by 2^{2n} to get a decimal approximation for j/r.

Continued fraction algorithm to retrieve the period

Then, we apply the continued fractions algorithm to find integers b and c, where \frac{b}{c} gives the best fraction approximation for the approximation measured from the circuit, for b, c < N and coprime b and c. The number of qubits in the first register, 2n, which determines the accuracy of the approximation, guarantees thatgiven the best approximation from the superposition of was measured (which can be made arbitrarily likely by using extra bits and truncating the output). However, while b and c are coprime, it may be the case that j and r are not coprime. Because of that, b and c may have lost some factors that were in j and r. This can be remedied by rerunning the quantum order-finding subroutine an arbitrary number of times, to produce a list of fraction approximationswhere s is the number of times the subroutine was run. Each c_k will have different factors taken out of it because the circuit will (likely) have measured multiple different possible values of j. To recover the actual r value, we can take the least common multiple of each c_k:The least common multiple will be the order r of the original integer a with high probability. In practice, a single run of the quantum order-finding subroutine is in general enough if more advanced post-processing is used.

Choosing the size of the first register

Phase estimation requires choosing the size of the first register to determine the accuracy of the algorithm, and for the quantum subroutine of Shor's algorithm, 2n qubits is sufficient to guarantee that the optimal bitstring measured from phase estimation (meaning the |k\rangle where k / 2^{2n} is the most accurate approximation of the phase from phase estimation) will allow the actual value of r to be recovered. Each before measurement in Shor's algorithm represents a superposition of integers approximating 2^{2 n} j/r. Let |k\rangle represent the most optimal integer in. The following theorem guarantees that the continued fractions algorithm will recover j/r from k/2^{2 {n}}: As k is the optimal bitstring from phase estimation, k/2^{2 {n}} is accurate to j/r by 2n bits. Thus,which implies that the continued fractions algorithm will recover j and r (or with their greatest common divisor taken out).

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 (currently) 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 n^3 gates for n qubits. Alternative techniques asymptotically improve gate counts by using quantum Fourier transforms, but are not competitive with fewer than 600 qubits owing to high constants.

Period finding and discrete logarithms

Shor's algorithms for the discrete log and the order finding problems are instances of an algorithm solving the period finding problem.. All three are instances of the hidden subgroup problem.

Shor's algorithm for discrete logarithms

Given a group G with order p and generator g \in G, suppose we know that, for some , and we wish to compute r, 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, where f corresponds to a group homomorphism. The kernel corresponds to the multiples of (r,1). So, if we can find the kernel, we can find r. A quantum algorithm for solving this problem exists. This algorithm is, like the factor-finding algorithm, due to Peter Shor and both are implemented by creating a superposition through using Hadamard gates, followed by implementing f as a quantum transform, followed finally by a quantum Fourier transform. Due to this, the quantum algorithm for computing the discrete logarithm is also occasionally referred to as "Shor's Algorithm." The order-finding problem can also be viewed as a hidden subgroup problem. To see this, consider the group of integers under addition, and for a given such that: a^{r}=1, the function For any finite abelian group G, a quantum algorithm exists for solving the hidden subgroup for G in polynomial time.

This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.

Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc.
Bliptext is not affiliated with or endorsed by Wikipedia or the Wikimedia Foundation.

Edit article