Papers
Topics
Authors
Recent
Search
2000 character limit reached

Shor's Quantum Factoring Algorithm

Updated 4 July 2026
  • Shor's Factoring Algorithm is a quantum approach that converts integer factorization into an order-finding problem using phase estimation.
  • It employs modular exponentiation and the quantum Fourier transform to estimate eigenphases, allowing extraction of nontrivial factors via classical gcd methods.
  • Practical implementations focus on optimizing arithmetic circuits, error control, and compilation strategies to overcome resource-intensive quantum operations.

Shor’s factoring algorithm is a quantum algorithm for integer factorization that reduces the factorization of an odd composite integer NN to the problem of finding the multiplicative order of a base aa modulo NN. In its standard form, the quantum subroutine estimates a phase s/rs/r associated with a modular exponentiation operator, while classical post-processing uses continued fractions and greatest-common-divisor computations to recover nontrivial factors. Its significance in cryptography is that RSA and related public-key constructions rely on the hardness of factoring large semiprimes, whereas Shor’s algorithm gives a polynomial-time quantum procedure for the relevant order-finding problem (Smolin et al., 2013, Grosshans et al., 2015, Jr, 2023).

1. Reduction from factoring to order finding

The classical reduction begins by choosing an integer aa such that

1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.

If gcd(a,N)1\gcd(a,N)\neq 1, a nontrivial factor has already been found. Otherwise one defines the order

r=ordN(a),r=\operatorname{ord}_N(a),

the smallest positive integer such that

ar1(modN).a^r \equiv 1 \pmod N.

This order is the central quantity sought by the quantum subroutine (Smolin et al., 2013, Grosshans et al., 2015).

Once an order rr is available, the standard factor-extraction criterion is equally classical. If aa0 is even and

aa1

then

aa2

and nontrivial factors are obtained from

aa3

The classical post-processing can fail if aa4 is odd, if aa5, or if the quantum routine returns only a divisor-related value rather than the exact order. One formulation used in the literature is that quantum order finding effectively produces

aa6

for a uniformly random aa7, so the returned denominator need not be the full order even when the phase estimate itself is correct (Grosshans et al., 2015).

This reduction explains both the power and the fragility of the algorithm. Factoring is not attacked directly; instead, success depends on an order-finding instance, the arithmetic structure of aa8, and the subsequent gcd test. A practical implication, explicitly emphasized in later refinements, is that quantum and classical parts of the algorithm should be analyzed together rather than as isolated stages (Grosshans et al., 2015).

2. Quantum period finding and phase estimation

The standard two-register form prepares a uniform superposition in a control register and computes modular exponentiation into a work register. A typical presentation chooses aa9 with

NN0

prepares

NN1

and applies

NN2

Applying the inverse quantum Fourier transform to the control register then yields measurement outcomes NN3 such that NN4 is close to NN5 for some integer NN6, after which continued fractions can recover NN7 with good probability (Smolin et al., 2013, Jr, 2023).

The operator-theoretic form makes the same structure explicit. Define

NN8

For order NN9, the relevant eigenstates may be written

s/rs/r0

with eigenvalues

s/rs/r1

Preparing s/rs/r2 in the work register automatically produces a uniform superposition of these eigenstates, so the algorithm can be viewed as quantum phase estimation on s/rs/r3 without first knowing which eigenstate is present (Jr, 2023).

A widely used resource reduction replaces the s/rs/r4-qubit control register by a single recycled qubit measured s/rs/r5 times, using the semiclassical inverse QFT. In this iterative form, previously measured bits determine whether a phase gate is applied before the next Hadamard, so the total number of qubits drops from approximately s/rs/r6 to s/rs/r7, at the cost of polynomial time overhead (Martin-Lopez et al., 2011).

The input to the Fourier stage is not arbitrary. The preprocessing stage produces periodic states of the form

s/rs/r8

and the QFT approximately maps such a state to a reciprocal-period state with the shift removed. An entanglement analysis based on the Groverian measure found that these periodic states already carry most of the multipartite entanglement generated during preprocessing, and that the QFT often changes that entanglement only slightly (Most et al., 2010).

3. Modular exponentiation, arithmetic cost, and architectural realizations

In asymptotic and practical analyses alike, modular exponentiation is the dominant cost center. One explicit comparison states that the hard part is

s/rs/r9

which can be done in time aa0, whereas the QFT costs only aa1 (Smolin et al., 2013). Pedagogical treatments of the modular exponentiation operator similarly identify it as the place where most of the quantum resources are deployed, and they emphasize that the relevant dynamics often live in an aa2-dimensional invariant subspace of the full work-register Hilbert space (Jr, 2023).

