Expand description
Shor’s period-finding subroutine.
The quantum heart of Shor’s factoring algorithm is order finding: given a
base a coprime to N, find the multiplicative order r — the least
positive integer with a^r ≡ 1 (mod N). Quantum phase estimation on the
modular-multiplication unitary U_a|y⟩ = |a·y mod N⟩ yields a phase
φ ≈ k/r, and the classical continued-fraction expansion of φ recovers
the denominator r. Once r is known (and even, with a^{r/2} ≢ −1), the
factors of N are gcd(a^{r/2} ± 1, N).
This module provides:
mod_exp— fast modular exponentiation by repeated squaring.gcd— binary Euclidean greatest common divisor.continued_fraction_convergents— the convergentsp_i/q_iof a real.order_finding— state-vector phase estimation ofU_aplus classical continued-fraction post-processing.shor_factor— the end-to-end reduction fromrto a non-trivial factor ofN.
The counting register is little-endian (qubit i carries weight 2^i),
matching crate::fourier::qft.
Structs§
- Order
Finding Result - Outcome of
order_finding. - Shor
Result - Outcome of
shor_factor.
Functions§
- classical_
order - Brute-force the multiplicative order of
amodulon(classical reference). - continued_
fraction_ convergents - Compute the continued-fraction convergents
(p_i, q_i)ofvalue ∈ [0, 1), stopping once a denominator exceedsmax_denominatoror the expansion terminates. - factor_
from_ order - Classical reduction from a period
r(order ofbasemodn) to a factor. - gcd
- Binary-Euclidean greatest common divisor of
aandb. - mod_exp
- Fast modular exponentiation
base^exp mod modulusvia repeated squaring. - order_
finding - Quantum order finding for the unitary
U_a|y⟩ = |a·y mod N⟩. - shor_
factor - End-to-end Shor factoring driver using quantum order finding.