Exact quantum period finding #
This module formalizes the quantum core of Shor's algorithm in the case where the period divides the size of the Fourier register (Shor, §5; de Wolf, §5.3, "Easy case: r divides q").
The problem. A function f : ZMod N → S has exact period r (Cslib.Quantum.HasExactPeriod)
when r ∣ N and f x = f x' exactly when x.val ≡ x'.val [MOD r]. For instance
a ↦ x^a mod M on ZMod N has exact period the order r of x modulo M whenever r ∣ N
(Cslib.Quantum.hasExactPeriod_pow).
The algorithm. Start in |0⟩|s₀⟩, apply the quantum Fourier transform (Cslib.Quantum.qft) to
the first register, apply an oracle unitary U with U|x, s₀⟩ = |x, f x⟩, and obtain the state
N^{-1/2} ∑_x |x⟩|f x⟩ (Cslib.Quantum.oracleState;
Cslib.Quantum.unitaryEquiv_oracle_qft_ket_zero; Shor, eqs. (5.1)–(5.2)). The standard
oracle |x, s⟩ ↦ |x, s + f x⟩ (Cslib.Quantum.addOracle) is one such unitary. Apply the Fourier
transform to the first register again (Cslib.Quantum.periodState, Shor eqs. (5.3)–(5.4)) and
measure the first register (Cslib.Quantum.periodFindingOutcome).
The analysis. The amplitude of |y, f x₀⟩ is N⁻¹ ∑_{x : f x = f x₀} ω^{xy}, a character sum
over the coset x₀ + ⟨r⟩, whose squared modulus is the probability of Shor's eq. (5.5). By
orthogonality over the subgroup ⟨r⟩ (ZMod.sum_dvd_val_stdAddChar_mul) it is ω^{x₀ y} / r when
N / r divides y, and 0 otherwise (Cslib.Quantum.HasExactPeriod.periodState_apply). Since
f takes r values, each multiple of N / r is measured with probability exactly 1 / r: the
outcome is uniformly distributed on the r multiples of N / r
(Cslib.Quantum.HasExactPeriod.periodFindingOutcome_eq; for the whole circuit
(F_N ⊗ I) U (F_N ⊗ I)|0, s₀⟩, Cslib.Quantum.HasExactPeriod.measure_period_circuit).
Classical recovery. An outcome y = c · N / r with 0 ≤ c < r satisfies
y / N = c / r, so the reduced denominator N / gcd(N, y) of y / N equals r exactly when c
is coprime to r (Shor, §5; de Wolf §5.3). Equivalently, y has additive order r in
ZMod N, and exactly φ(r) of the multiples do, so the recovery succeeds with probability exactly
φ(r) / r (Cslib.Quantum.HasExactPeriod.periodFindingOutcome_recover). An elementary bound on
φ(r) / r (Nat.le_totient_mul_log_add_one) makes this at least 1 / (log₂ r + 1)
(Cslib.Quantum.HasExactPeriod.inv_log_add_one_le_periodFindingOutcome_recover).
Scope. This is the special case r ∣ N of Shor's analysis, which takes N = q a power of two
with n² ≤ q < 2n² and handles r ∤ q by continued fractions; that case is not formalized. The
Fourier transform and the oracle are unitary matrices, not gate-level circuits, so no gate counts,
uniformity or approximation costs are claimed, and nothing here proves that factoring is in BQP.
The recovery bound 1 / (log₂ r + 1) is weaker than the Ω(1 / log log r) of Shor and de Wolf,
which rests on Hardy and Wright's Theorem 328 and is not formalized. The same computation solves the
hidden subgroup problem for the subgroup ⟨r⟩ of ZMod N: the outcomes are uniform on its
annihilator.
Main definitions #
Cslib.Quantum.HasExactPeriod:f : ZMod N → Shas exact periodr ∣ N.Cslib.Quantum.oracleState: the stateN^{-1/2} ∑_x |x⟩|f x⟩.Cslib.Quantum.addOracle: the oracle|x, s⟩ ↦ |x, s + f x⟩.Cslib.Quantum.periodState: the state after the second Fourier transform.Cslib.Quantum.periodFindingOutcome: the distribution of the first register's measurement.
Main results #
Cslib.Quantum.hasExactPeriod_pow: order finding is an instance when the order dividesN.Cslib.Quantum.unitaryEquiv_oracle_qft_ket_zero: Fourier transform and oracle prepareoracleState ffrom|0, s₀⟩.Cslib.Quantum.HasExactPeriod.periodState_apply: the final amplitudes.Cslib.Quantum.HasExactPeriod.periodFindingOutcome_apply: each outcome has probability1 / rif it is a multiple ofN / r, and0otherwise.Cslib.Quantum.HasExactPeriod.periodFindingOutcome_eq: the outcome is uniform on the multiples ofN / r.Cslib.Quantum.HasExactPeriod.measure_period_circuit: the same for the first register of the measured circuit(F_N ⊗ I) U (F_N ⊗ I)|0, s₀⟩, for any oracle unitaryU.Cslib.Quantum.HasExactPeriod.periodFindingOutcome_recover:N / gcd(N, y) = rwith probability exactlyφ(r) / r.Cslib.Quantum.HasExactPeriod.inv_log_add_one_le_periodFindingOutcome_recover: that probability is at least1 / (log₂ r + 1).
References #
Under exact period r, f x = f x' exactly when x' - x lies in the subgroup generated by
r.
A function with exact period r takes exactly r values.
Order finding is exact period finding when the order divides N: if orderOf x ∣ N, then
a ↦ x ^ a.val has exact period orderOf x (Shor, §5, with x^a mod n in the
group of units of ZMod n).
State preparation #
The state N^{-1/2} ∑_x |x⟩|f x⟩ after one query to f on a uniform superposition
(Shor, eq. (5.2)).
The Fourier transform of |0⟩ is the uniform superposition: (F_N ⊗ I)|0, s₀⟩ = N^{-1/2} ∑_x |x, s₀⟩ (Shor, eq. (5.1)).
State preparation (Shor, eqs. (5.1)–(5.2)): for any oracle unitary U with
U|x, s₀⟩ = |x, f x⟩, applying the Fourier transform to the first register of |0, s₀⟩ and then
U gives N^{-1/2} ∑_x |x⟩|f x⟩.
The standard oracle |x, s⟩ ↦ |x, s + f x⟩ of a function into an additive group, the
permutation matrix of a shear of ZMod N × S.
With the standard oracle and s₀ = 0, Fourier transform and oracle prepare
N^{-1/2} ∑_x |x⟩|f x⟩.
The final state and its measurement #
The state (F_N ⊗ I) N^{-1/2} ∑_x |x⟩|f x⟩ before the final measurement
(Shor, eq. (5.4)).
The amplitude of |y, s⟩ in periodState f is N⁻¹ ∑_{x : f x = s} ω^{xy}.
The final amplitudes under exact period r, in the case r ∣ N: the amplitude of
|y, f x₀⟩ is ω^{x₀ y} / r when N / r divides y, and 0 otherwise. Its squared modulus is
the probability of Shor, eq. (5.5) (HasExactPeriod.norm_periodState_apply_sq).
Under exact period r, each joint outcome (y, f x₀) has probability 1 / r² when N / r
divides y, and 0 otherwise: the probability of Shor, eq. (5.5), in the case
r ∣ N.
The distribution of the outcome of measuring the first register of periodState f: the
marginal on ZMod N of the computational-basis measurement of both registers.
Exact period finding (de Wolf, §5.3, the case where r divides q):
measuring the first register gives y with probability 1 / r if N / r divides y, and 0
otherwise.
Exact period finding, as an equality of distributions: the measured value is uniformly
distributed on the r multiples of N / r.
Exact period finding, end to end: for any oracle unitary U with U|x, s₀⟩ = |x, f x⟩,
measuring the state (F_N ⊗ I) U (F_N ⊗ I)|0, s₀⟩ and reading the first register gives a uniformly
distributed multiple of N / r (Shor, eqs. (5.1)–(5.5), in the case r ∣ N;
de Wolf, §5.3).
Classical recovery (Shor, §5; de Wolf, §5.3): the reduced
denominator N / gcd(N, y) of y / N is the period r with probability exactly φ(r) / r.
The recovery of Cslib.Quantum.HasExactPeriod.periodFindingOutcome_recover succeeds with
probability at least 1 / (log₂ r + 1), by the elementary bound r ≤ φ(r) (log₂ r + 1)
(Nat.le_totient_mul_log_add_one).