Documentation

HexBerlekamp.Irreducibility

X^(p^k) - X reduced modulo f.

Equations
Instances For

    Positive divisors of n below n, listed in ascending order.

    These are the candidates from which Rabin's test extracts the maximal proper divisors.

    Equations
    Instances For

      The maximal proper divisors of n, i.e. those proper divisors not strictly below any other proper divisor of n.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        true exactly when g is a nonzero constant polynomial.

        Equations
        Instances For

          Berlekamp's executable rank criterion: a nonconstant monic f passes when rank(Q_f - I) = deg(f) - 1.

          Equations
          Instances For

            The divisibility leg of Rabin's criterion: f divides X^(p^n) - X, with n = deg(f), exactly when the reduced remainder vanishes.

            Equations
            Instances For

              The gcd leg of Rabin's criterion at a single maximal proper divisor d of deg(f).

              Equations
              Instances For

                Record the per-divisor Rabin gcd checks so downstream factorization code can see which maximal proper divisor rejected a candidate polynomial.

                Equations
                Instances For

                  Bezout evidence that one Rabin gcd leg is coprime.

                  • left : FpPoly p

                    Coefficient multiplying the polynomial under test.

                  • right : FpPoly p

                    Coefficient multiplying the corresponding Frobenius difference.

                  Instances For

                    Self-describing certificate data for Rabin irreducibility checking.

                    The bezout array is indexed in the same order as maximalProperDivisors n. Each witness proves coprimality of f and X^(p^d) - X mod f by the executable identity left * f + right * (X^(p^d) - X) = 1.

                    • p : Nat

                      The characteristic of the finite field.

                    • bounds : ZMod64.Bounds self.p

                      The modulus bound, carried so the certificate is self-describing.

                    • n : Nat

                      The degree claimed for the polynomial under test.

                    • powChain : Array (FpPoly self.p)

                      Successive Frobenius powers used by the Rabin checks.

                    • bezout : Array (RabinBezoutWitness self.p)

                      Bezout witnesses for the maximal proper divisors of n.

                    Instances For

                      Read the certified X^(p^k) mod f witness, if present.

                      Equations
                      Instances For

                        Read the Bezout witness for the i-th maximal proper divisor, if present.

                        Equations
                        Instances For

                          Same-prime view of a self-contained certificate after its stored p has been matched against the ambient field.

                          • n : Nat

                            The degree claimed for the polynomial under test.

                          • powChain : Array (FpPoly p)

                            Successive Frobenius powers used by the Rabin checks.

                          • Bezout witnesses for the maximal proper divisors of n.

                          Instances For

                            Match a certificate's stored prime against the ambient p. Returns the same-prime view on success, or none if the certificate is for a different prime.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              def Hex.Berlekamp.certifiedFrobeniusDiffMod {p : Nat} [ZMod64.Bounds p] (f : FpPoly p) (hmonic : DensePoly.Monic f) (powWitness : FpPoly p) :

                              The Rabin difference polynomial represented by a certificate pow-chain entry.

                              Equations
                              Instances For

                                Check that a certificate's pow chain matches the committed Frobenius routine.

                                Equations
                                Instances For

                                  Kernel-reducible pow-chain check for small closed polynomials. It checks the same mathematical witnesses as checkPowChain, but compares against the structural Frobenius evaluator so decide can reduce concrete certificates.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Check one Bezout witness for a Rabin maximal-proper-divisor leg.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      Check all Bezout witnesses against maximalProperDivisors cert.n.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        Executable checker for a Rabin irreducibility certificate.

                                        It validates the self-described p and n, recomputes every pow-chain entry, checks the divisibility leg X^(p^n) = X mod f, and verifies each Bezout identity for the maximal proper divisors of n.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          Kernel-reducible Rabin certificate checker. This is intended for small record-literal polynomials where the theorem input rabinTest f hmonic = true should be discharged by decide.

                                          @[expose] because that is the whole point: without an exposed body, decide in a downstream module file gets stuck on the unreduced application, and the only way to discharge the check is a hand-written simp unfolding, which is what this definition exists to avoid.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For

                                            Rabin's executable irreducibility test: f must be nonconstant, divide X^(p^n) - X, and be coprime to X^(p^d) - X for every maximal proper divisor d of n = deg(f).

                                            Equations
                                            Instances For

                                              Bezout witness that f and the Rabin difference X^(p^d) - X mod f are coprime, computed by the extended Euclidean algorithm.

                                              The extended gcd returns left₀ * f + right₀ * diff = g with g a nonzero constant when the two are coprime; scaling both coefficients by g⁻¹ (as its leading coefficient, i.e. its constant value) normalises the identity to left * f + right * diff = 1, which is exactly the equation checkRabinBezoutWitness verifies. This is compiled, never-in-kernel prep: a wrong witness simply makes the downstream check return false.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For

                                                Assemble a Rabin irreducibility certificate for the monic polynomial f, when rabinTest accepts it.

                                                The pow chain records X^(p^k) mod f for k = 0, …, deg f, matching checkPowChain, and the Bezout array records one normalised rabinBezoutWitness per maximal proper divisor of deg f, in the same order as maximalProperDivisors, matching checkRabinBezoutWitnesses. Returns none when f fails Rabin's test.

                                                This is the prep half of the certifying-irreducibility pattern: the expensive Frobenius-chain and extended-gcd work runs in compiled code here, so the kernel only has to replay the cheap checkIrreducibilityCertificate reduction on the finished data. The generator carries no soundness proof of its own; a wrong certificate makes checkIrreducibilityCertificate return false, never a false pass.

                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For

                                                  berlekampRankTest succeeds exactly when the fixed-space matrix has rank deg(f) - 1, the Berlekamp rank criterion.

                                                  rabinDividesTest reduces to checking that frobeniusDiffMod f _ n vanishes, where n = deg(f).

                                                  theorem Hex.Berlekamp.checkPowChain_spec {p : Nat} [ZMod64.Bounds p] (f : FpPoly p) (hmonic : DensePoly.Monic f) (cert : SamePrimeIrreducibilityCertificate p) :
                                                  checkPowChain f hmonic cert = true∀ (k : Nat), k cert.ncert.powChain[k]? = some (f.frobeniusXPowMod hmonic k)

                                                  If checkPowChain accepts, every entry cert.powChain[k] (for k ≤ cert.n) agrees with the committed Frobenius routine FpPoly.frobeniusXPowMod.

                                                  theorem Hex.Berlekamp.checkPowChainLinear_spec {p : Nat} [ZMod64.Bounds p] [ZMod64.PrimeModulus p] (f : FpPoly p) (hmonic : DensePoly.Monic f) (cert : SamePrimeIrreducibilityCertificate p) :
                                                  checkPowChainLinear f hmonic cert = true∀ (k : Nat), k cert.ncert.powChain[k]? = some (f.frobeniusXPowMod hmonic k)

                                                  Linear-kernel companion to checkPowChain_spec: if checkPowChainLinear accepts, every entry agrees with FpPoly.frobeniusXPowMod, after rewriting the structural Frobenius evaluator through FpPoly.frobeniusXPowModLinear_eq_frobeniusXPowMod.

                                                  If checkIrreducibilityCertificate accepts a self-describing certificate, the corresponding rabinTest succeeds. Downstream irreducibility soundness (FpPoly.Irreducible) is then chained via HexBerlekamp.RabinSoundness.rabinTest_imp_irreducible.

                                                  Kernel-reducible counterpart of checkIrreducibilityCertificate_rabinTest, suited to decide-discharged certificates over small concrete polynomials.

                                                  The single-step recurrence: powChain[k+1] must equal (powChain[k])^p mod f.

                                                  Equations
                                                  • One or more equations did not get rendered due to their size.
                                                  Instances For

                                                    Kernel-reducible incremental pow-chain check. Validates that powChain[0] = X mod f and that each successor is the previous entry's p-th power modulo f. Total work is O(n · p) instead of O(Σ p^k).

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For

                                                      Quotient-witness checker for FpPoly 2 pow chains. Entry k of quotients certifies powChain[k] * powChain[k] = powChain[k+1] + quotients[k] * f, with both chain entries already reduced modulo f.

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For
                                                        theorem Hex.Berlekamp.checkPowChainLinearIncrementalQuotientWitnessStep_of_entries (f prev curr quot : FpPoly 2) (cert : SamePrimeIrreducibilityCertificate 2) (quotients : Array (FpPoly 2)) (k : Nat) (hprev : cert.powChain[k]? = some prev) (hcurr : cert.powChain[k + 1]? = some curr) (hquot : quotients[k]? = some quot) (hprevRed : DensePoly.natDegree prev < DensePoly.natDegree f) (hcurrRed : DensePoly.natDegree curr < DensePoly.natDegree f) (hmulCoeffs : (prev * prev).coeffs = (curr + quot * f).coeffs) :

                                                        Soundness of checkPowChainLinearIncrementalQuotientWitnessStep from explicit chain and quotient entries: given powChain[k] = prev, powChain[k+1] = curr, quotients[k] = quot, both entries reduced below deg f, and the witnessed identity prev * prev = curr + quot * f on coefficients, the checker returns true.

                                                        theorem Hex.Berlekamp.checkPowChainLinearIncrementalQuotientWitnessStep_of_entry_bools (f prev curr quot : FpPoly 2) (cert : SamePrimeIrreducibilityCertificate 2) (quotients : Array (FpPoly 2)) (k : Nat) (hprev : cert.powChain[k]? = some prev) (hcurr : cert.powChain[k + 1]? = some curr) (hquot : quotients[k]? = some quot) (hprevRed : decide (DensePoly.natDegree prev < DensePoly.natDegree f) = true) (hcurrRed : decide (DensePoly.natDegree curr < DensePoly.natDegree f) = true) (hmulCoeffs : ((prev * prev).coeffs == (curr + quot * f).coeffs) = true) :

                                                        _of_entries restated with the two degree bounds and the coefficient equality supplied as decide/== Booleans, matching the form the checker itself evaluates.

                                                        theorem Hex.Berlekamp.degree?_getD_lt_of_size_le {R : Type u} [Zero R] [DecidableEq R] (g : DensePoly R) {n : Nat} (hnpos : 0 < n) (hsize : g.size n) :

                                                        A DensePoly whose coefficient size is at most n (with 0 < n) has natDegree < n. Converts a coefficient-count bound into the degree bound consumed by the quotient-witness step lemmas.

                                                        theorem Hex.Berlekamp.checkPowChainLinearIncrementalQuotientWitnessStep_of_entry_size_bounds (f prev curr quot : FpPoly 2) (cert : SamePrimeIrreducibilityCertificate 2) (quotients : Array (FpPoly 2)) (k : Nat) (hprev : cert.powChain[k]? = some prev) (hcurr : cert.powChain[k + 1]? = some curr) (hquot : quotients[k]? = some quot) (hfpos : 0 < DensePoly.natDegree f) (hprevSize : DensePoly.size prev DensePoly.natDegree f) (hcurrSize : DensePoly.size curr DensePoly.natDegree f) (hmulCoeffs : (prev * prev).coeffs = (curr + quot * f).coeffs) :

                                                        _of_entries restated with the two reducedness hypotheses replaced by size bounds on the chain entries, discharged through degree?_getD_lt_of_size_le.

                                                        The i-th coefficient in ZMod64 2 of a packed UInt64 bit-word: 1 when bit i of bits is set, 0 otherwise.

                                                        Equations
                                                        Instances For
                                                          def Hex.Berlekamp.gf2WordPoly (bits : UInt64) (width : Nat) :

                                                          Reinterpret the low width bits of bits as an FpPoly 2, with coefficient i given by gf2BitCoeff bits i.

                                                          Equations
                                                          Instances For
                                                            theorem Hex.Berlekamp.gf2WordPoly_size_le (bits : UInt64) (width : Nat) :
                                                            DensePoly.size (gf2WordPoly bits width) width

                                                            gf2WordPoly bits width has coefficient size at most width.

                                                            theorem Hex.Berlekamp.gf2WordPoly_degree?_getD_lt (bits : UInt64) {width bound : Nat} (hwidth_pos : 0 < bound) (hwidth : width bound) :
                                                            DensePoly.natDegree (gf2WordPoly bits width) < bound

                                                            If width ≤ bound and 0 < bound, then (gf2WordPoly bits width).natDegree < bound; the degree bound used when feeding a bit-word polynomial to the witness step.

                                                            theorem Hex.Berlekamp.gf2WordPoly_coeff (bits : UInt64) (width i : Nat) :
                                                            DensePoly.coeff (gf2WordPoly bits width) i = if i < width then gf2BitCoeff bits i else 0

                                                            Coefficient i of gf2WordPoly bits width is gf2BitCoeff bits i when i < width, and 0 otherwise.

                                                            def Hex.Berlekamp.coeffsEqUpTo (bound : Nat) (a b : FpPoly 2) :

                                                            true exactly when a and b agree on every coefficient 0 … bound-1; the bounded executable prefix-equality check over List.range bound.

                                                            Equations
                                                            Instances For
                                                              def Hex.Berlekamp.quotientStepCoeffCheck (bound : Nat) (prev curr quot f : FpPoly 2) :

                                                              Bounded per-step quotient-witness test: prev * prev and curr + quot * f agree on coefficients below bound.

                                                              Equations
                                                              Instances For
                                                                theorem Hex.Berlekamp.coeff_eq_of_coeffsEqUpTo {bound : Nat} {a b : FpPoly 2} (h : coeffsEqUpTo bound a b = true) (i : Nat) :
                                                                i < boundDensePoly.coeff a i = DensePoly.coeff b i

                                                                A passing coeffsEqUpTo yields coefficient equality on every index below the bound.

                                                                theorem Hex.Berlekamp.coeffs_eq_of_size_le_of_coeff_eq {bound : Nat} {a b : FpPoly 2} (ha : DensePoly.size a bound) (hb : DensePoly.size b bound) (hcoeff : ∀ (i : Nat), i < boundDensePoly.coeff a i = DensePoly.coeff b i) :

                                                                If both polynomials have size at most bound and agree on coefficients below bound, their full coefficient arrays are equal.

                                                                theorem Hex.Berlekamp.coeffs_eq_of_size_le_of_coeffsEqUpTo {bound : Nat} {a b : FpPoly 2} (ha : DensePoly.size a bound) (hb : DensePoly.size b bound) (h : coeffsEqUpTo bound a b = true) :

                                                                Upgrade a passing coeffsEqUpTo to full coefficient-array equality, given that both polynomials have size at most bound.

                                                                theorem Hex.Berlekamp.quotientStep_coeffs_eq_of_check {bound : Nat} {prev curr quot f : FpPoly 2} (hleft : DensePoly.size (prev * prev) bound) (hright : DensePoly.size (curr + quot * f) bound) (hcheck : quotientStepCoeffCheck bound prev curr quot f = true) :
                                                                (prev * prev).coeffs = (curr + quot * f).coeffs

                                                                A passing quotientStepCoeffCheck, with both sides bounded in size by bound, certifies (prev * prev).coeffs = (curr + quot * f).coeffs.

                                                                def Hex.Berlekamp.gf2WordQuotientStepCoeffCheck (bound width : Nat) (prevBits currBits quotBits fBits : UInt64) :

                                                                quotientStepCoeffCheck specialised to GF(2) operands packed as UInt64 bit-words, decoded through gf2WordPoly.

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For
                                                                  theorem Hex.Berlekamp.gf2WordQuotientStep_coeffs_eq_of_check {bound width : Nat} {prevBits currBits quotBits fBits : UInt64} (hleft : DensePoly.size (gf2WordPoly prevBits width * gf2WordPoly prevBits width) bound) (hright : DensePoly.size (gf2WordPoly currBits width + gf2WordPoly quotBits width * gf2WordPoly fBits width) bound) (hcheck : gf2WordQuotientStepCoeffCheck bound width prevBits currBits quotBits fBits = true) :
                                                                  (gf2WordPoly prevBits width * gf2WordPoly prevBits width).coeffs = (gf2WordPoly currBits width + gf2WordPoly quotBits width * gf2WordPoly fBits width).coeffs

                                                                  Word-packed analogue of quotientStep_coeffs_eq_of_check: a passing gf2WordQuotientStepCoeffCheck under the size bounds yields coefficient-array equality of the decoded GF(2) polynomials.

                                                                  theorem Hex.Berlekamp.checkRabinBezoutWitness_of_coeffsEqUpTo (f : FpPoly 2) (hmonic : DensePoly.Monic f) (cert : SamePrimeIrreducibilityCertificate 2) {i d bound : Nat} {powWitness : FpPoly 2} {witness : RabinBezoutWitness 2} (hpow : cert.powChain[d]? = some powWitness) (hbezout : cert.bezout[i]? = some witness) (hleft : DensePoly.size (witness.left * f + witness.right * certifiedFrobeniusDiffMod f hmonic powWitness) bound) (hright : DensePoly.size 1 bound) (hcoeffs : coeffsEqUpTo bound (witness.left * f + witness.right * certifiedFrobeniusDiffMod f hmonic powWitness) 1 = true) :
                                                                  checkRabinBezoutWitness f hmonic cert i d = true

                                                                  Prefix-check entry point to checkRabinBezoutWitness: if the Bezout combination left * f + right * diff agrees with 1 on every coefficient up to bound (with both sides bounded by bound), the witness check accepts. Used when the certifier carries a coeffsEqUpTo prefix comparison rather than full polynomial equality.

                                                                  theorem Hex.Berlekamp.checkRabinBezoutWitness_of_coeffs_eq (f : FpPoly 2) (hmonic : DensePoly.Monic f) (cert : SamePrimeIrreducibilityCertificate 2) {i d : Nat} {powWitness : FpPoly 2} {witness : RabinBezoutWitness 2} (hpow : cert.powChain[d]? = some powWitness) (hbezout : cert.bezout[i]? = some witness) (hcoeffs : (witness.left * f + witness.right * certifiedFrobeniusDiffMod f hmonic powWitness).coeffs = DensePoly.coeffs 1) :
                                                                  checkRabinBezoutWitness f hmonic cert i d = true

                                                                  Coefficient-equality entry point to checkRabinBezoutWitness: if the Bezout combination left * f + right * diff has the same coefficient array as 1, the witness check accepts.

                                                                  theorem Hex.Berlekamp.checkRabinBezoutWitness_of_poly_eq (f : FpPoly 2) (hmonic : DensePoly.Monic f) (cert : SamePrimeIrreducibilityCertificate 2) {i d : Nat} {powWitness : FpPoly 2} {witness : RabinBezoutWitness 2} (hpow : cert.powChain[d]? = some powWitness) (hbezout : cert.bezout[i]? = some witness) (hpoly : witness.left * f + witness.right * certifiedFrobeniusDiffMod f hmonic powWitness = 1) :
                                                                  checkRabinBezoutWitness f hmonic cert i d = true

                                                                  Polynomial-equality entry point to checkRabinBezoutWitness: if the Bezout combination left * f + right * diff equals 1 as a polynomial, the witness check accepts. The terminal form the two coefficient-level entry points reduce to.

                                                                  Discharge the first-entry condition of checkPowChainLinearIncrementalQuotientWitnesses from coefficient equality: if powChain[0] has the same coefficient array as X mod f, then powChain[0]? == some (X mod f).

                                                                  Bool-valued variant of checkPowChainLinearIncrementalQuotientWitnesses_first_of_coeffs: accepts the first-entry condition from a == coefficient comparison that evaluates to true.

                                                                  Quotient-witness form of the incremental pow-chain check: validates the chain size, that powChain[0] = X mod f, and every per-step witness via checkPowChainLinearIncrementalQuotientWitnessStep. Avoids recomputing the modular squarings by reading the quotients off the certificate.

                                                                  Equations
                                                                  • One or more equations did not get rendered due to their size.
                                                                  Instances For
                                                                    theorem Hex.Berlekamp.checkPowChainLinearIncrementalQuotientWitnesses_of_steps (f : FpPoly 2) (hmonic : DensePoly.Monic f) (cert : SamePrimeIrreducibilityCertificate 2) (quotients : Array (FpPoly 2)) (hpowSize : (cert.powChain.size == cert.n + 1) = true) (hquotSize : (quotients.size == cert.n) = true) (hfirst : (cert.powChain[0]? == some (f.modByMonic FpPoly.X hmonic)) = true) (hsteps : ∀ (k : Nat), k < cert.ncheckPowChainLinearIncrementalQuotientWitnessStep f cert quotients k = true) :

                                                                    Introduction rule for checkPowChainLinearIncrementalQuotientWitnesses: assemble acceptance from the two size conditions, the first-entry condition, and a per-step witness check for every k < cert.n.

                                                                    Soundness of the quotient-witness chain check against the squaring-based one: if checkPowChainLinearIncrementalQuotientWitnesses accepts, then so does checkPowChainLinearIncremental. Each accepted quotient witness prev * prev = curr + quot * f (both entries reduced) pins curr = powModMonicLinear prev f _ 2, recovering the step recurrence.

                                                                    Incremental Rabin certificate checker, suitable for (p, n) regimes where p^n is too large for checkIrreducibilityCertificateLinear but n · p remains in budget (e.g. (5, 6) or (7, 6)).

                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For

                                                                      Incremental companion to checkPowChain_spec: if checkPowChainLinearIncremental accepts, every entry agrees with FpPoly.frobeniusXPowMod. The proof inducts on k, using the chain identity X^(p^(k+1)) ≡ (X^(p^k))^p (mod f).

                                                                      Incremental counterpart of checkIrreducibilityCertificate_rabinTest, suited to (p, n) regimes where the per-step O(n · p) cost fits the decide kernel budget but the bulk O(Σ p^k) of the non-incremental checker does not.

                                                                      The incremental kernel checker implies the committed checker: a certificate accepted by checkIrreducibilityCertificateLinearIncremental is accepted by checkIrreducibilityCertificate. This lets kernel-replayed certificates feed consumers stated over the committed checker without restating their soundness.