--- id: QuantumShorContinuedFractions language: en section: quantum-physics source: Verification/QuantumShorContinuedFractions.lean source_sha256: 281c191f1d94e0a16f0de9cf477b92cb3fc738e40e882cd5e0fc6f9b075d70d0 novelty: not-assessed status: reviewed --- # Continued fractions for Shor postprocessing [Section](../quantum-physics/README.md) · [Lean](../../Verification/QuantumShorContinuedFractions.lean) ## Executable algorithm convergents and partialQuotients accept a rational number and use floor followed by reciprocal fractional part. Rat floor is integer Euclidean division. Recursion stops at an integer and terminates by strictly decreasing canonical denominator. These are computable definitions, not noncomputable witnesses from Legendre. candidates(y,Q,N) filters convergents of the exact rational y/Q by denominator < N. Its inputs contain no unknown spectral numerator s or order r. checkedCandidates additionally takes a and filters denominators through a^q mod N = 1 mod N. mem_convergents_iff proves both directions between membership in the finite list and Mathlib Real.convergent. Mathlib's repeated terminal convergents are covered. The strict Legendre theorem Real.exists_rat_eq_convergent is reused from pinned Mathlib; its foundational number theory is not claimed as new work. The list length is at most the input denominator. More strongly, the number of Euclidean stages (partial-quotient list length) is at most 2*Nat.log 2 denominator+1, hence at most 2*Nat.log 2 Q+1 for y/Q with Q>0. The proof uses a strict denominator reduction at each step and a factor-of-two reduction over two steps. This counts Euclidean stages, not all list-map work, bit operations, modular exponentiation cost, or a bound on total program runtime. No O(log N) claim without relating Q to N. ## Approximation and recovery The existing Shor Parameters supply N≥2, a coprime to N and the padded target register. The actual period is r=orderOf(a : ZMod N), with r>0 and r0, and the two are coprime. Since q≤r