Kernel-checkable Rabin irreducibility certificates over prime fields #
Rabin's test (CompPoly/Data/Polynomial/Rabin.lean) reduces irreducibility of a degree-d
polynomial f over ZMod p to divisibility and coprimality conditions against X^(p^k) - X.
Verifying those conditions requires computing X^(p^k) mod f — around d · log₂ p modular
squarings — which is far beyond what decide can do on Polynomial values and which this
repository's TCB policy forbids delegating to native_decide.
This file provides the reusable, degree-agnostic certificate infrastructure:
- Polynomials are represented as little-endian
ℕ-coefficient lists (toPolyinterprets them in(ZMod p)[X]), with schoolbook arithmetic (addNat,mulNat) by structural recursion, so every check reduces in the kernel via GMP-acceleratedNatoperations. - A certificate
Steprecords a squaring (or multiply-by-X) together with the quotient and remainder of the division byf;checkStepverifiescur² = q·f + r(coefficientwise, modp) andrunChainfolds a whole square-and-multiply chain, so an entire exponentiation certificate is one list literal checked by a single kernel reduction. runChain_soundlifts a checked chain toX^N % f = r % fin(ZMod p)[X]; the two Rabin conditions follow viadvd_X_pow_sub_X_of_runChain(trace) andisCoprime_X_pow_sub_X_of_runChain(coprimality, from a Bézout certificate on the reduced residue).irreducible_of_rabin_prime_degreepackages Rabin's test for prime degreed, where the conditions collapse to a single trace and a single coprimality check;irreducible_of_rabin_prime_powerdoes the same atd = ℓ ^ k, where the collapse is still sound;irreducible_of_rabin_two_prime_factorsandirreducible_of_rabin_degree_sixcover a degree with two distinct prime factors. All take the field size as a numeralqwithFintype.card F = q, the shape concrete extensions use.
Certificate data is produced by the untrusted generator scripts/gen_rabin_certificate.py;
the kernel re-checks every step. Contrast CompPoly/Fields/Binary/BF128Ghash/, the bespoke
GF(2¹²⁸) predecessor of this framework, which spells out each step as a separate lemma.
ℕ-level polynomial arithmetic #
Little-endian coefficient lists. No coefficient is ever reduced during a product — entries
stay below d² · p², comfortably inside GMP range — and comparisons reduce mod p at the
end (eqModP), so no subtraction (and hence no truncation) occurs anywhere.
The specification bridge #
Interpret a little-endian coefficient list in (ZMod p)[X], Horner-style. Specification
only; certificate checking never evaluates it.
Instances For
addNat denotes addition: the coefficientwise sum of two lists is the sum of the
polynomials they denote. One of the three specification bridges that make the ℕ-list
arithmetic usable as a certificate format.
mulNat denotes multiplication: schoolbook convolution of the coefficient lists is the
product of the polynomials they denote. Proved from toPoly_addNat and toPoly_scaleNat,
following the same recursion mulNat uses.
A list whose every coefficient is 0 mod p denotes the zero polynomial. This is the base
case behind toPoly_eq_of_eqModP, which is how a eqModP kernel check becomes an equation
between polynomials.
Square-and-multiply chains #
One step of a square-and-multiply chain modulo f: from the current residue cur, either
square it (mulX = false) or multiply it by X (mulX = true), and divide by f to get
quotient q and next residue r. The generator supplies q and r; the checker only has
to confirm one polynomial identity per step.
- mulX : Bool
truefor a multiply-by-Xstep,falsefor a squaring step. The quotient of the step's product by the modulus.
The remainder — the next residue in the chain.
Instances For
Soundness of a whole chain: a checked chain starting at the residue of X^e ends at
the residue of X^(chainExp e steps).
A chain started at [0, 1] (the residue of X¹) computes X^N % f.
The two Rabin conditions from certificates #
Equal remainders mean the divisor divides the difference.
The trace condition from a chain. A checked chain for X^N ending back at [0, 1]
(the residue X) proves f ∣ X^N - X.
The coprimality condition from a chain plus a Bézout certificate.
The chain reduces X^N to a residue rp; writing rp = w + X (checked by eqModP), we have
X^N - X ≡ w (mod f), so a Bézout identity u·f + v·w = 1 (again checked by eqModP)
witnesses IsCoprime f (X^N - X).
Packaging Rabin's test at a concrete degree #
Polynomial.irreducible_of_rabin already quantifies the coprimality condition over
d.primeFactors. The wrappers below discharge that quantifier for the shapes of d that
concrete extensions use, so a caller supplies one coprimality proof per prime factor and nothing
else. Each takes the field size as a numeral q with hcard : Fintype.card F = q, exactly as
Polynomial.irreducible_of_rabin does — supply ZMod.card _ at a concrete field, or rfl to
read the conditions at Fintype.card F. The section comment in
CompPoly/Data/Polynomial/Rabin.lean records why that is the only shape these statements have.
Note that irreducible_of_rabin_prime_degree does not apply at composite d, and its
collapsed condition is not merely inconvenient but unsound there: a product of equal-degree
factors divides X^(q^d) - X and is coprime to X^q - X, so it would pass.
irreducible_of_rabin_prime_power is the collapse that is sound at d = ℓ ^ k.
Rabin's test for prime degree. For f of prime degree d over a finite field with q
elements, the per-prime-factor conditions collapse to a single coprimality check at exponent q:
f is irreducible provided f ∣ X^(q^d) - X and IsCoprime f (X^q - X).
Alias of CompPoly.RabinCert.irreducible_of_rabin_prime_degree.
Rabin's test for prime degree. For f of prime degree d over a finite field with q
elements, the per-prime-factor conditions collapse to a single coprimality check at exponent q:
f is irreducible provided f ∣ X^(q^d) - X and IsCoprime f (X^q - X).
Rabin's test for a prime-power degree, such as d = 8, 64 or 128.
d = ℓ ^ k has the single prime factor ℓ, so — exactly as at prime degree — the caller supplies
the trace condition plus one coprimality certificate, here at exponent q ^ (d / ℓ). Unlike
irreducible_of_rabin_prime_degree this is sound at composite d: the check at d / ℓ rules
out every proper divisor of d, because every proper divisor of ℓ ^ k divides ℓ ^ (k - 1).
d is kept separate from ℓ ^ k and tied to it by hd_eq so that the conditions read at the
caller's numeral (q ^ 64, not q ^ 2 ^ 6); supply hd_eq as by norm_num. This is the shape
the characteristic-two moduli use — Aes.modulus at d = 8 and BF64.basePoly at d = 64.
Rabin's test for a degree with exactly two prime factors, such as d = 6.
The caller supplies the trace condition plus one coprimality certificate per prime factor, at
exponents q^(d/ℓ₁) and q^(d/ℓ₂). The hypothesis h_factors is by decide at a concrete
degree — for d = 6 it is (6 : ℕ).primeFactors = {2, 3}, giving checks at q^3 and q^2.
Both checks are needed. Dropping the q^3 one admits a product of two irreducible cubics;
dropping the q^2 one admits a product of three irreducible quadratics.
Rabin's test at degree 6. f of degree 6 over a finite field with q elements is irreducible
provided f ∣ X^(q^6) - X, IsCoprime f (X^(q^3) - X), and IsCoprime f (X^(q^2) - X).
This is the shape used by the KoalaBear degree-6 extension. It differs from
irreducible_of_rabin_two_prime_factors only in discharging Nat.primeFactors 6 = {2, 3}
internally, so callers never touch Nat.primeFactors.
The q^3 check is what rules out a product of two irreducible cubics, and the q^2 check a
product of three irreducible quadratics; the trace condition alone permits both.
Alias of CompPoly.RabinCert.irreducible_of_rabin_degree_six.
Rabin's test at degree 6. f of degree 6 over a finite field with q elements is irreducible
provided f ∣ X^(q^6) - X, IsCoprime f (X^(q^3) - X), and IsCoprime f (X^(q^2) - X).
This is the shape used by the KoalaBear degree-6 extension. It differs from
irreducible_of_rabin_two_prime_factors only in discharging Nat.primeFactors 6 = {2, 3}
internally, so callers never touch Nat.primeFactors.
The q^3 check is what rules out a product of two irreducible cubics, and the q^2 check a
product of three irreducible quadratics; the trace condition alone permits both.