Concrete compiled studies make the bottleneck especially visible. For the aa3 IBM implementation based on compiled phase estimation, a full uncompiled realization was estimated to require about aa4 elementary gates on aa5 qubits, far beyond the target device. The compiled circuit therefore reduced the work register to the orbit aa6, encoded those three values into two qubits, and used approximate Toffoli gates with residual phase shifts that preserved functional correctness on the reachable subspace (Skosana et al., 2021).

Architectural analyses show that the cost profile depends strongly on encoding and fault-tolerant model. In ternary and metaplectic settings, one may either translate the arithmetic into true ternary form or emulate standard binary arithmetic inside qutrits. The detailed comparison concludes that denser ternary encoding does not automatically make Shor cheaper: binary emulation is often better for low-width ripple-carry implementations, whereas true ternary gains a width advantage in reduced-depth carry-lookahead designs. In the metaplectic topological model, non-Clifford resource preparation is asymptotically lower than in the generic ternary magic-state model (Bocharov et al., 2016).

A recurrent implementation lesson is that arithmetic design, ancilla management, and controllization dominate the practical cost of Shor’s algorithm far more than the abstract statement “apply a QFT” would suggest. This is why many proof-of-principle demonstrations simplify or compile modular exponentiation first, and why comparisons across experiments are meaningful only when the arithmetic assumptions are made explicit (Smolin et al., 2013, Skosana et al., 2021).

4. Variants, special cases, and refined post-processing

Several works modify the standard workflow without changing the factoring-to-order-finding reduction itself. One notable result concerns safe semiprimes,

aa7

for which the multiplicative structure is so constrained that a single call to quantum order finding almost always suffices when the fixed base aa8 is used. In that setting, the order of aa9 modulo 1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.0 is either 1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.1 or 1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.2, and the classical post-processing can recover the factors with probability

1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.3

substantially improving over the standard procedure on that restricted input family (Grosshans et al., 2015).

Another refinement revisits a standard failure mode: odd orders. The usual presentation discards odd 1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.4, but this is not always necessary when the chosen base is a perfect square. For 1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.5 and 1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.6, for example, the order is 1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.7, yet

1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.8

is an integer, and

1<a<N,gcd(a,N)=1.1<a<N,\qquad \gcd(a,N)=1.9

still yields the factors. A systematic analysis shows that odd orders can sometimes be salvaged in this way, or by collapsing a failed square base to a lower root, although the overall efficiency gain is small and asymptotically equivalent to simply avoiding square coprimes (Lawson, 2014).

Resource distribution has also been studied directly. A distributed version of Shor’s order-finding algorithm splits the estimation of gcd(a,N)1\gcd(a,N)\neq 10 across two quantum computers: one estimates leading bits, the other later bits of the same phase. To ensure that both estimates refer to the same eigencomponent gcd(a,N)1\gcd(a,N)\neq 11, the gcd(a,N)1\gcd(a,N)\neq 12-qubit work register is teleported from the first computer to the second. In the comparison model adopted there, the scheme reduces the maximum qubit count per computer by nearly gcd(a,N)1\gcd(a,N)\neq 13 and reduces the circuit depth of each computer, while introducing gcd(a,N)1\gcd(a,N)\neq 14 EPR pairs and gcd(a,N)1\gcd(a,N)\neq 15 classical communication bits (Xiao et al., 2022).

These variants do not alter the core mathematics of Shor’s algorithm. Rather, they show that the boundary between “quantum part” and “classical part” is adjustable: classical number theory, special input structure, and architecture-aware decomposition can materially change the effective quantum cost without changing the underlying reduction to order finding (Grosshans et al., 2015, Xiao et al., 2022).

5. Experimental demonstrations and the problem of compilation

Experimental work has concentrated on highly compiled instances. A photonic realization with qubit recycling implemented a compiled two-photon algorithm for gcd(a,N)1\gcd(a,N)\neq 16, encoding the work register in higher-dimensional states and producing an output distribution distinguishable from noise (Martin-Lopez et al., 2011). On IBM superconducting processors, a compiled phase-estimation circuit for gcd(a,N)1\gcd(a,N)\neq 17 used only gcd(a,N)1\gcd(a,N)\neq 18 qubits, approximate relative-phase Toffoli gates, and enough phase precision to complete the classical post-processing and recover the factors gcd(a,N)1\gcd(a,N)\neq 19 and r=ordN(a),r=\operatorname{ord}_N(a),0 (Skosana et al., 2021). Another IBM study used the semi-classical QFT on r=ordN(a),r=\operatorname{ord}_N(a),1, r=ordN(a),r=\operatorname{ord}_N(a),2, and r=ordN(a),r=\operatorname{ord}_N(a),3, with square statistical overlap as a way to assign periods directly from the experimentally measured phase distributions (Amico et al., 2019).

