Knuth–Schönhage Half-GCD and Modular Polynomial Inversion over ZMod p #
Implements the divide-and-conquer Half-GCD recursion (hgcd), extended Euclidean algorithm
(fastExtGCDCore), and modular polynomial inversion (fastInvMod) for univariate polynomials
over prime fields ZMod p, proving exact algebraic correctness, unimodularity, degree reduction
below d / 2, and matrix entry-degree invariants.
Scope and Provenance #
This module is an algebraic correctness milestone for the Half-GCD recursion following
Knuth (1970), Schönhage (1971), and [vzGG13], Chapter 11 (fast Euclidean
algorithm). Polynomial division, remainder, and
multiplication use Mathlib's abstract (ZMod p)[X] operations without a machine-level
Word-RAM or multi-tape running-time certificate; certifying the Õ(d * log p) bit complexity in
a concrete machine model is left as future work.
Main definitions #
Cslib.Algorithms.PolynomialArithmetic.PolyMat2:2 × 2polynomial transition matrix over a field with determinant and entry-degree invariants.Cslib.Algorithms.PolynomialArithmetic.hgcd,fastExtGCDCore,fastInvMod: divide-and-conquer Half-GCD, extended GCD, and modular polynomial inversion.
Main results #
Cslib.Algorithms.PolynomialArithmetic.hgcd_spec: unimodularity, degree reduction belowd / 2, and matrix entry-degree bounds.Cslib.Algorithms.PolynomialArithmetic.fastExtGCDCore_spec: Bézout correctness and GCD universality.Cslib.Algorithms.PolynomialArithmetic.fastInvMod_spec: modular inversion correctness for coprime polynomials in(ZMod p)[X].
2 × 2 Polynomial Matrices and Shift-Quotient Helpers #
A 2 × 2 matrix over F[X] tracking Euclidean transition steps in Half-GCD.
- a : Polynomial F
Top-left entry.
- b : Polynomial F
Top-right entry.
- c : Polynomial F
Bottom-left entry.
- d : Polynomial F
Bottom-right entry.
Identity 2 × 2 polynomial matrix.
Single Euclidean step matrix [[0, 1], [1, -q]].
Matrix-vector action on a pair of polynomials.
Polynomial Truncation by X^m #
Recursive Knuth–Schönhage Half-GCD over ZMod p (with prime p). Given r₀, r₁ with
r₁.natDegree < r₀.natDegree (and r₀ ≠ 0), computes a unimodular transition matrix R reducing
(r₀, r₁) to (b₀, b₁) with b₀.natDegree ≥ (r₀.natDegree + 1) / 2 and
b₁ = 0 ∨ b₁.natDegree < (r₀.natDegree + 1) / 2.
Algebraic correctness and entry-degree bound for hgcd.
Extended Euclidean algorithm using hgcd, returning (g, u, v) with
u * r₀ + v * r₁ = g, g ∣ r₀, and g ∣ r₁.
Correctness specification of fastExtGCDCore for r₁.natDegree < r₀.natDegree.
Modular polynomial inverse in (ZMod p)[X] modulo M via fastExtGCDCore:
returns some U with (U * G) % M = 1 % M when gcd(G, M) is a nonzero constant, and none
otherwise.
Specification of fastInvMod: whenever M ≠ 0 and IsCoprime G M, fastInvMod G M
returns some U satisfying (U * G) % M = 1 % M, and any returned some U satisfies
(U * G) % M = 1 % M.