Order Finding and Period Finding
Order finding is the beating heart of quantum computing's most famous result — Shor's polynomial-time factoring algorithm — and yet the problem it solves is pure number theory with no quantum mechanics in sight. Fix a modulus and a base coprime to it. The powers march around a finite cycle and eventually return to ; the length of that cycle is the multiplicative order , the smallest with . Computing classically is, as far as anyone knows, as hard as factoring itself. The quantum algorithm cracks it by a change of viewpoint: it treats "multiply by " as a unitary operator, notices that the period is written into that operator's eigenvalues , and reads those eigenvalues off with quantum phase estimation and the quantum Fourier transform. The mechanism is disarmingly clean. Multiplication by modulo permutes the basis states , so it is unitary; its eigenvectors are Fourier modes over the orbit of , with eigenphases exactly the multiples . We never build those eigenvectors — we cannot, since that would require knowing . Instead we feed in the humble state , an equal superposition of all of them, and let phase estimation collapse it onto one random . A single run hands us a rational whose hidden denominator is ; the ancient theory of continued fractions then sifts that denominator out exactly, provided the register carried more than qubits of precision. Order finding sits at the head of a family tree — general period finding, Simon's problem, the discrete logarithm, and the whole abelian hidden subgroup problem are the same circuit template with the Fourier transform taken over a different group. Master this node and the rest of the tree unlocks.
- Order finding asks: given coprime integers and , find the least with ; period finding is the same question for any with .
- The modular-multiplication unitary has eigenvalues , so the period lives in its phase spectrum.
- Phase estimation seeded with samples a uniformly random multiple ; continued fractions convert the measured into the exact denominator once .
- One run returns the full order when , which happens with probability — a handful of repetitions makes success a near certainty.
- The whole routine runs in time, an exponential speedup over the best known classical factoring, and needs no black-box oracle: is a real reversible arithmetic circuit.
- Key idea: The multiplicative order is hidden in the eigenphases of the modular-multiplication unitary , whose eigenvalues are . Phase estimation seeded with samples a uniformly random , and continued fractions reconstruct exactly once the precision exceeds .
Where this lives today
Order finding is no longer just a theorem — it is the reference target the whole field aims at, and the reason a global cryptographic migration is underway. Small instances are the standard end-to-end benchmark: the 2001 IBM–Stanford NMR experiment factored 15, and later photonic and superconducting devices repeated 15 and 21, each stressing the full stack — reversible modular arithmetic, the inverse QFT, and classical post-processing — rather than isolated gates, and the community now insists on circuits that do not secretly compile in the answer . The sobering numbers are for cryptographically relevant : factoring a 2048-bit RSA modulus is estimated to need on the order of twenty million noisy physical qubits running for hours under surface-code error correction, which motivates work on qubit-efficient modular exponentiation. Meanwhile the abstract structure keeps paying dividends: the discrete-logarithm variant threatens elliptic-curve cryptography, and the recognition that all of these are abelian hidden-subgroup problems drives the hunt for a non-abelian generalization — so far unsuccessful, which is exactly why post-quantum cryptography bets on those harder groups.
The physical picture
Picture the sequence as the hand of a clock that ticks forward one notch each time you multiply by and snaps back to every ticks. The whole algorithm measures the spacing of that clock without walking around it tick by tick — because can be of order itself, counting is hopeless. The first figure fixes the object: a small orbit whose length is exactly the number we want.
The Fourier transform sees periodicity the way a prism sees a pure colour: a signal of period concentrates all of its weight at frequencies that are multiples of . So if we load the orbit into a register and Fourier-transform it, the answer shows up as a comb of sharp peaks whose spacing encodes — exactly what phase estimation on arranges. The slick part is that we never prepare an eigenvector by hand: the state is already the equal superposition of every eigenvector of , so phase estimation acting linearly collapses onto one random eigenphase for free. The second figure shows what the measurement register looks like: a picket fence of peaks at the integers nearest .
Why ? Because two distinct candidate fractions with denominators below can be as close as ; if the measurement lands within of the true , no impostor can sit closer, and continued fractions must return the right one. The precision has to beat the minimum gap between periods. One last subtlety separates order finding over from Simon's problem over : in general does not divide , so the Fourier peaks are slightly smeared and we get an approximation , not an exact equation. Continued fractions are precisely the tool for de-noising an approximate rational back to an exact one.
The core equations
The problem lives in the multiplicative group : the order of an element is the smallest exponent that brings it home to the identity.
where: — the modulus, an integer to be factored or analyzed; — a base coprime to , an element of ; — the multiplicative order of . Coprimality makes invertible mod , so a finite order exists and divides by Lagrange's theorem. The quantum leverage comes from promoting "multiply by " to an operator on qubits. Because is invertible, this map permutes basis states, and every permutation matrix is unitary.
where: — the unitary permuting basis states by multiplication by mod ; — a basis state encoding the integer . Applying times returns every state to itself, so and all eigenvalues are -th roots of unity: the classical period becomes the operator's order. The eigenvectors are the discrete Fourier modes over a single orbit of , each packaging the whole cycle with an -th-root-of-unity twist; the eigenphase is the multiple we are hunting.
where: — the -th eigenvector, a Fourier mode over the orbit of ; — the eigenphase label, ; — the eigenvalue whose phase is a multiple of . Learn the eigenphase, learn a multiple of the reciprocal period. We cannot prepare — it is built from powers of up to , and is unknown. The escape hatch is that summing all the eigenvectors reconstitutes a state we can trivially prepare, the integer .
where: — the basis state encoding the integer , the seed fed into phase estimation. Feeding in is thus identical to feeding in a uniformly random eigenvector: linearity averages, and we harvest a random at no cost. Phase estimation with a -qubit register outputs an integer pinning the eigenphase to within one part in ; its nearest-integer bound is a textbook constant.
where: — the integer read from the -qubit phase register; — the register dimension, i.e. the precision; — the guaranteed lower bound on landing on the nearest integer to . Taking makes continued fractions unable to fail. The classical post-processing is a theorem from Diophantine approximation: a rational close enough to a small-denominator target must appear among that target's continued-fraction convergents.
where: — the measured rational; in lowest terms — the target; — the recovered denominator, equal to when . The Euclidean algorithm generates every convergent cheaply. Whether a run returns the full order or a divisor is decided by one coprimality event, with probability Euler's totient ratio.
where: — Euler's totient, the count of integers in coprime to ; — a positive absolute constant. The bound decays so slowly that repetitions suffice for constant success. Assembling the pieces gives the runtime that made the algorithm famous: polynomial in the digits of , where every classical method is superpolynomial.
where: — the quantum cost, dominated by modular exponentiation with fast (Schönhage–Strassen) multiplication; — including continued-fraction post-processing. With schoolbook arithmetic the quantum cost is a plain .
Go deeper · Derivation B · 2 minTracing the order-finding circuit from input to measurement
The goal here is to follow the actual quantum circuit register by register and watch the period surface as a measurable integer. We run phase estimation on with the seed : superpose over exponents, apply controlled modular exponentiation to correlate each exponent with a power of , decompose the target in the eigenbasis so each eigenphase tags its own phase ramp, invert the Fourier transform to turn each ramp into a spike, and measure. The endpoint is a random integer within of — one noisy sample of a multiple of .
Step 1. Initialize with control qubits and a target holding the integer . Why: the control register will hold the exponent ; seeding the target with invokes the seed identity so we never need an eigenvector.
Step 2. Hadamard the controls to build a uniform superposition over all exponents:
Why: superposing every exponent at once is the quantum parallelism that lets a single circuit probe the entire sequence .
Step 3. Apply controlled modular exponentiation, conditioned on , giving . Why: this is the only oracle-like step, and it is a genuine circuit — repeated squaring turns into controlled multiplications, no exponential blowup.
Step 4. Rewrite the target in the eigenbasis using and :
Why: each eigenvalue branch now carries a pure phase ramp in the control register — a signal of frequency that the Fourier transform is built to detect.
Step 5. Apply the inverse QFT to the controls, mapping each ramp to a state sharply peaked at the nearest integer to :
Why: the inverse QFT converts "a phase winding at rate " into "a spike at position ".
Step 6. Measure the control register: the outcome is for a uniformly random , the nearest integer with probability . Why: the entangled target picks one branch at random, and the peaked register reads out its eigenphase — one clean sample of a multiple of . *Verified: reduces to standard QFT phase estimation (Nielsen & Chuang §5.2–5.3). For the peaks fall exactly on with ; for the peak lands at — both confirmed numerically.*
Go deeper · Derivation C · 1 minRecovering the period with continued fractions
The goal of this final derivation is to justify the classical back end: given a single measured rational guaranteed within of some unknown , recover exactly and provably. The engine is a uniqueness argument — with enough precision, only one fraction of denominator below can sit that close to the measurement — married to the theorem that such a fraction must be a continued-fraction convergent of . The one gap is the coprimality of and , which we detect and repair by a verification-and-repeat loop.
Step 1. Bound the gap between rival periods: for distinct fractions with denominators below ,
Why: the numerator is a nonzero integer, so it is at least ; this sets the minimum spacing the precision must beat.
Step 2. Demand precision that beats the half-gap. Choosing gives
so is the unique fraction of denominator within reach. Why: once the error is below the continued-fraction theorem (6) applies verbatim, and no impostor can compete.
Step 3. Expand as a continued fraction by the Euclidean algorithm and list its convergents ; the theorem guarantees (in lowest terms) is one of them. Why: continued fractions give the best rational approximations of every denominator, so the unique close fraction must appear.
Step 4. Read off the denominator: precisely when ; otherwise it is the proper divisor . Verify each candidate by testing . Why: a cheap modular exponentiation distinguishes the true order from a divisor with certainty.
Step 5. If the check fails, repeat: two runs yield denominators whose least common multiple equals with constant probability, and ensures runs suffice. Why: coprime numerators are common enough that a handful of samples reconstructs the full order almost surely. *Verified: for the measurement gives continued fraction with convergent (denominator ), and , so recovery is provably forced. Confirmed against Hardy & Wright and Nielsen & Chuang Theorem A4.16.*
Limiting cases
The algorithm's behaviour turns entirely on the register precision, whether the random numerator is coprime to , and whether is degenerate:
| Case | Result | Meaning |
|---|---|---|
| Sufficient precision | The measurement is closer to than any rival fraction of denominator , so continued fractions recover exactly; also lifts phase-estimation success above . | |
| Coprime numerator | The lucky case: continued fractions return the full order in one shot, with probability . | |
| Non-coprime numerator | The run returns only the proper divisor ; recover from of two runs' denominators, which succeeds with constant probability. | |
| Insufficient precision | A competing fraction can masquerade as ; continued fractions may return a wrong denominator, and the algorithm loses its correctness guarantee. | |
| Degenerate order | means (excluded by construction); with gives no useful Shor factor. Classical preprocessing discards these before the quantum subroutine runs. |
Worked examples
1 · Factoring 15 with a = 7 (fully worked)
Take and the random base . Trace the order-finding circuit, read a measurement, recover the order, and complete Shor's reduction to a factor of 15.
Step 1. Fix the register size. With , use control qubits and ; the condition holds, so continued fractions are forced to succeed.
Step 2. For checking, the order is , so . The circuit does not know this; it discovers a multiple of .
Step 3. Predict the comb: peaks at , i.e. — here divides exactly, so the peaks are perfectly sharp. Suppose the register returns .
Step 4. Post-process. Form ; its denominator is and , so this is the full order . Verify . (Had we measured , the denominator is only the divisor ; the check flags it and we repeat.)
Step 5. Complete Shor's reduction. Since is even and , compute and . The order yields the factorization .
2 · Factoring 21 with a = 2 (continued fractions genuinely needed)
Take , . Now the order will not divide the register size, so the peaks are smeared and continued fractions do real work.
Step 1. Register size: , so and . The order is , so — and crucially .
Step 2. The peak sits near , so the register most likely returns . Form .
Step 3. Run the Euclidean algorithm on : the continued fraction is , with convergents . The convergent is the closest fraction of denominator below : , inside the guaranteed window.
Step 4. Read from the denominator, with confirming the full order; check . Continued fractions recovered from a smeared peak no naive rounding could resolve.
Step 5. Shor's reduction: even, , so and . The order yields .
Physics of the portrait
Order finding is where a 350-year-old thread of number theory — Fermat's little theorem, Gauss's modular arithmetic, the structure of — collided with quantum mechanics and produced the result that turned quantum computing from a curiosity into a strategic technology.
Origins · 1 minPeter Shor and how this was discovered
Peter Williston Shor was a combinatorialist at Bell Labs when, in 1994, he did the thing that made quantum computing matter to governments: he showed a quantum computer could factor large integers in polynomial time. The pivot was recognizing that factoring reduces to order finding — an idea rooted in classical number theory, sharpened by Gary Miller's 1976 result under the extended Riemann hypothesis — and that order finding is a period-detection problem the quantum Fourier transform solves exponentially faster than any known classical method. Shor's insight was an architecture, not a trick: encode the period into the eigenphases of modular multiplication, extract them with phase estimation, and clean up the noisy rational with centuries-old continued fractions. The paper detonated the field, and worries that decoherence would make it unbuildable soon drove Shor to invent quantum error-correcting codes in 1995 — arguably a deeper contribution, since it showed fault-tolerant quantum computation is possible in principle. The shadow is long: it is why the world's cryptographic infrastructure is being rebuilt around post-quantum standards, and why order finding is taught as the canonical exponential quantum speedup.
Going further
Texts. Nielsen & Chuang, Quantum Computation and Quantum Information, §5.3 (order finding and factoring) and Appendix 4 (continued fractions) · Mermin, Quantum Computer Science, Ch. 3 (period finding) · Kitaev, Shen & Vyalyi, Classical and Quantum Computation, §13 (abelian problems) · Preskill, Lecture Notes for Physics 219, Ch. 6 · Shor, Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer, SIAM J. Comput. 26, 1484 (1997) · Watrous, quantum-complexity lecture notes.
Provenance. Structure and analysis follow Nielsen & Chuang §5.3: the eigenvector and eigenphase identities, the seed decomposition of , and the continued-fraction recovery; complexity bounds cross-checked against Shor (1997) and Preskill Ch. 6. A verifier should recompute: (1) the eigenvalue equation by root-of-unity reindexing; (2) the seed identity from geometric-series orthogonality; (3) the precision inequality forcing from the minimal gap; (4) the two worked examples — giving , and with continued fraction giving ; (5) the phase-estimation bound and the totient lower bound. All numerical results were checked programmatically.
Prerequisites. Quantum Phase Estimation · Quantum Fourier Transform · Hidden Subgroup Problem · Quantum Parallelism and the Oracle Model. Leads to. Shor's Factoring Algorithm · Quantum Discrete Logarithm Algorithm · Hidden Subgroup Problem · Simon's Algorithm.
Ask the tutor: Ask me to run the order-finding circuit on your own and — I will trace the peaks, do the continued fraction, and show exactly how the period falls out.
Is order finding the same thing as Shor's algorithm?
Not quite — order finding is the quantum engine, and Shor's algorithm is the full factoring machine around it. Shor's algorithm is mostly classical: pick a random coprime to , call order finding to get , and if is even with , read a factor from . The only genuinely quantum step is finding ; everything else is classical number theory a laptop does instantly. So "Shor's algorithm" is order finding wrapped in a classical reduction that converts a period into a factor.
Why not just measure the target register after the modular exponentiation to read off the period?
You can, and it is illuminating, but it does not give directly. Measuring the target collapses it to some , leaving the control register in an equal superposition over the progression — periodic with period but shifted by an unknown offset . Applying the QFT then yields a multiple of , because the Fourier transform is blind to the offset (it only shifts phases). This "measure first" picture is exactly equivalent to the eigenvalue picture above, which is just cleaner because it isolates one phase per branch.
What makes order finding hard for a classical computer?
No classical shortcut to the period is known that avoids essentially exponential work. You can compute quickly for any single , but finding the smallest with seems to require searching candidates or knowing — and computing is itself equivalent to factoring . The best classical factoring algorithm, the number field sieve, runs in time roughly , superpolynomial in the digits. The quantum advantage is that the Fourier transform reads global periodicity from a superposition in one shot, whereas classically you can only sample the sequence point by point, so the period of an exponentially long cycle stays hidden.
Where does the number-theoretic assumption enter that r is usually even and well-behaved?
It enters in Shor's classical reduction, not in order finding itself. Order finding returns whatever is; the reduction needs even and . A theorem guarantees that for a random coprime to an odd composite that is not a prime power, both conditions hold with probability at least (in fact for distinct odd prime factors). So if a run gives a useless , pick a fresh and try again; a constant expected number of attempts suffices. Prime powers and even are stripped off first by cheap classical tests.
Why continued fractions specifically — is there no simpler way to round j over two to the t to s over r?
Naive rounding fails because you do not know , so you cannot tell which nearby fraction the measurement intends. The measured is close to but also to infinitely many fractions with larger denominators; you want the unique one with small denominator (below ) near . Continued fractions produce exactly the best rational approximations ordered by denominator size, and the theorem that any fraction within of appears among its convergents turns "close" into "provably recovered." No simpler rounding rule carries that guarantee, and the smeared peaks when (as in the example) are precisely why you need it.
How does order finding generalize to period finding and the hidden subgroup problem?
Order finding is the special case where has period . The same circuit — uniform superposition, evaluate into a target, Fourier-transform the input, measure — finds the period of any efficiently computable periodic . Recast group-theoretically, the periods form the hidden subgroup of , and is constant on its cosets. Replacing by other abelian groups and the QFT by the Fourier transform over that group solves Simon's problem (), the discrete logarithm (a period lattice), and the general finite abelian hidden subgroup problem — one template, many exponential speedups.