Skip to content
Quantum ComputingAN INTERACTIVE OPEN TEXTBOOK
charithj.com.au

Regev’s factoring algorithm

See how several modular directions and classical lattice processing can reduce the size of a factoring circuit per run.

Research18 min lessonDr. Charith Jayasekara↓ Chapter PDF
By the end, you’ll be able to
  • Trace a small modular relation into a lattice constraint.
  • Separate per-run circuit cost from repetition and classical work.
  • Distinguish the original heuristic from subsequent rigorous variants.

Before you begin: Shor’s algorithm, modular arithmetic, Fourier sampling and an introduction to lattices.

Shor’s factoring method finds repetition in modular powers. Regev’s approach uses several small bases simultaneously and looks for a multidimensional collection of relations. A lattice is an orderly set of integer combinations of basis vectors. Here its points describe exponent choices that make a modular product equal one.

The worked relation below uses ordinary multiplication and greatest common divisors. The full proof requires advanced number theory.

Let NN be an odd composite integer, after straightforward cases such as prime powers have been handled classically. Choose small integers b1,…,bdb_1,\ldots,b_d coprime to NN, and set ai=bi2a_i=b_i^2. Consider

f(z)=∏i=1daizi(modN).f(\mathbf z)=\prod_{i=1}^{d}a_i^{z_i}\pmod N.

Negative exponents mean modular inverses, which exist because the chosen bases are coprime to NN. The relation lattice is

L={z∈Zd:f(z)=1(modN)}.L=\{\mathbf z\in\mathbb Z^d:f(\mathbf z)=1\pmod N\}.

For a relation z\mathbf z, define u=∏ibizi(modN)u=\prod_i b_i^{z_i}\pmod N. Since the aia_i are squares, u2=1(modN)u^2=1\pmod N. If uu is a nontrivial square root of one, the classical calculation gcd⁡(u−1,N)\gcd(u-1,N) gives a nontrivial factor.

Checkpoint. Does every relation guarantee a factor? No. A relation producing u=1u=1 or u=−1(modN)u=-1\pmod N is unhelpful for this step. The post-processing must obtain a useful relation.

Use N=15N=15, b1=2b_1=2 and b2=7b_2=7. Both are coprime to 15, and

a1=4,a2=49≡4(mod15).a_1=4,\qquad a_2=49\equiv4\pmod{15}.

The vector (1,−1)(1,-1) is a relation because 4⋅4−1=1(mod15)4\cdot4^{-1}=1\pmod{15}. Since 7−1=13(mod15)7^{-1}=13\pmod{15}, its corresponding square root is

u=2⋅7−1≡2⋅13≡11(mod15).u=2\cdot7^{-1}\equiv2\cdot13\equiv11\pmod{15}.

Check 112=121≡1(mod15)11^2=121\equiv1\pmod{15}. Then

gcd⁡(11−1,15)=5,gcd⁡(11+1,15)=3.\gcd(11-1,15)=5,\qquad \gcd(11+1,15)=3.

This relation was chosen by inspection. The quantum and lattice algorithms obtain suitable information for large, unknown instances.

In this toy example, f(z1,z2)=4z1+z2(mod15)f(z_1,z_2)=4^{z_1+z_2}\pmod{15}, and 4 has order two. Therefore LL consists of integer points with z1+z2z_1+z_2 even. One basis is (1,1),(1,−1)(1,1),(1,-1). The relation lattice can be drawn as a checkerboard subset of the integer grid.

The algorithm prepares a smoothly weighted superposition over exponent vectors, coherently computes f(z)f(\mathbf z) into a value register, then Fourier transforms the exponent registers and measures them. Ignoring or measuring the value register groups exponents with the same modular product. Differences between such exponents lie in LL.

Fourier sampling gives approximate information about the dual lattice,

L∗={y∈Rd:y⋅z∈Z for every z∈L}.L^*=\{\mathbf y\in\mathbb R^d:\mathbf y\cdot\mathbf z\in\mathbb Z \text{ for every }\mathbf z\in L\}.

Several independent runs provide samples for classical lattice processing. The processing reconstructs enough relation information to attempt the square-root and gcd step. The measurement output is therefore an input to a classical algorithm, rather than a list of factors by itself.

Regev toy instance: modular relations form a latticeFor N fifteen and bases two and seven, both squared bases equal four modulo fifteen. Gaussian exponent registers each control modular multiplication by four, followed by Fourier transforms and measurement. A grid marks even-sum exponent points, with useful relation one minus one. Regev toy instance: modular relations form a lattice z₁ |0⟩ z₂ |0⟩ value |1⟩ G_R G_R M₄ M₄ QFT QFT Controls use least significant exponent bits in this toy instance. z₁ z₂ (1, −1) Blue points: z₁ + z₂ is even 4ᶻ¹ × 4ᶻ² = 1 mod 15 Relation (1, −1) gives u = 2 × 7⁻¹ = 11 gcd(11 − 1, 15) = 5 gcd(11 + 1, 15) = 3
A toy modular-multiplication circuit and the even-sum relation lattice, with factors recovered from a useful relation.

The toy circuit’s GRG_R operations prepare smoothly weighted exponent registers. Here each modular multiplier M4M_4 is controlled by the least significant exponent bit: higher bits contribute identity because 42=1(mod15)4^2=1\pmod{15}. The four-qubit multiplier fixes the unused basis state 15, completing a reversible permutation. The grid marks the relation lattice in blue and the useful vector (1,−1)(1,-1) in teal.

Regev’s original 2023 result uses O~(n3/2)\widetilde O(n^{3/2}) gates per quantum run for an nn-bit input, with O(n)O(\sqrt n) independent runs and polynomial classical processing. The tilde suppresses logarithmic factors. Multiplying the per-run cost by the number of runs gives a different total-work quantity. Reducing the size or depth of an individual coherent circuit can still be valuable when hardware reliability constrains each run.

The original analysis used a number-theoretic heuristic. Subsequent space-efficient work reduces the required qubit count, and Pilatte establishes unconditional correctness for slightly modified variants, preserving the improvement up to logarithmic factors. These are mathematical algorithm results. A practical RSA resource comparison additionally needs concrete arithmetic, error correction, connectivity, runtime and success targets.

Draw the toy lattice and test its basis vectors freely. For (1,1)(1,1), compute u=14≡−1(mod15)u=14\equiv-1\pmod{15}: this relation is unhelpful. For (1,−1)(1,-1), recover the useful value 11. The contrast shows why finding a relation and finding a factor are separate tasks.

  1. Is (2,0)(2,0) a relation, and is it useful?

  2. What should a resource table separate?

Worked answers
  1. yes: 42=1(mod15)4^2=1\pmod{15}. It gives u=22=4u=2^2=4, so gcd⁡(3,15)=3\gcd(3,15)=3.

  2. qubits, gates/depth per run, run count, classical work and physical implementation assumptions.

PAUSE & THINK

What does the headline gate improvement describe?

Choose your answer

Regev’s approach replaces one-dimensional period finding with multidimensional relation finding. The useful output emerges from quantum samples, classical geometry and modular arithmetic working together.

Regev, original algorithm; Ragavan and Vaikuntanathan, space-efficient variant; Pilatte, unconditional variants, revised August 2026. The N=15N=15 relation, grid and circuit figure above are original instructional calculations.

ONE IDEA FURTHER

Ready for the next step?

Your progress stays in this browser.

View progress & resume a chapter →