Shor's algorithm: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
imported>Qcomp
m direct link to article instead of list of names
imported>Countercheck
light copyedit; added a diagram
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Short description|Quantum algorithm for integer factorization}}'''Shor's algorithm''' is a [[quantum algorithm]] for finding the [[prime factor]]s of an integer. It was developed in 1994 by the American mathematician [[Peter Shor]].<ref>{{cite book |doi=10.1109/sfcs.1994.365700 |chapter=Algorithms for quantum computation: Discrete logarithms and factoring |title=Proceedings 35th Annual Symposium on Foundations of Computer Science |date=1994 |last1=Shor |first1=P.W. |pages=124–134 |isbn=978-0-8186-6580-6 }}</ref><ref name="siam">{{Cite journal |last=Shor |first=Peter W. |date=October 1997 |title=Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer |journal=SIAM Journal on Computing |volume=26 |issue=5 |pages=1484–1509 |arxiv=quant-ph/9508027 |doi=10.1137/S0097539795293172 |s2cid=2337707 }}</ref> 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.<ref name=":0" /> On the other hand, factoring numbers of practical significance requires far more [[qubit|qubits]] than available in the near future.<ref name="q2000">{{cite journal|arxiv=1905.09749| title =  
{{Short description|Quantum algorithm for integer factorization}}'''Shor's algorithm''' is a [[quantum algorithm]] for finding the [[prime factor]]s of an integer. It was developed in 1994 by the American mathematician [[Peter Shor]].<ref>{{cite book |doi=10.1109/sfcs.1994.365700 |chapter=Algorithms for quantum computation: Discrete logarithms and factoring |title=Proceedings 35th Annual Symposium on Foundations of Computer Science |date=1994 |last1=Shor |first1=P.W. |pages=124–134 |isbn=978-0-8186-6580-6 }}</ref><ref name="siam">{{Cite journal |last=Shor |first=Peter W. |date=October 1997 |title=Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer |journal=SIAM Journal on Computing |volume=26 |issue=5 |pages=1484–1509 |arxiv=quant-ph/9508027 |doi=10.1137/S0097539795293172 |s2cid=2337707 }}</ref> 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.<ref name=":0" /> However, beating classical computers will require quantum computers with millions of qubits due to the overhead caused by [[quantum error correction]].<ref name="q2000">{{cite journal|arxiv=1905.09749| title =  
How to factor 2048 bit RSA integers in 8 hours using 20 million noisy qubits |
How to factor 2048 bit RSA integers in 8 hours using 20 million noisy qubits |
first1 = Craig | last1 = Gidney | first2 = Martin | last2 = Ekerå| journal=Quantum | year=2021 | volume=5 | page=433 | doi=10.22331/q-2021-04-15-433 | bibcode =  
first1 = Craig | last1 = Gidney | first2 = Martin | last2 = Ekerå| journal=Quantum | year=2021 | volume=5 | article-number=433 | doi=10.22331/q-2021-04-15-433 | bibcode =  
2021Quant...5..433G | s2cid=162183806 }}
2021Quant...5..433G | s2cid=162183806 }}
</ref> Another concern is that noise in quantum circuits may undermine results,<ref name="noise"/> requiring additional qubits for [[quantum error correction]].
</ref>


