Documentation

CslibFrontier.Foundations.FieldTheory.Finite.BinaryPolynomial

Binary polynomials as bit lists #

The executable side of the explicit binary fields. A binary polynomial is represented by its list of coefficients, constant term first (Cslib.polyOfBits); the binary digits of a code m are the coefficients of polyOfCode m (Cslib.polyOfBits_bits).

Reduction modulo a polynomial g of degree m uses one primitive, multiplication by X modulo g on coefficient lists of length m (Cslib.mulXMod): shift up and add g when the top coefficient overflows. The remainder of f is the sum of the remainders of the powers X ^ j with f j = 1 (Cslib.modBits), so g ∣ f exactly when that sum vanishes (Cslib.modBits_all_false_iff). Trial division by the polynomials of degree at most half the degree decides irreducibility (Cslib.isIrreducibleCode_iff), and an exhaustive search over codes finds the irreducible polynomial of least code (Cslib.polyOfCode_leastIrreducibleCode). The remainders of X ^ e, e < 2 m, give the arithmetic of 𝔽₂[X] / (g) in the power basis (Cslib.pow_eq_sum_powerTable).

Main definitions #

Main results #

References #

noncomputable def Cslib.polyOfBits :

The binary polynomial with coefficient list l, constant term first.

Instances For

    Concatenating coefficient lists shifts the upper polynomial by X ^ l.length.

    If true appears in l, then polyOfBits l is nonzero.

    The degree of polyOfBits l is strictly less than l.length.

    theorem Cslib.aeval_polyOfBits {A : Type u_1} [CommSemiring A] [Algebra (ZMod 2) A] (α : A) (l : List Bool) :

    Evaluating polyOfBits l at α sums l.getD d false • α ^ d over d < l.length.

    The coefficient list of the code m, its binary digits, gives the polynomial with code m.

    theorem Cslib.exists_bits_eq_append_true {m : ℕ} (hm : m ≠ 0) :
    ∃ (l : List Bool), m.bits = l ++ [true]

    The binary digits of a nonzero number end with a one.

    Reduction modulo a binary polynomial #

    Multiplication by X modulo the polynomial with coefficient list g, on coefficient lists of length g.length - 1: shift up, add g when the coefficient of degree g.length - 1 is one, and drop that coefficient.

    Instances For

      One step of modBits: the next power of X modulo g, and the partial remainder.

      Instances For

        The remainder of the polynomial with coefficient list f modulo the one with coefficient list g, as a coefficient list of length g.length - 1: the sum of the remainders of the powers X ^ j with f j = 1, computed by repeated multiplication by X modulo g.

        Instances For

          Multiply two coefficient words modulo g by scanning the bits of b. The two live words hold successive shifts of a modulo g and the partial product. For a monic modulus, a should have length one less than g.

          Instances For
            theorem Cslib.length_modMulBits (g a b : List Bool) (ha : a.length = g.length - 1) :
            (modMulBits g a b).length = g.length - 1

            Multiplication retains the modulus width for any supplied modulus if the first operand already has that width.

            With a padded to the degree of the modulus, any prefix of the multiplier leaves two degree-sized words and its modular product is the product in the quotient.

            For a coefficient list g = l ++ [true] with top coefficient one, modBits g f is congruent to f modulo the polynomial of g: both have the same image in AdjoinRoot (polyOfBits g).

            The divisibility test: the polynomial with coefficient list l ++ [true] divides the one with coefficient list f exactly when the remainder modBits vanishes.

            The divisibility test on codes: for d ≠ 0, some coefficient of the remainder of f modulo the polynomial with code d is one exactly when that polynomial does not divide f.

            def Cslib.divisorPasses (candidate divisor : ℕ) :

            One trial divisor passes when its degree is outside the tested range or its remainder is nonzero. Both codes use their little-endian binary coefficient words.

            Instances For

              Trial division: whether the binary polynomial with code m is irreducible. It is when m ≥ 2 and no polynomial of degree between 1 and half the degree of m (a code d < m) divides it.

              Instances For

                Trial division decides irreducibility: isIrreducibleCode m holds exactly when the binary polynomial with code m is irreducible.

                The exhaustive search: the least code m < B of an irreducible binary polynomial of degree p, by trial division (0 if there is none).

                Instances For

                  The search finds the code of leastIrreducible p once its range contains all codes of degree p.

                  Remainders of powers #

                  The coefficient lists of the remainders of X ^ e, e < 2 (g.length - 1), modulo the polynomial with coefficient list g.

                  Instances For
                    theorem Cslib.pow_eq_sum_powerTable {A : Type u_1} [CommRing A] [Algebra (ZMod 2) A] (l : List Bool) {α : A} (hα : (Polynomial.aeval α) (polyOfBits (l ++ [true])) = 0) {e : ℕ} (he : e < 2 * l.length) :

                    At a root α of the polynomial with coefficient list l ++ [true], the power α ^ e, e < 2 l.length, is the combination of the powers below l.length given by powerTable.