Hardware-specific compiled proposals extend beyond superconducting qubits. A semiconductor nanostructure implementation based on SAW-driven electrons in coupled quantum wires numerically studied compiled factoring of r=ordN(a),r=\operatorname{ord}_N(a),4, obtaining fidelity r=ordN(a),r=\operatorname{ord}_N(a),5 for r=ordN(a),r=\operatorname{ord}_N(a),6 and r=ordN(a),r=\operatorname{ord}_N(a),7 for r=ordN(a),r=\operatorname{ord}_N(a),8, with near-maximal argument-register linear entropy in both cases (Buscemi, 2010). A separate room-temperature pass-transistor logic realization reproduced the circuit structure of factoring r=ordN(a),r=\operatorname{ord}_N(a),9 in a classical emulation framework, precisely to probe which observed features of small Shor demonstrations are genuinely quantum (Johansson et al., 2017).

The status of such demonstrations has been a persistent source of controversy. Smolin, Smith, and Vargo argued that if one allows sufficiently aggressive compilation, then for any semiprime ar1(modN).a^r \equiv 1 \pmod N.0 with distinct odd primes one can choose a base ar1(modN).a^r \equiv 1 \pmod N.1 with order ar1(modN).a^r \equiv 1 \pmod N.2, so that the quantum part collapses to a two-qubit constant-depth circuit and, in the most degenerate case, even to sampling a fair coin. Their point is not that general factoring is easy, but that the correct measure of difficulty is not the size of the number factored; it is the complexity of the period-finding instance, especially the length of the period found (Smolin et al., 2013).

This benchmark criterion has shaped how later experiments are interpreted. Factoring ar1(modN).a^r \equiv 1 \pmod N.3 is no longer taken as strong evidence of scalable progress, because all relevant orders are powers of two and the arithmetic can be reduced drastically. Demonstrations that target non-power-of-two orders, such as ar1(modN).a^r \equiv 1 \pmod N.4 with order ar1(modN).a^r \equiv 1 \pmod N.5, are treated as more informative precisely because they test genuine interference structure rather than only compiled permutation gadgets (Martin-Lopez et al., 2011, Amico et al., 2019).

6. Noise, simulation, and interpretive debates

Noise sensitivity has been studied rigorously at the level of the QFT. Under a random noise model for controlled rotation gates,

ar1(modN).a^r \equiv 1 \pmod N.6

one asymptotic failure theorem shows that if

ar1(modN).a^r \equiv 1 \pmod N.7

then Shor’s algorithm does not factor ar1(modN).a^r \equiv 1 \pmod N.8-bit semiprimes from a positive-density set, and similarly fails for random prime pairs with probability ar1(modN).a^r \equiv 1 \pmod N.9. In that model, random phase errors wash out the Fourier peaks needed for period recovery (Cai, 2023).

At the same time, large-scale classical simulation has painted a more optimistic picture of the algorithm itself. A GPU-based study of more than rr0 factoring scenarios, using the iterative version of Shor’s circuit, found average success probabilities above rr1, even though conservative textbook bounds suggest only rr2–rr3. The discrepancy was traced to a high frequency of “lucky” cases, in which factorization succeeds despite unmet sufficient conditions. The same study reported that Ekerå-style post-processing can drive the success probability arbitrarily close to one with only a single run of the quantum subroutine, and it factored the semiprime

rr4

without exploiting prior knowledge of the solution (Willsch et al., 2023).

The quantum resources responsible for Shor’s advantage remain a separate line of analysis. One resource-theoretic study of a sequential realization of Shor’s order finding concluded that, within that fixed protocol structure, coherence is the quantum resource that bounds the success probability from below and above through measures of coherence creation and coherence detection. In that formulation, the relevant lower bound takes the form

rr5

linking algorithmic performance directly to rigorously defined dynamical coherence measures (Ahnefeld et al., 2022). Complementary entanglement analyses of periodic states reached the more specific conclusion that the preprocessing stage already generates most of the multipartite entanglement later present in the algorithm, while the QFT mainly reorganizes amplitudes so that the period becomes measurable (Most et al., 2010).

Debate has also touched the interpretation of multi-register correlations and the certification of quantum computers. A critique based on duplicating output registers argued that if the standard probability expression is treated as a joint probability, then extending the circuit to several identical target registers creates a tension with the usual counting argument for success probability. In the supplied analysis, that objection is characterized as interpretive rather than a formal refutation, but it reflects a broader concern: certifying a Shor implementation requires more than reproducing the output of tiny compiled instances; it requires demonstrating the nontrivial coherent modular arithmetic and register correlations on which the polynomial-time complexity claim depends (Cao et al., 2014).

In contemporary understanding, Shor’s factoring algorithm is therefore both mathematically settled and implementation-sensitive. Its reduction from factoring to order finding is exact, its asymptotic quantum advantage is well defined, and its practical difficulty is governed by modular arithmetic, coherent phase estimation, error control, and the extent to which a given demonstration avoids compilation that already encodes the answer (Smolin et al., 2013, Willsch et al., 2023).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Shor's Factoring Algorithm.