Shor proposed multiple similar algorithms for solving the [[Integer factorization|factoring problem]], the [[Discrete logarithm|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]].
Shor proposed multiple similar algorithms for solving the [[Integer factorization|factoring problem]], the [[Discrete logarithm|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 <math> N </math>, Shor's algorithm runs in [[polynomial time]], meaning the time taken is polynomial in <math> \log N </math>.<ref>See also [[pseudo-polynomial time]].</ref> It takes [[quantum logic gate|quantum gates]] of order <math> O \! \left((\log N)^{2} (\log \log N) (\log \log \log N) \right) </math> using fast multiplication,<ref name="Beckman">{{cite journal |last1=Beckman |first1=David |last2=Chari |first2=Amalavoyal N. |last3=Devabhaktuni |first3=Srikrishna |last4=Preskill |first4=John |title=Efficient networks for quantum factoring |journal=Physical Review A |date=August 1996 |volume=54 |issue=2 |pages=1034–1063 |doi=10.1103/physreva.54.1034 |pmid=9913575 |arxiv=quant-ph/9602016 |bibcode=1996PhRvA..54.1034B }}</ref> or even <math> O \! \left((\log N)^{2} (\log \log N) \right) </math> utilizing the asymptotically fastest multiplication algorithm currently known due to Harvey and [[Joris van der Hoeven|van der Hoeven]],<ref name="Integer multiplication in time <math">{{cite journal |last1=Harvey |first1=David |last2=van der Hoeven |first2=Joris |title=Integer multiplication in time O (n log n) |journal=Annals of Mathematics |date=March 2021 |volume=193 |issue=2 |doi=10.4007/annals.2021.193.2.4 |url=https://hal.science/hal-02070778v2/file/nlogn.pdf }}</ref> 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 significantly faster than the most efficient known classical factoring algorithm, the [[general number field sieve]], which works in [[Time complexity#Sub-exponential time|sub-exponential time]]: <math> O \! \left(e^{1.9 (\log N)^{1/3} (\log \log N)^{2/3}} \right) </math>.<ref>{{cite web|url = http://mathworld.wolfram.com/NumberFieldSieve.html|title = Number Field Sieve|work = wolfram.com|access-date = 23 October 2015}}</ref>
On a quantum computer, to factor an integer <math> N </math>, Shor's algorithm runs in [[polynomial time]], meaning the time taken is polynomial in <math> \log N </math>.<ref>See also [[pseudo-polynomial time]].</ref> It takes [[quantum logic gate|quantum gates]] of order <math> O \! \left((\log N)^{2} (\log \log N) (\log \log \log N) \right) </math> using fast multiplication,<ref name="Beckman">{{cite journal |last1=Beckman |first1=David |last2=Chari |first2=Amalavoyal N. |last3=Devabhaktuni |first3=Srikrishna |last4=Preskill |first4=John |title=Efficient networks for quantum factoring |journal=Physical Review A |date=August 1996 |volume=54 |issue=2 |pages=1034–1063 |doi=10.1103/physreva.54.1034 |pmid=9913575 |arxiv=quant-ph/9602016 |bibcode=1996PhRvA..54.1034B }}</ref> or even <math> O \! \left((\log N)^{2} (\log \log N) \right) </math> using the asymptotically fastest multiplication algorithm currently known due to Harvey and [[Joris van der Hoeven|van der Hoeven]],<ref name="Integer multiplication in time <math">{{cite journal |last1=Harvey |first1=David |last2=van der Hoeven |first2=Joris |title=Integer multiplication in time O (n log n) |journal=Annals of Mathematics |date=March 2021 |volume=193 |issue=2 |doi=10.4007/annals.2021.193.2.4 |url=https://hal.science/hal-02070778v2/file/nlogn.pdf }}</ref> thus demonstrating that the [[integer factorization]] problem is in [[complexity class]] '''[[BQP]]'''. Shor's algorithm is asymptotically faster than the most scalable classical factoring algorithm, the [[general number field sieve]], which works in [[Time complexity#Sub-exponential time|sub-exponential time]]: <math> O \! \left(e^{1.9 (\log N)^{1/3} (\log \log N)^{2/3}} \right) </math>.<ref>{{cite web|url = http://mathworld.wolfram.com/NumberFieldSieve.html|title = Number Field Sieve|work = wolfram.com|access-date = 23 October 2015}}</ref>


== Feasibility and impact ==
== Feasibility and impact ==
 
[[File:Asymmetric encryption scheme.png|thumb|upright=1.2|Diagram presenting the encryption and the decryption of a document using asymmetric cryptography. Some forms of encryption (including asymmetric cryptography) are at risk of being broken by future quantum computers.]]
If a quantum computer with a sufficient number of [[qubit]]s could operate without succumbing to [[quantum noise]] and other [[quantum decoherence|quantum-decoherence]] phenomena, then Shor's algorithm could be used to break [[public-key cryptography]] schemes, such as
Assuming a quantum computer with a sufficient number of [[qubit]]s could operate without succumbing to [[quantum noise]] and other [[quantum decoherence|quantum-decoherence]] phenomena, then Shor's algorithm could be used to break [[public-key cryptography]] schemes, such as


* The [[RSA (cryptosystem)|RSA]] scheme
* The [[RSA (cryptosystem)|RSA]] scheme
* The finite-field [[Diffie–Hellman]] key exchange
* The finite-field [[Diffie–Hellman]] key exchange
* The elliptic-curve Diffie–Hellman key exchange<ref>{{cite conference
* The [[elliptic-curve Diffie–Hellman]] key exchange<ref>{{cite conference
  | last1 = Roetteler | first1 = Martin
  | last1 = Roetteler | first1 = Martin
  | last2 = Naehrig | first2 = Michael
  | last2 = Naehrig | first2 = Michael
Line 33: Line 33:
  }}</ref>
  }}</ref>


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]].
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 can be done with a polynomial complexity circuit on an ideal quantum computer. Thus, it might be feasible to defeat RSA by constructing a large enough quantum computer. This was 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]] (PQC).


=== Physical implementation ===
=== 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.
As of 2025, the high error rates of quantum computers and limited number of physical qubits available for [[quantum error correction]], laboratory demonstrations of Shor's algorithm obtain correct results in only in a fraction of attempts, and have only succeeded with small [[semiprime]]s.
 
In 2001, Shor's algorithm was demonstrated by a group at [[IBM]], who factored <math> 15 </math> into <math> 3 \times 5 </math>, using an [[Nuclear magnetic resonance quantum computer|NMR implementation]] of a quantum computer with seven qubits.<ref name = "VSBYSC01">{{cite journal |last1=Vandersypen |first1=Lieven M. K. |last2=Steffen |first2=Matthias |last3=Breyta |first3=Gregory |last4=Yannoni |first4=Costantino S. |last5=Sherwood |first5=Mark H. |last6=Chuang |first6=Isaac L. |title=Experimental realization of Shor's quantum factoring algorithm using nuclear magnetic resonance |journal=Nature |date=December 2001 |volume=414 |issue=6866 |pages=883–887 |doi=10.1038/414883a |pmid=11780055 |arxiv=quant-ph/0112176 |bibcode=2001Natur.414..883V }}</ref> After IBM's implementation, two independent groups implemented Shor's algorithm using [[Photonics|photonic]] qubits, emphasizing that multi-qubit [[quantum entanglement|entanglement]] was observed when running the Shor's algorithm circuits.<ref name = "LBYP07">{{cite journal |last1=Lu |first1=Chao-Yang |last2=Browne |first2=Daniel E. |last3=Yang |first3=Tao |last4=Pan |first4=Jian-Wei |title=Demonstration of a Compiled Version of Shor's Quantum Factoring Algorithm Using Photonic Qubits |journal=Physical Review Letters |date=19 December 2007 |volume=99 |issue=25 |page=250504 |doi=10.1103/PhysRevLett.99.250504 |pmid=18233508 |arxiv=0705.1684 |bibcode=2007PhRvL..99y0504L }}</ref><ref name = "LWLBJGW07">{{cite journal |last1=Lanyon |first1=B. P. |last2=Weinhold |first2=T. J. |last3=Langford |first3=N. K. |last4=Barbieri |first4=M. |last5=James |first5=D. F. V. |last6=Gilchrist |first6=A. |last7=White |first7=A. G. |title=Experimental Demonstration of a Compiled Version of Shor's Algorithm with Quantum Entanglement |journal=Physical Review Letters |date=19 December 2007 |volume=99 |issue=25 |page=250505 |doi=10.1103/PhysRevLett.99.250505 |pmid=18233509 |arxiv=0705.1398 |bibcode=2007PhRvL..99y0505L }}</ref> In 2012, the factorization of <math> 15 </math> was performed with solid-state qubits.<ref>{{Cite journal|last1 = Lucero|first1 = Erik|last2 = Barends|first2 = Rami|last3 = Chen|first3 = Yu|last4 = Kelly|first4 = Julian|last5 = Mariantoni|first5 = Matteo|last6 = Megrant|first6 = Anthony|last7 = O'Malley|first7 = Peter|last8 = Sank|first8 = Daniel|last9 = Vainsencher|first9 = Amit|last10 = Wenner|first10 = James|last11 = White|first11 = Ted|last12 = Yin|first12 = Yi|last13 = Cleland|first13 = Andrew N.|last14 = Martinis|first14 = John M.|title = Computing prime factors with a Josephson phase qubit quantum processor|journal = Nature Physics|volume = 8|issue = 10|pages = 719|year = 2012|doi = 10.1038/nphys2385|bibcode = 2012NatPh...8..719L|arxiv = 1202.5707|s2cid = 44055700}}</ref> Later, in 2012, the factorization of <math> 21 </math> was achieved.<ref>{{cite journal|last1 = Martín-López|first1 = Enrique|last2 = Martín-López|first2 = Enrique|last3 = Laing|first3 = Anthony|last4 = Lawson|first4 = Thomas|last5 = Alvarez|first5 = Roberto|last6 = Zhou|first6 = Xiao-Qi|last7 = O'Brien|first7 = Jeremy L.|title = Experimental realization of Shor's quantum factoring algorithm using qubit recycling|journal = Nature Photonics|volume =6|issue = 11|pages = 773–776|date = 12 October 2012|doi = 10.1038/nphoton.2012.259|arxiv = 1111.4147|bibcode = 2012NaPho...6..773M|s2cid = 46546101}}</ref> In 2016, the factorization of <math> 15 </math> was performed again using trapped-ion qubits with a recycling technique.<ref>{{cite journal|last1 = Monz|first1 = Thomas |last2 = Nigg|first2 = Daniel|last3 = Martinez|first3 = Esteban A.|last4 = Brandl|first4 = Matthias F.|last5 = Schindler|first5 = Philipp|last6 = Rines|first6 = Richard|last7 = Wang|first7 = Shannon X.|last8 = Chuang|first8 = Isaac L.|last9 = Blatt|first9 = Rainer|title = Realization of a scalable Shor algorithm|journal = Science|volume =351|issue = 6277|pages = 1068–1070|date = 4 March 2016|doi = 10.1126/science.aad9480|pmid = 26941315 |arxiv = 1507.08852|bibcode = 2016Sci...351.1068M|s2cid = 17426142}}</ref> In 2019, an attempt was made to factor the number <math> 35 </math> using Shor's algorithm on an IBM [[IBM Q System One|Q System One]], but the algorithm failed because of accumulating errors.<ref>{{cite journal |last1=Amico |first1=Mirko |last2=Saleem |first2=Zain H. |last3=Kumph |first3=Muir |title=Experimental study of Shor's factoring algorithm using the IBM Q Experience |journal=Physical Review A |date=8 July 2019 |volume=100 |issue=1 |page=012305 |doi=10.1103/PhysRevA.100.012305 |arxiv=1903.00768 |bibcode=2019PhRvA.100a2305A |s2cid=92987546 }}</ref> 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.<ref>{{cite journal |last1=Smolin |first1=John A. |last2=Smith |first2=Graeme |last3=Vargo |first3=Alexander |title=Oversimplifying quantum factoring |journal=Nature |date=July 2013 |volume=499 |issue=7457 |pages=163–165 |doi=10.1038/nature12290 |pmid=23846653 |arxiv=1301.7007 |bibcode=2013Natur.499..163S }}</ref> Furthermore, attempts using quantum computers with other algorithms have been made.<ref>{{cite journal |last1=Karamlou |first1=Amir H. |last2=Simon |first2=William A. |last3=Katabarwa |first3=Amara |last4=Scholten |first4=Travis L. |last5=Peropadre |first5=Borja |last6=Cao |first6=Yudong |title=Analyzing the performance of variational quantum factoring on a superconducting quantum processor |journal=npj Quantum Information |date=28 October 2021 |volume=7 |issue=1 |page=156 |doi=10.1038/s41534-021-00478-z |arxiv=2012.07825 |bibcode=2021npjQI...7..156K }}</ref> 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.<ref>{{Cite web |date=2019-12-28 |title=Quantum computing motte-and-baileys |url=https://scottaaronson.blog/?p=4447 |access-date=2021-11-15 |website=Shtetl-Optimized |language=en-US}}</ref>


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 {{OEIS el|A073024}}.<ref name="noise">{{cite journal |arxiv=2306.10072 |last1=Cai |first1=Jin-Yi |date=2024 |title=Shor's algorithm does not factor large integers in the presence of noise |journal=Science China Information Sciences |volume=67 |issue=7 |doi=10.1007/s11432-023-3961-3 }}</ref> These primes <math>p</math> have the property that <math>p-1</math> has a prime factor larger than <math>p^{2/3}</math>, 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.
In 2001, Shor's algorithm was demonstrated by a group at [[IBM]], who factored <math> 15 </math> into <math> 3 \times 5 </math>, using an [[Nuclear magnetic resonance quantum computer|NMR implementation]] of a quantum computer with seven qubits.<ref name = "VSBYSC01">{{cite journal |last1=Vandersypen |first1=Lieven M. K. |last2=Steffen |first2=Matthias |last3=Breyta |first3=Gregory |last4=Yannoni |first4=Costantino S. |last5=Sherwood |first5=Mark H. |last6=Chuang |first6=Isaac L. |title=Experimental realization of Shor's quantum factoring algorithm using nuclear magnetic resonance |journal=Nature |date=December 2001 |volume=414 |issue=6866 |pages=883–887 |doi=10.1038/414883a |pmid=11780055 |arxiv=quant-ph/0112176 |bibcode=2001Natur.414..883V }}</ref> After IBM's implementation, two independent groups implemented Shor's algorithm using [[Photonics|photonic]] qubits, emphasizing that multi-qubit [[quantum entanglement|entanglement]] was observed when running the Shor's algorithm circuits.<ref name = "LBYP07">{{cite journal |last1=Lu |first1=Chao-Yang |last2=Browne |first2=Daniel E. |last3=Yang |first3=Tao |last4=Pan |first4=Jian-Wei |title=Demonstration of a Compiled Version of Shor's Quantum Factoring Algorithm Using Photonic Qubits |journal=Physical Review Letters |date=19 December 2007 |volume=99 |issue=25 |article-number=250504 |doi=10.1103/PhysRevLett.99.250504 |pmid=18233508 |arxiv=0705.1684 |bibcode=2007PhRvL..99y0504L }}</ref><ref name = "LWLBJGW07">{{cite journal |last1=Lanyon |first1=B. P. |last2=Weinhold |first2=T. J. |last3=Langford |first3=N. K. |last4=Barbieri |first4=M. |last5=James |first5=D. F. V. |last6=Gilchrist |first6=A. |last7=White |first7=A. G. |title=Experimental Demonstration of a Compiled Version of Shor's Algorithm with Quantum Entanglement |journal=Physical Review Letters |date=19 December 2007 |volume=99 |issue=25 |article-number=250505 |doi=10.1103/PhysRevLett.99.250505 |pmid=18233509 |arxiv=0705.1398 |bibcode=2007PhRvL..99y0505L }}</ref> In 2012, the factorization of <math> 15 </math> was performed with solid-state qubits.<ref>{{Cite journal|last1 = Lucero|first1 = Erik|last2 = Barends|first2 = Rami|last3 = Chen|first3 = Yu|last4 = Kelly|first4 = Julian|last5 = Mariantoni|first5 = Matteo|last6 = Megrant|first6 = Anthony|last7 = O'Malley|first7 = Peter|last8 = Sank|first8 = Daniel|last9 = Vainsencher|first9 = Amit|last10 = Wenner|first10 = James|last11 = White|first11 = Ted|last12 = Yin|first12 = Yi|last13 = Cleland|first13 = Andrew N.|last14 = Martinis|first14 = John M.|title = Computing prime factors with a Josephson phase qubit quantum processor|journal = Nature Physics|volume = 8|issue = 10|page = 719|year = 2012|doi = 10.1038/nphys2385|bibcode = 2012NatPh...8..719L|arxiv = 1202.5707|s2cid = 44055700}}</ref> Later, in 2012, the factorization of <math> 21 </math> was achieved.<ref>{{cite journal|last1 = Martín-López|first1 = Enrique|last2 = Laing|first2 = Anthony|last3 = Lawson|first3 = Thomas|last4 = Alvarez|first4 = Roberto|last5 = Zhou|first5 = Xiao-Qi|last6 = O'Brien|first6 = Jeremy L.|title = Experimental realization of Shor's quantum factoring algorithm using qubit recycling|journal = Nature Photonics|volume =6|issue = 11|pages = 773–776|date = 12 October 2012|doi = 10.1038/nphoton.2012.259|arxiv = 1111.4147|bibcode = 2012NaPho...6..773M|s2cid = 46546101}}</ref> In 2016, the factorization of <math> 15 </math> was performed again using trapped-ion qubits.<ref>{{cite journal|last1 = Monz|first1 = Thomas |last2 = Nigg|first2 = Daniel|last3 = Martinez|first3 = Esteban A.|last4 = Brandl|first4 = Matthias F.|last5 = Schindler|first5 = Philipp|last6 = Rines|first6 = Richard|last7 = Wang|first7 = Shannon X.|last8 = Chuang|first8 = Isaac L.|last9 = Blatt|first9 = Rainer|title = Realization of a scalable Shor algorithm|journal = Science|volume =351|issue = 6277|pages = 1068–1070|date = 4 March 2016|doi = 10.1126/science.aad9480|pmid = 26941315 |arxiv = 1507.08852|bibcode = 2016Sci...351.1068M|s2cid = 17426142}}</ref> However, none of these demonstrations fulfill the requirements of Shor’s algorithm: they compile the circuit using prior knowledge of the solution, and some have even oversimplified the algorithm in a way that makes it equivalent to coin flipping.<ref>{{cite journal |last1=Smolin |first1=John A. |last2=Smith |first2=Graeme |last3=Vargo |first3=Alexander |title=Oversimplifying quantum factoring |journal=Nature |date=July 2013 |volume=499 |issue=7457 |pages=163–165 |doi=10.1038/nature12290 |pmid=23846653 |arxiv=1301.7007 |bibcode=2013Natur.499..163S }}</ref>


== Algorithm ==
== Algorithm ==
Line 47: Line 45:
To achieve this, Shor's algorithm consists of two parts:
To achieve this, Shor's algorithm consists of two parts:


# A classical reduction of the factoring problem to the problem of [[Order (group theory)|order]]-finding. This reduction is similar to that used for other [[integer factorization|factoring algorithms]], such as the [[quadratic sieve]].
# A classical reduction of the factoring problem to the problem of [[Multiplicative order|order]]-finding. This reduction is similar to that used for other [[integer factorization|factoring algorithms]], such as the [[quadratic sieve]].
# A quantum algorithm to solve the order-finding problem.
# A quantum algorithm to solve the order-finding problem.


Line 55: Line 53:
A basic observation is that, using [[Euclidean algorithm|Euclid's algorithm]], we can always compute the [[Greatest common divisor|GCD]] between two integers efficiently. In particular, this means we can check efficiently whether <math> N </math> is even, in which case 2 is trivially a factor. Let us thus assume that <math> N </math> is odd for the remainder of this discussion. Afterwards, we can use efficient classical algorithms to check whether <math> N </math> is a [[prime power]].<ref>{{cite journal |last1=Bernstein |first1=Daniel |title=Detecting perfect powers in essentially linear time |journal=Mathematics of Computation |date=1998 |volume=67 |issue=223 |pages=1253–1283 |doi=10.1090/S0025-5718-98-00952-1 }}</ref> For prime powers, efficient classical factorization algorithms exist,<ref>For example, computing the first <math>\log_2(N)</math> roots of <math>N</math>, e.g., with the [[Nth_root#Computing_principal_roots|Newton method]] and checking each integer result for primality ([[AKS primality test]]).</ref> hence the rest of the quantum algorithm may assume that <math> N </math> is not a prime power.
A basic observation is that, using [[Euclidean algorithm|Euclid's algorithm]], we can always compute the [[Greatest common divisor|GCD]] between two integers efficiently. In particular, this means we can check efficiently whether <math> N </math> is even, in which case 2 is trivially a factor. Let us thus assume that <math> N </math> is odd for the remainder of this discussion. Afterwards, we can use efficient classical algorithms to check whether <math> N </math> is a [[prime power]].<ref>{{cite journal |last1=Bernstein |first1=Daniel |title=Detecting perfect powers in essentially linear time |journal=Mathematics of Computation |date=1998 |volume=67 |issue=223 |pages=1253–1283 |doi=10.1090/S0025-5718-98-00952-1 }}</ref> For prime powers, efficient classical factorization algorithms exist,<ref>For example, computing the first <math>\log_2(N)</math> roots of <math>N</math>, e.g., with the [[Nth_root#Computing_principal_roots|Newton method]] and checking each integer result for primality ([[AKS primality test]]).</ref> hence the rest of the quantum algorithm may assume that <math> N </math> is not a prime power.


If those easy cases do not produce a nontrivial factor of <math> N </math>, the algorithm proceeds to handle the remaining case. We pick a random integer <math> 2 \leq a < N </math>. A possible nontrivial divisor of <math> N </math> can be found by computing <math> \gcd(a, N) </math>, which can be done classically and efficiently using the [[Euclidean algorithm]]. If this produces a nontrivial factor (meaning <math> \gcd(a, N) \ne 1 </math>), the algorithm is finished, and the other nontrivial factor is <math> N/\gcd(a, N) </math>. If a nontrivial factor was not identified, then this means that <math> N </math> and the choice of <math> a </math> are [[coprime]], so <math>a</math> is contained in the [[multiplicative group of integers modulo n|multiplicative group of integers modulo <math>N</math>]], having a [[multiplicative inverse]] modulo <math>N</math>. Thus, <math>a</math> has a [[multiplicative order]] <math> r </math> modulo <math>N</math>, meaning
If those easy cases do not produce a nontrivial factor of <math> N </math>, the algorithm proceeds to handle the remaining case. We pick a random integer <math> 2 \leq a < N{.} </math> A possible nontrivial divisor of <math> N </math> can be found by computing <math> \gcd(a, N) </math>, which can be done classically and efficiently using the [[Euclidean algorithm]]. If this produces a nontrivial factor (meaning <math> \gcd(a, N) \ne 1 </math>), the algorithm is finished, and the other nontrivial factor is <math> N/\gcd(a, N) </math>. If a nontrivial factor was not identified, then this means that <math> N </math> and the choice of <math> a </math> are [[coprime]], so <math>a</math> is contained in the [[multiplicative group of integers modulo n|multiplicative group of integers modulo <math>N</math>]], having a [[multiplicative inverse]] modulo <math>N</math>. Thus, <math>a</math> has a [[multiplicative order]] <math> r </math> modulo <math>N</math>, meaning
: <math>a^r \equiv 1 \bmod N,</math>
: <math>a^r \equiv 1 \bmod N,</math>
and <math>r</math> is the smallest positive integer satisfying this congruence.
and <math>r</math> is the smallest positive integer satisfying this congruence.


The quantum subroutine finds <math>r</math>. It can be seen from the congruence that <math> N </math> [[divides]] <math> a^r - 1 </math>, written <math> N \mid a^r - 1 </math>. This can be factored using [[difference of squares]]:
The quantum subroutine finds <math>r</math>. It can be seen from the congruence that <math> N </math> [[divides]] <math> a^r - 1 </math>, written <math> N \mid a^r - 1 </math>. This can be factored using [[difference of squares]]:<math display="block">
<math display="block">
  N \mid (a^{r/2} - 1)(a^{r/2} + 1).
  N \mid (a^{r/2} - 1)(a^{r/2} + 1).
</math>
</math>Since we have factored the expression in this way, the algorithm doesn't work for odd <math> r </math> (because <math> a^{r/2} </math> must be an integer), meaning that the algorithm would have to restart with a new <math> a </math>. Hereafter we can therefore assume that <math> r </math> is even. It cannot be the case that <math> N \mid a^{r/2} - 1 </math>, since this would imply <math>a^{r/2} \equiv 1 \bmod N</math>, which would contradictorily imply that <math> r/2 </math> would be the order of <math> a </math>, which was already <math> r </math>. At this point, it may or may not be the case that <math> N \mid a^{r/2} + 1 </math>. If <math>N</math> does not divide <math> a^{r/2} + 1 </math>, then this means that we are able to find a nontrivial factor of <math> N </math>. We compute<math display="block">
Since we have factored the expression in this way, the algorithm doesn't work for odd <math> r </math> (because <math> a^{r/2} </math> must be an integer), meaning that the algorithm would have to restart with a new <math> a </math>. Hereafter we can therefore assume that <math> r </math> is even. It cannot be the case that <math> N \mid a^{r/2} - 1 </math>, since this would imply <math>a^{r/2} \equiv 1 \bmod N</math>, which would contradictorily imply that <math> r/2 </math> would be the order of <math> a </math>, which was already <math> r </math>. At this point, it may or may not be the case that <math> N \mid a^{r/2} + 1 </math>. If <math>N</math> does not divide <math> a^{r/2} + 1 </math>, then this means that we are able to find a nontrivial factor of <math> N </math>. We compute
<math display="block">
  d = \gcd(N, a^{r/2} - 1).
  d = \gcd(N, a^{r/2} - 1).
</math>
</math>If <math> d = 1 </math>, then <math> N \mid a^{r/2} + 1 </math> was true, and a nontrivial factor of <math> N </math> cannot be achieved from <math> a </math>, and the algorithm must restart with a new <math> a </math>. Otherwise, we have found a nontrivial factor of <math> N </math>, with the other being <math> N/d </math>, and the algorithm is finished. For this step, it is also equivalent to compute <math> \gcd(N, a^{r/2} + 1) </math>; it will produce a nontrivial factor if <math> \gcd(N, a^{r/2} - 1) </math> is nontrivial, and will not if it's trivial (where <math> N \mid a^{r/2} + 1 </math>).
If <math> d = 1 </math>, then <math> N \mid a^{r/2} + 1 </math> was true, and a nontrivial factor of <math> N </math> cannot be achieved from <math> a </math>, and the algorithm must restart with a new <math> a </math>. Otherwise, we have found a nontrivial factor of <math> N </math>, with the other being <math> N/d </math>, and the algorithm is finished. For this step, it is also equivalent to compute <math> \gcd(N, a^{r/2} + 1) </math>; it will produce a nontrivial factor if <math> \gcd(N, a^{r/2} - 1) </math> is nontrivial, and will not if it's trivial (where <math> N \mid a^{r/2} + 1 </math>).


The algorithm restated shortly follows: let <math> N </math> be odd, and not a prime power. We want to output two nontrivial factors of <math> N </math>.
The algorithm restated shortly follows: let <math> N </math> be odd, and not a prime power. We want to output two nontrivial factors of <math> N </math>.
Line 77: Line 71:
# Compute <math>g = \gcd(N, a^{r/2} + 1)</math>. If <math>g </math> is nontrivial, the other factor is <math>N/g</math>, and we're done. Otherwise, go back to step 1.
# Compute <math>g = \gcd(N, a^{r/2} + 1)</math>. If <math>g </math> is nontrivial, the other factor is <math>N/g</math>, 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.<ref name="siam"/> In practice, a single call to the quantum order-finding subroutine is enough to completely factor <math>N</math> with very high probability of success if one uses a more advanced reduction.<ref name="Ekerå21">{{cite journal |last1=Ekerå |first1=Martin |title=On completely factoring any integer efficiently in a single run of an order-finding algorithm |journal=Quantum Information Processing |date=June 2021 |volume=20 |issue=6 |page=205 |doi=10.1007/s11128-021-03069-1 |arxiv=2007.10044 |bibcode=2021QuIP...20..205E |doi-access=free }}</ref>
It has been shown that this will be likely to succeed after a few runs.<ref name="siam"/> In practice, a single call to the quantum order-finding subroutine is enough to completely factor <math>N</math> with very high probability of success if one uses a more advanced reduction.<ref name="Ekerå21">{{cite journal |last1=Ekerå |first1=Martin |title=On completely factoring any integer efficiently in a single run of an order-finding algorithm |journal=Quantum Information Processing |date=June 2021 |volume=20 |issue=6 |article-number=205 |doi=10.1007/s11128-021-03069-1 |arxiv=2007.10044 |bibcode=2021QuIP...20..205E |doi-access=free }}</ref>


=== Quantum order-finding subroutine ===
=== Quantum order-finding subroutine ===
The goal of the quantum subroutine of Shor's algorithm is, given [[coprime integers]] <math> N </math> and <math> 1< a<N </math>, to find the [[Multiplicative order|order <math> r </math> of <math>a</math> modulo <math>N</math>]], which is the smallest positive integer such that <math>a^r \equiv 1 \pmod N</math>. To achieve this, Shor's algorithm uses a quantum circuit involving two registers. The second register uses <math> n </math> qubits, where <math> n </math> is the smallest integer such that <math> N\le 2^n </math>, i.e., <math> n = \left \lceil {\log_2N} \right \rceil </math>. The size of the first register determines how accurate of an approximation the circuit produces. It can be shown that using <math> 2n </math> qubits gives sufficient accuracy to find <math> r </math>. The exact quantum circuit depends on the parameters <math>a</math> and <math>N</math>, which define the problem. The following description of the algorithm uses [[bra–ket notation]] to denote quantum states, and <math>\otimes</math> to denote the [[tensor product]], rather than [[logical AND]].
The goal of the quantum subroutine of Shor's algorithm is, given [[coprime integers]] <math> N </math> and <math> 1< a<N </math>, to find the [[Multiplicative order|order]] <math> r </math> of <math>a</math> modulo <math>N</math>, the smallest positive integer <math> r </math> such that <math>a^r \equiv 1 \pmod N</math>. To achieve this, Shor's algorithm uses a quantum circuit involving two registers. The second register uses <math> n </math> qubits, where <math> n </math> is the smallest integer such that <math> N\le 2^n </math>, i.e., <math> n = \left \lceil {\log_2N} \right \rceil </math>. The size of the first register determines how accurate of an approximation the circuit produces. It can be shown that using <math> 2n </math> qubits gives sufficient accuracy to find <math> r </math>. The exact quantum circuit depends on the parameters <math>a</math> and <math>N</math>, which define the problem. The following description of the algorithm uses [[bra–ket notation]] to denote quantum states, and <math>\otimes</math> to denote the [[tensor product]].


The algorithm consists of two main steps:
The algorithm consists of two main steps:


# Use [[Quantum phase estimation algorithm|quantum phase estimation]] with unitary <math>U</math> representing the operation of multiplying by <math>a</math> (modulo <math>N</math>), and input state <math>|0\rangle^{\otimes 2 n}\otimes|1\rangle</math> (where the second register is <math>|1\rangle</math> made from <math>n</math> qubits). The eigenvalues of this <math>U</math> encode information about the period, and <math>|1\rangle</math> can be seen to be writable as a sum of its eigenvectors. Thanks to these properties, the quantum phase estimation stage gives as output a random integer of the form <math>\frac{j}{r} 2^{2n}</math> for random <math>j=0,1,...,r-1</math>.
# Use [[Quantum phase estimation algorithm|quantum phase estimation]] with [[unitary matrix]] <math>U</math> representing the operation of multiplying by <math>a</math> (modulo <math>N</math>), and input state <math>|0\rangle^{\otimes 2 n}\otimes|1\rangle</math> (where the second register is <math>|1\rangle</math> made from <math>n</math> qubits). The [[eigenvalue]]s of this <math>U</math> encode information about the period, and <math>|1\rangle</math> can be seen to be writable as a sum of its eigenvectors. Thanks to these properties, the quantum phase estimation stage gives as output a random integer of the form <math>\frac{j}{r} 2^{2n}</math> for random <math>j=0,1,...,r-1</math>.
# Use the [[simple continued fraction|continued fractions algorithm]] to extract the period <math>r</math> from the measurement outcomes obtained in the previous stage. This is a procedure to post-process (with a classical computer) the measurement data obtained from measuring the output quantum states, and retrieve the period.
# Use the [[simple continued fraction|continued fractions algorithm]] to extract the period <math>r</math> from the measurement outcomes obtained in the previous stage. This is a procedure to post-process (with a classical computer) the measurement data obtained from measuring the output quantum states, and retrieve the period.


The connection with quantum phase estimation was not discussed in the original formulation of Shor's algorithm,<ref name="siam" /> but was later proposed by Kitaev.<ref>{{cite arXiv |eprint=quant-ph/9511026 |last1=Kitaev |first1=A. Yu |date=1995 |title=Quantum measurements and the Abelian Stabilizer Problem }}</ref>
The connection with quantum phase estimation was not discussed in the original formulation of Shor's algorithm,<ref name="siam" /> but was later proposed by [[Alexei Kitaev]].<ref>{{cite arXiv |eprint=quant-ph/9511026 |last1=Kitaev |first1=A. Yu |date=1995 |title=Quantum measurements and the Abelian Stabilizer Problem }}</ref>


==== Quantum phase estimation ====
==== Quantum phase estimation ====
[[File:Shor's algorithm.svg|frame|Quantum subroutine in Shor's algorithm]]
[[File:Shor's algorithm.svg|frame|Quantum subroutine in Shor's algorithm]]
In general the [[quantum phase estimation algorithm]], for any unitary <math>U</math> and eigenstate <math>|\psi\rangle</math> such that <math>U|\psi\rangle=e^{2\pi i\theta} |\psi\rangle</math>, sends input states <math>|0\rangle|\psi\rangle</math> to output states close to <math>|\phi\rangle|\psi\rangle</math>, where <math>\phi</math> is a superposition of integers close to <math>2^{2n} \theta</math>. In other words, it sends each eigenstate <math>|\psi_j\rangle</math> of <math>U</math> to a state containing information close to the associated eigenvalue. For the purposes of quantum order-finding, we employ this strategy using the unitary defined by the action
In general the [[quantum phase estimation algorithm]], for any unitary <math>U</math> and eigenstate <math>|\psi\rangle</math> such that <math>U|\psi\rangle=e^{2\pi i\theta} |\psi\rangle</math>, sends input states <math>|0\rangle|\psi\rangle</math> to output states close to <math>|\phi\rangle|\psi\rangle</math>, where <math>\phi</math> is a superposition of integers close to <math>2^{2n} \theta</math>. In other words, it sends each eigenstate <math>|\psi_j\rangle</math> of <math>U</math> to a state containing information close to the associated eigenvalue. For the purposes of quantum order-finding, we employ this strategy using the unitary defined by the action<math display="block">
<math display="block">
  U|k\rangle = \begin{cases}
  U|k\rangle = \begin{cases}
   |ak \pmod N\rangle & 0 \le k < N, \\
   |ak \pmod N\rangle & 0 \le k < N, \\
   |k\rangle & N \le k < 2^n.
   |k\rangle & N \le k < 2^n.
\end{cases}</math>
\end{cases}</math>The action of <math>U</math> on states <math>|k\rangle</math> with <math> N \leq k < 2^n </math> is not crucial to the functioning of the algorithm, but needs to be included to ensure that the overall transformation is a well-defined quantum gate. Implementing the circuit for quantum phase estimation with <math>U</math> requires being able to efficiently implement the gates <math> U^{2^j} </math>. This can be accomplished via [[modular exponentiation]], which is the slowest part of the algorithm.
The action of <math>U</math> on states <math>|k\rangle</math> with <math> N \leq k < 2^n </math> is not crucial to the functioning of the algorithm, but needs to be included to ensure that the overall transformation is a well-defined quantum gate. Implementing the circuit for quantum phase estimation with <math>U</math> requires being able to efficiently implement the gates <math> U^{2^j} </math>. This can be accomplished via [[modular exponentiation]], which is the slowest part of the algorithm.


The gate thus defined satisfies <math>U^r = I</math>, which immediately implies that its eigenvalues are the <math>r</math>-th [[Root of unity|roots of unity]] <math>\omega_r^k = e^{2\pi ik/r}</math>. Furthermore, each eigenvalue <math>\omega_r^j</math> has an eigenvector of the form <math display="inline">|\psi_j\rangle=r^{-1/2}\sum_{k=0}^{r-1}\omega_r^{-kj}|a^k\rangle </math>, and these eigenvectors are such that
The gate thus defined satisfies <math>U^r = I</math>, which immediately implies that its eigenvalues are the <math>r</math>-th [[Root of unity|roots of unity]] <math>\omega_r^k = e^{2\pi ik/r}</math>. Furthermore, each eigenvalue <math>\omega_r^j</math> has an eigenvector of the form <math display="inline">|\psi_j\rangle=r^{-1/2}\sum_{k=0}^{r-1}\omega_r^{-kj}|a^k\rangle </math>, and these eigenvectors are such that<math display="block">\begin{align}
<math display="block">\begin{align}
  \frac{1}{\sqrt{r}} \sum_{j = 0}^{r - 1} |\psi_j\rangle &= \frac{1}{r} \sum_{j = 0}^{r - 1} \sum_{k = 0}^{r - 1} \omega_r^{jk}|a^k\rangle \\
  \frac{1}{\sqrt{r}} \sum_{j = 0}^{r - 1} |\psi_j\rangle &= \frac{1}{r} \sum_{j = 0}^{r - 1} \sum_{k = 0}^{r - 1} \omega_r^{jk}|a^k\rangle \\
  &= |1\rangle + \frac{1}{r} \sum_{k = 1}^{r - 1} \left(\sum_{j = 0}^{r - 1} \omega_r^{jk} \right) |a^k\rangle =|1\rangle,
  &= |1\rangle + \frac{1}{r} \sum_{k = 1}^{r - 1} \left(\sum_{j = 0}^{r - 1} \omega_r^{jk} \right) |a^k\rangle =|1\rangle,
Line 108: Line 99:
Using [[Quantum phase estimation algorithm|quantum phase estimation]] on an input state <math>|0\rangle^{\otimes 2 n}|\psi_j\rangle</math> would then return the integer <math>2^{2n} j/r</math> with high probability. More precisely, the quantum phase estimation circuit sends <math>|0\rangle^{\otimes 2 n}|\psi_j\rangle</math> to <math>|\phi_j\rangle|\psi_j\rangle</math> such that the resulting probability distribution <math>p_k \equiv|\langle k|\phi_j\rangle|^2</math> is peaked around <math>k=2^{2n} j/r</math>, with <math>p_{2^{2n}j/r} \ge 4/\pi^2 \approx 0.4053</math>. This probability can be made arbitrarily close to 1 using extra qubits.
Using [[Quantum phase estimation algorithm|quantum phase estimation]] on an input state <math>|0\rangle^{\otimes 2 n}|\psi_j\rangle</math> would then return the integer <math>2^{2n} j/r</math> with high probability. More precisely, the quantum phase estimation circuit sends <math>|0\rangle^{\otimes 2 n}|\psi_j\rangle</math> to <math>|\phi_j\rangle|\psi_j\rangle</math> such that the resulting probability distribution <math>p_k \equiv|\langle k|\phi_j\rangle|^2</math> is peaked around <math>k=2^{2n} j/r</math>, with <math>p_{2^{2n}j/r} \ge 4/\pi^2 \approx 0.4053</math>. This probability can be made arbitrarily close to 1 using extra qubits.


Applying the above reasoning to the input <math>|0\rangle^{\otimes 2 n}|1\rangle</math>, quantum phase estimation thus results in the evolution
Applying the above reasoning to the input <math>|0\rangle^{\otimes 2 n}|1\rangle</math>, quantum phase estimation thus results in the evolution<math display="block">
<math display="block">
  |0\rangle^{\otimes 2 n}|1\rangle =
  |0\rangle^{\otimes 2 n}|1\rangle =
   \frac{1}{\sqrt{r}} \sum_{j = 0}^{r - 1} |0\rangle^{\otimes 2 n} |\psi_j\rangle \to
   \frac{1}{\sqrt{r}} \sum_{j = 0}^{r - 1} |0\rangle^{\otimes 2 n} |\psi_j\rangle \to
   \frac{1}{\sqrt{r}} \sum_{j = 0}^{r - 1} |\phi_j\rangle|\psi_j\rangle.
   \frac{1}{\sqrt{r}} \sum_{j = 0}^{r - 1} |\phi_j\rangle|\psi_j\rangle.
</math>
</math>Measuring the first register, we now have a balanced probability <math>1/r</math> to find each <math>|\phi_j\rangle</math>, each one giving an integer approximation to <math>2^{2 n} j/r</math>, which can be divided by <math>2^{2n}</math> to get a decimal approximation for <math>j/r</math>.
Measuring the first register, we now have a balanced probability <math>1/r</math> to find each <math>|\phi_j\rangle</math>, each one giving an integer approximation to <math>2^{2 n} j/r</math>, which can be divided by <math>2^{2n}</math> to get a decimal approximation for <math>j/r</math>.


==== Continued-fraction algorithm to retrieve the period ====
==== Continued-fraction algorithm to retrieve the period ====
Then, we apply the [[continued fraction|continued-fraction]] algorithm to find integers <math>b</math> and <math>c</math>, where <math>b/c</math> gives the best fraction approximation for the approximation measured from the circuit, for <math>b, c < N</math> and [[Coprime integers|coprime]] <math>b</math> and <math>c</math>. The number of qubits in the first register, <math>2n</math>, which determines the accuracy of the approximation, guarantees that
Then, we apply the [[continued fraction|continued-fraction]] algorithm to find integers <math>b</math> and <math>c</math>, where <math>b/c</math> gives the best fraction approximation for the approximation measured from the circuit, for <math>b, c < N</math> and [[Coprime integers|coprime]] <math>b</math> and <math>c</math>. The number of qubits in the first register, <math>2n</math>, which determines the accuracy of the approximation, guarantees that<math display="block">
<math display="block">
  \frac{b}{c} = \frac{j}{r},
  \frac{b}{c} = \frac{j}{r},
</math>
</math>
given the best approximation from the superposition of <math>|\phi_j\rangle</math> was measured<ref name="siam"/> (which can be made arbitrarily likely by using extra bits and truncating the output). However, while <math>b</math> and <math>c</math> are coprime, it may be the case that <math>j</math> and <math>r</math> are not coprime. Because of that, <math>b</math> and <math>c</math> may have lost some factors that were in <math>j</math> and <math>r</math>. This can be remedied by rerunning the quantum order-finding subroutine an arbitrary number of times, to produce a list of fraction approximations
given the best approximation from the superposition of <math>|\phi_j\rangle</math> was measured<ref name="siam"/> (which can be made arbitrarily likely by using extra bits and truncating the output). However, while <math>b</math> and <math>c</math> are coprime, it may be the case that <math>j</math> and <math>r</math> are not coprime. Because of that, <math>b</math> and <math>c</math> may have lost some factors that were in <math>j</math> and <math>r</math>. This can be remedied by rerunning the quantum order-finding subroutine an arbitrary number of times, to produce a list of fraction approximations<math display="block">
<math display="block">
  \frac{b_1}{c_1}, \frac{b_2}{c_2}, \ldots, \frac{b_s}{c_s},
  \frac{b_1}{c_1}, \frac{b_2}{c_2}, \ldots, \frac{b_s}{c_s},
</math>
</math>where <math>s</math> is the number of times the subroutine was run. Each <math>c_k</math> will have different factors taken out of it because the circuit will (likely) have measured multiple different possible values of <math>j</math>. To recover the actual <math>r</math> value, we can take the [[least common multiple]] of each <math>c_k</math>:<math display="block">
where <math>s</math> is the number of times the subroutine was run. Each <math>c_k</math> will have different factors taken out of it because the circuit will (likely) have measured multiple different possible values of <math>j</math>. To recover the actual <math>r</math> value, we can take the [[least common multiple]] of each <math>c_k</math>:
<math display="block">
  \operatorname{lcm}(c_1, c_2, \ldots, c_s).
  \operatorname{lcm}(c_1, c_2, \ldots, c_s).
</math>
</math>The least common multiple will be the order <math>r</math> of the original integer <math>a</math> 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.<ref name="Ekerå24">{{cite journal |last1=Ekerå |first1=Martin |title=On the Success Probability of Quantum Order Finding |journal=ACM Transactions on Quantum Computing |date=May 2024 |volume=5 |issue=2 |pages=1–40 |doi=10.1145/3655026 |doi-access=free |arxiv=2201.07791 }}</ref>
The least common multiple will be the order <math>r</math> of the original integer <math>a</math> 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.<ref name="Ekerå24">{{cite journal |last1=Ekerå |first1=Martin |title=On the Success Probability of Quantum Order Finding |journal=ACM Transactions on Quantum Computing |date=May 2024 |volume=5 |issue=2 |pages=1–40 |doi=10.1145/3655026 |doi-access=free |arxiv=2201.07791 }}</ref>


==== Choosing the size of the first register ====
==== Choosing the size of the first register ====
Line 143: Line 127:


=== The bottleneck ===
=== 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 computing|reversible gates]], starting with [[Adder (electronics)#Ripple-carry adder|ripple-carry adders]]. Knowing the base and the modulus of exponentiation facilitates further optimizations.<ref>{{cite journal |first1=Igor L. |last1=Markov |first2=Mehdi |last2=Saeedi |title=Constant-Optimized Quantum Circuits for Modular Multiplication and Exponentiation |journal=Quantum Information and Computation |volume=12 |issue=5–6 |pages=361–394 |year=2012 |doi=10.26421/QIC12.5-6-1 |arxiv=1202.6614 |bibcode = 2012arXiv1202.6614M |s2cid=16595181 }}</ref><ref>{{cite journal |first1=Igor L. |last1=Markov |first2=Mehdi |last2=Saeedi |title=Faster Quantum Number Factoring via Circuit Synthesis |journal=Phys. Rev. A |volume=87 |issue= 1|pages=012310 |year=2013 |arxiv=1301.3210 |bibcode = 2013PhRvA..87a2310M |doi = 10.1103/PhysRevA.87.012310 |s2cid=2246117 }}</ref> Reversible circuits typically use on the order of <math>n^3</math> gates for <math>n</math> qubits. Alternative techniques asymptotically improve gate counts by using [[quantum Fourier transform]]s, but are not competitive with fewer than 600 qubits owing to high constants.
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 computing|reversible gates]], starting with [[Adder (electronics)#Ripple-carry adder|ripple-carry adders]]. Knowing the base and the modulus of exponentiation facilitates further optimizations.<ref>{{cite journal |first1=Igor L. |last1=Markov |first2=Mehdi |last2=Saeedi |title=Constant-Optimized Quantum Circuits for Modular Multiplication and Exponentiation |journal=Quantum Information and Computation |volume=12 |issue=5–6 |pages=361–394 |year=2012 |doi=10.26421/QIC12.5-6-1 |arxiv=1202.6614 |bibcode = 2012arXiv1202.6614M |s2cid=16595181 }}</ref><ref>{{cite journal |first1=Igor L. |last1=Markov |first2=Mehdi |last2=Saeedi |title=Faster Quantum Number Factoring via Circuit Synthesis |journal=Phys. Rev. A |volume=87 |issue= 1|article-number=012310 |year=2013 |arxiv=1301.3210 |bibcode = 2013PhRvA..87a2310M |doi = 10.1103/PhysRevA.87.012310 |s2cid=2246117 }}</ref> Reversible circuits typically use on the order of <math>n^3</math> gates for <math>n</math> qubits. Alternative techniques asymptotically improve gate counts by using [[quantum Fourier transform]]s, but are not competitive with fewer than 600 qubits owing to high constants.


== Period finding and discrete logarithms ==
== Period finding and discrete logarithms ==
Line 173: Line 157:
* {{cite book |last1=Nielsen |first1=Michael A. |last2=Chuang |first2=Isaac L. |title=Quantum Computation and Quantum Information: 10th Anniversary Edition |date=2010 |publisher=Cambridge University Press |isbn=978-1-107-00217-3 }}
* {{cite book |last1=Nielsen |first1=Michael A. |last2=Chuang |first2=Isaac L. |title=Quantum Computation and Quantum Information: 10th Anniversary Edition |date=2010 |publisher=Cambridge University Press |isbn=978-1-107-00217-3 }}
* {{cite book |doi=10.1093/oso/9780198570004.001.0001 |title=An Introduction to Quantum Computing |date=2006 |last1=Kaye |first1=Phillip |last2=Laflamme |first2=Raymond |last3=Mosca |first3=Michele |isbn=978-0-19-857000-4 }}
* {{cite book |doi=10.1093/oso/9780198570004.001.0001 |title=An Introduction to Quantum Computing |date=2006 |last1=Kaye |first1=Phillip |last2=Laflamme |first2=Raymond |last3=Mosca |first3=Michele |isbn=978-0-19-857000-4 }}
* [http://scottaaronson.com/blog/?p=208 "Explanation for the man in the street"] by [[Scott Aaronson]], "[http://scottaaronson.com/blog/?p=208#comment-9958 approved]" by Peter Shor. (Shor wrote "Great article, Scott! That’s the best job of explaining quantum computing to the man on the street that I’ve seen."). An alternate metaphor for the QFT was presented in [http://www.scottaaronson.com/blog/?p=208#comment-5187 one of the comments]. Scott Aaronson suggests the following 12 references as further reading (out of "the 10<sup>10<sup>5000</sup></sup> quantum algorithm tutorials that are already on the web."):
* [http://scottaaronson.com/blog/?p=208 "Explanation for the man in the street"] by [[Scott Aaronson]], "[http://scottaaronson.com/blog/?p=208#comment-9958 approved]" by Peter Shor. (Shor wrote "Great article, Scott! That's the best job of explaining quantum computing to the man on the street that I've seen."). An alternate metaphor for the QFT was presented in [http://www.scottaaronson.com/blog/?p=208#comment-5187 one of the comments]. Scott Aaronson suggests the following 12 references as further reading (out of "the 10<sup>10<sup>5000</sup></sup> quantum algorithm tutorials that are already on the web."):
* {{Citation |last=Shor |first=Peter W. |year=1997 |title=Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer |journal=SIAM J. Comput. |volume=26 |issue=5 |pages=1484–1509 |doi=10.1137/S0036144598347011 |arxiv=quant-ph/9508027v2|bibcode = 1999SIAMR..41..303S }}. Revised version of the original paper by Peter Shor ("28 pages, LaTeX. This is an expanded version of a paper that appeared in the Proceedings of the 35th Annual Symposium on Foundations of Computer Science, Santa Fe, NM, Nov. 20--22, 1994. Minor revisions made January, 1996").
* {{Citation |last=Shor |first=Peter W. |year=1997 |title=Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer |journal=SIAM J. Comput. |volume=26 |issue=5 |pages=1484–1509 |doi=10.1137/S0036144598347011 |arxiv=quant-ph/9508027v2|bibcode = 1999SIAMR..41..303S }}. Revised version of the original paper by Peter Shor ("28 pages, LaTeX. This is an expanded version of a paper that appeared in the Proceedings of the 35th Annual Symposium on Foundations of Computer Science, Santa Fe, New Mexico, November 20--22, 1994. Minor revisions made January, 1996").
* [https://quantum-algorithms.herokuapp.com/299/paper/index.html Quantum Computing and Shor's Algorithm], Matthew Hayward's [https://quantum-algorithms.herokuapp.com/ Quantum Algorithms Page], 2005-02-17, imsa.edu, LaTeX2HTML version of the original [https://quantum-algorithms.herokuapp.com/299/paper.tex LaTeX document], also available as [https://quantum-algorithms.herokuapp.com/299/paper.pdf PDF] or [https://quantum-algorithms.herokuapp.com/299/paper.ps postscript] document.
* [https://quantum-algorithms.herokuapp.com/299/paper/index.html Quantum Computing and Shor's Algorithm], Matthew Hayward's [https://quantum-algorithms.herokuapp.com/ Quantum Algorithms Page], 2005-02-17, imsa.edu, LaTeX2HTML version of the original [https://quantum-algorithms.herokuapp.com/299/paper.tex LaTeX document], also available as [https://quantum-algorithms.herokuapp.com/299/paper.pdf PDF] or [https://quantum-algorithms.herokuapp.com/299/paper.ps postscript] document.
* [http://homepages.cwi.nl/~rdewolf/publ/qc/survey.ps Quantum Computation and Shor's Factoring Algorithm], Ronald de Wolf, CWI and University of Amsterdam, January 12, 1999, 9 page postscript document.
* [http://homepages.cwi.nl/~rdewolf/publ/qc/survey.ps Quantum Computation and Shor's Factoring Algorithm], Ronald de Wolf, CWI and University of Amsterdam, January 12, 1999, 9 page postscript document.
Line 183: Line 167:
* [https://web.archive.org/web/20121115112940/http://people.ccmr.cornell.edu/~mermin/qcomp/chap3.pdf III. Breaking RSA Encryption with a Quantum Computer: Shor's Factoring Algorithm], Lecture notes on Quantum computation, Cornell University, Physics 481–681, CS 483; Spring, 2006 by N. David Mermin. Last revised 2006-03-28, 30 page PDF document.
* [https://web.archive.org/web/20121115112940/http://people.ccmr.cornell.edu/~mermin/qcomp/chap3.pdf III. Breaking RSA Encryption with a Quantum Computer: Shor's Factoring Algorithm], Lecture notes on Quantum computation, Cornell University, Physics 481–681, CS 483; Spring, 2006 by N. David Mermin. Last revised 2006-03-28, 30 page PDF document.
* {{Cite arXiv|eprint=quant-ph/0303175|last1= Lavor|first1= C.|title= Shor's Algorithm for Factoring Large Integers|last2=  Manssur|first2= L. R. U.|last3=  Portugal|first3= R.|year= 2003}}
* {{Cite arXiv|eprint=quant-ph/0303175|last1= Lavor|first1= C.|title= Shor's Algorithm for Factoring Large Integers|last2=  Manssur|first2= L. R. U.|last3=  Portugal|first3= R.|year= 2003}}
* {{Cite arXiv|eprint=quant-ph/0010034|last1=Lomonaco|first1=Jr|title=Shor's Quantum Factoring Algorithm|year=2000}} This paper is a written version of a one-hour lecture given on Peter Shor's quantum factoring algorithm. 22 pages.
* {{Cite arXiv|eprint=quant-ph/0010034|last1=Lomonaco|first1=Jr|title=Shor's Quantum Factoring Algorithm|year=2000 }} This paper is a written version of a one-hour lecture given on Peter Shor's quantum factoring algorithm. 22 pages.
* [http://www.cs.princeton.edu/theory/complexity/quantumchap.pdf Chapter 20 Quantum Computation], from ''Computational Complexity: A Modern Approach'', Draft of a book: Dated January 2007, Sanjeev Arora and Boaz Barak, Princeton University. Published as Chapter 10 Quantum Computation of Sanjeev Arora, Boaz Barak, "Computational Complexity: A Modern Approach", Cambridge University Press, 2009, {{isbn|978-0-521-42426-4}}
* [http://www.cs.princeton.edu/theory/complexity/quantumchap.pdf Chapter 20 Quantum Computation], from ''Computational Complexity: A Modern Approach'', Draft of a book: Dated January 2007, Sanjeev Arora and Boaz Barak, Princeton University. Published as Chapter 10 Quantum Computation of Sanjeev Arora, Boaz Barak, "Computational Complexity: A Modern Approach", Cambridge University Press, 2009, {{isbn|978-0-521-42426-4}}
* [http://blogs.discovermagazine.com/80beats/2011/01/19/a-step-towards-quantum-computing-entangling-10-billion-particles/ A Step Toward Quantum Computing: Entangling 10 Billion Particles] {{Webarchive|url=https://web.archive.org/web/20110120103006/http://blogs.discovermagazine.com/80beats/2011/01/19/a-step-towards-quantum-computing-entangling-10-billion-particles/ |date=2011-01-20 }}, from "Discover Magazine", Dated January 19, 2011.
* [http://blogs.discovermagazine.com/80beats/2011/01/19/a-step-towards-quantum-computing-entangling-10-billion-particles/ A Step Toward Quantum Computing: Entangling 10 Billion Particles]. {{Webarchive|url=https://web.archive.org/web/20110120103006/http://blogs.discovermagazine.com/80beats/2011/01/19/a-step-towards-quantum-computing-entangling-10-billion-particles/ |date=2011-01-20 }}, from "Discover Magazine", Dated January 19, 2011.
* [http://www.fi.muni.cz/usr/gruska/survey1.ps Josef Gruska - ''Quantum Computing Challenges''] also in [https://www.amazon.com/Mathematics-Unlimited-Bj%C3%B6rn-Engquist/dp/3540669132 Mathematics unlimited: 2001 and beyond], Editors Björn Engquist, Wilfried Schmid, Springer, 2001, {{isbn|978-3-540-66913-5}}
* [http://www.fi.muni.cz/usr/gruska/survey1.ps Josef Gruska - ''Quantum Computing Challenges''] also in [https://www.amazon.com/Mathematics-Unlimited-Bj%C3%B6rn-Engquist/dp/3540669132 Mathematics unlimited: 2001 and beyond], Editors Björn Engquist, Wilfried Schmid, Springer, 2001, {{isbn|978-3-540-66913-5}}


Line 201: Line 185:
[[Category:Integer factorization algorithms]]
[[Category:Integer factorization algorithms]]
[[Category:Post-quantum cryptography]]
[[Category:Post-quantum cryptography]]
[[Category:Eponymous algorithms]]

Latest revision as of 20:06, 16 December 2025

Template:Short descriptionShor'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.[1][2] 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.[3] However, beating classical computers will require quantum computers with millions of qubits due to the overhead caused by quantum error correction.[4]

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 logN.[5] It takes quantum gates of order O((logN)2(loglogN)(logloglogN)) using fast multiplication,[6] or even O((logN)2(loglogN)) using the asymptotically fastest multiplication algorithm currently known due to Harvey and van der Hoeven,[7] thus demonstrating that the integer factorization problem is in complexity class BQP. Shor's algorithm is asymptotically faster than the most scalable classical factoring algorithm, the general number field sieve, which works in sub-exponential time: O(e1.9(logN)1/3(loglogN)2/3).[8]

Feasibility and impact

File:Asymmetric encryption scheme.png
Diagram presenting the encryption and the decryption of a document using asymmetric cryptography. Some forms of encryption (including asymmetric cryptography) are at risk of being broken by future quantum computers.

Assuming 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 can be done with a polynomial complexity circuit on an ideal quantum computer. Thus, it might be feasible to defeat RSA by constructing a large enough quantum computer. This was 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 (PQC).

Physical implementation

As of 2025, the high error rates of quantum computers and limited number of physical qubits available for quantum error correction, laboratory demonstrations of Shor's algorithm obtain correct results in only in a fraction of attempts, and have only succeeded with small semiprimes.

In 2001, Shor's algorithm was demonstrated by a group at IBM, who factored 15 into 3×5, using an NMR implementation of a quantum computer with seven qubits.[10] 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.[11][12] In 2012, the factorization of 15 was performed with solid-state qubits.[13] Later, in 2012, the factorization of 21 was achieved.[14] In 2016, the factorization of 15 was performed again using trapped-ion qubits.[15] However, none of these demonstrations fulfill the requirements of Shor’s algorithm: they compile the circuit using prior knowledge of the solution, and some have even oversimplified the algorithm in a way that makes it equivalent to coin flipping.[16]

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:

  1. A classical reduction of the factoring problem to the problem of order-finding. This reduction is similar to that used for other factoring algorithms, such as the quadratic sieve.
  2. A quantum algorithm to solve the order-finding problem.

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 whether N is a prime power.[17] For prime powers, efficient classical factorization algorithms exist,[18] 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 2a<N. 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 gcd(a,N)1), the algorithm is finished, and the other nontrivial factor is N/gcd(a,N). If a nontrivial factor was not identified, then this 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

ar1modN,

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 ar1, written Nar1. This can be factored using difference of squares:N(ar/21)(ar/2+1).Since we have factored the expression in this way, the algorithm doesn't work for odd r (because ar/2 must be an integer), meaning that the algorithm would have to restart with a new a. Hereafter we can therefore assume that r is even. It cannot be the case that Nar/21, since this would imply ar/21modN, which would contradictorily imply that r/2 would be the order of a, which was already r. At this point, it may or may not be the case that Nar/2+1. If N does not divide ar/2+1, then this means that we are able to find a nontrivial factor of N. We computed=gcd(N,ar/21).If d=1, then Nar/2+1 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 N/d, and the algorithm is finished. For this step, it is also equivalent to compute gcd(N,ar/2+1); it will produce a nontrivial factor if gcd(N,ar/21) is nontrivial, and will not if it's trivial (where Nar/2+1).

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. Compute K=gcd(a,N), the greatest common divisor of a and N.
  3. If K1, then K is a nontrivial factor of N, with the other factor being N/K, and we are done.
  4. Otherwise, use the quantum subroutine to find the order r of a.
  5. If r is odd, then go back to step 1.
  6. Compute g=gcd(N,ar/2+1). If g is nontrivial, the other factor is 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.[2] 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.[19]

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, the smallest positive integer r such that ar1(modN). 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 N2n, i.e., n=log2N. 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 to denote the tensor product.

The algorithm consists of two main steps:

  1. Use quantum phase estimation with unitary matrix U representing the operation of multiplying by a (modulo N), and input state |02n|1 (where the second register is |1 made from n qubits). The eigenvalues of this U encode information about the period, and |1 can be seen to be writable as a sum of its eigenvectors. Thanks to these properties, the quantum phase estimation stage gives as output a random integer of the form jr22n for random j=0,1,...,r1.
  2. Use the continued fractions algorithm to extract the period r from the measurement outcomes obtained in the previous stage. This is a procedure to post-process (with a classical computer) the measurement data obtained from measuring the output quantum states, and retrieve the period.

The connection with quantum phase estimation was not discussed in the original formulation of Shor's algorithm,[2] but was later proposed by Alexei Kitaev.[20]

Quantum phase estimation

File:Shor's algorithm.svg
Quantum subroutine in Shor's algorithm

In general the quantum phase estimation algorithm, for any unitary U and eigenstate |ψ such that U|ψ=e2πiθ|ψ, sends input states |0|ψ to output states close to |ϕ|ψ, where ϕ is a superposition of integers close to 22nθ. In other words, it sends each eigenstate |ψj of U to a state containing information close to the associated eigenvalue. For the purposes of quantum order-finding, we employ this strategy using the unitary defined by the actionU|k={|ak(modN)0k<N,|kNk<2n.The action of U on states |k with Nk<2n is not crucial to the functioning of the algorithm, but needs to be included to ensure that 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 U2j. This can be accomplished via modular exponentiation, which is the slowest part of the algorithm.

The gate thus defined satisfies Ur=I, which immediately implies that its eigenvalues are the r-th roots of unity ωrk=e2πik/r. Furthermore, each eigenvalue ωrj has an eigenvector of the form |ψj=r1/2k=0r1ωrkj|ak, and these eigenvectors are such that1rj=0r1|ψj=1rj=0r1k=0r1ωrjk|ak=|1+1rk=1r1(j=0r1ωrjk)|ak=|1, where the last identity follows from the geometric series formula, which implies j=0r1ωrjk=0.

Using quantum phase estimation on an input state |02n|ψj would then return the integer 22nj/r with high probability. More precisely, the quantum phase estimation circuit sends |02n|ψj to |ϕj|ψj such that the resulting probability distribution pk|k|ϕj|2 is peaked around k=22nj/r, with p22nj/r4/π20.4053. This probability can be made arbitrarily close to 1 using extra qubits.

Applying the above reasoning to the input |02n|1, quantum phase estimation thus results in the evolution|02n|1=1rj=0r1|02n|ψj1rj=0r1|ϕj|ψj.Measuring the first register, we now have a balanced probability 1/r to find each |ϕj, each one giving an integer approximation to 22nj/r, which can be divided by 22n to get a decimal approximation for j/r.

Continued-fraction algorithm to retrieve the period

Then, we apply the continued-fraction algorithm to find integers b and c, where 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 thatbc=jr, given the best approximation from the superposition of |ϕj was measured[2] (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 approximationsb1c1,b2c2,,bscs,where s is the number of times the subroutine was run. Each ck 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 ck:lcm(c1,c2,,cs).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.[21]

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 where k/22n is the most accurate approximation of the phase from phase estimation) will allow the actual value of r to be recovered.

Each |ϕj before measurement in Shor's algorithm represents a superposition of integers approximating 22nj/r. Let |k represent the most optimal integer in |ϕj. The following theorem guarantees that the continued fractions algorithm will recover j/r from k/22n: Template:Math theorem [3] As k is the optimal bitstring from phase estimation, k/22n is accurate to j/r by 2n bits. Thus,|jrk22n|122n+112N212r2which 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.[22][23] Reversible circuits typically use on the order of n3 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.Script error: No such module "Unsubst". All three are instances of the hidden subgroup problem.

Shor's algorithm for discrete logarithms

Given a group G with order p and generator gG, suppose we know that x=grG, for some rp, and we wish to compute r, which is the discrete logarithm: r=logg(x). Consider the abelian group p×p, where each factor corresponds to modular addition of values. Now, consider the function

f:p×pG;f(a,b)=gaxb.

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.[3] 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.[3] To see this, consider the group of integers under addition, and for a given a such that: ar=1, the function

f:;f(x)=ax,f(x+r)=f(x).

For any finite abelian group G, a quantum algorithm exists for solving the hidden subgroup for G in polynomial time.[3]

See also

References

<templatestyles src="Reflist/styles.css" />

  1. Script error: No such module "citation/CS1".
  2. a b c d Script error: No such module "Citation/CS1".
  3. a b c d e Script error: No such module "citation/CS1".
  4. Script error: No such module "Citation/CS1".
  5. See also pseudo-polynomial time.
  6. Script error: No such module "Citation/CS1".
  7. Script error: No such module "Citation/CS1".
  8. Script error: No such module "citation/CS1".
  9. Script error: No such module "citation/CS1".
  10. Script error: No such module "Citation/CS1".
  11. Script error: No such module "Citation/CS1".
  12. Script error: No such module "Citation/CS1".
  13. Script error: No such module "Citation/CS1".
  14. Script error: No such module "Citation/CS1".
  15. Script error: No such module "Citation/CS1".
  16. Script error: No such module "Citation/CS1".
  17. Script error: No such module "Citation/CS1".
  18. For example, computing the first log2(N) roots of N, e.g., with the Newton method and checking each integer result for primality (AKS primality test).
  19. Script error: No such module "Citation/CS1".
  20. Script error: No such module "citation/CS1".
  21. Script error: No such module "Citation/CS1".
  22. Script error: No such module "Citation/CS1".
  23. Script error: No such module "Citation/CS1".
  24. Script error: No such module "citation/CS1".

Script error: No such module "Check for unknown parameters".

Further reading

External links

Template:Quantum computing

Script error: No such module "Navbox".