Documentation

HexGF2.Field.Word

theorem Hex.GF2Poly.coeff_eq_false_of_reduced_bound_le {p : GF2Poly} {bound n : Nat} (hred : p.IsZero p.natDegree < bound) (hbound : bound n) :

Coefficients above a reduced degree bound are zero.

def Hex.GF2Poly.reducedCoeffVector (bound : Nat) (p : GF2Poly) :
Fin boundBool

Bounded coefficient vector used as a finite-index code for reduced packed polynomials.

Equations
Instances For
    theorem Hex.GF2Poly.eq_of_reducedCoeffVector_eq {bound : Nat} {p q : GF2Poly} (hp : p.IsZero p.natDegree < bound) (hq : q.IsZero q.natDegree < bound) (hcoeff : reducedCoeffVector bound p = reducedCoeffVector bound q) :
    p = q

    Two reduced packed polynomials below the same bound are equal when their bounded coefficient vectors agree.

    Internal Boolean coefficient values used to build finite coefficient-list enumerations for packed quotient proofs.

    Equations
    Instances For
      @[simp]

      The internal Boolean coefficient enumeration has exactly the two field coefficients.

      Every Boolean coefficient appears in the internal coefficient enumeration.

      The internal Boolean coefficient enumeration contains no duplicates, so coefficient-list enumeration does not duplicate choices at one position.

      Internal enumeration of all Boolean coefficient lists of length d, ordered lexicographically by the head coefficient.

      Equations
      Instances For
        @[simp]

        Base case of the coefficient-list enumeration: the only length-0 Boolean list is the empty list.

        @[simp]

        Recursion equation for the coefficient-list enumeration: every length-d+1 list is obtained by prepending each Boolean head value to a length-d list.

        theorem Hex.GF2Poly.Internal.length_of_mem_coeffBoolLists {d : Nat} {coeffs : List Bool} (hmem : coeffs coeffBoolLists d) :
        coeffs.length = d

        Every list produced by coeffBoolLists d has length exactly d.

        Membership in coeffBoolLists d is exactly having length d.

        theorem Hex.GF2Poly.Internal.mem_coeffBoolLists_of_length_eq {d : Nat} {coeffs : List Bool} (hlen : coeffs.length = d) :

        Every fixed-length Boolean coefficient list appears in the enumeration.

        @[simp]

        The Boolean coefficient-list enumeration has exactly 2 ^ d entries.

        The fixed-length Boolean coefficient-list enumeration has no duplicates.

        Internal builder for the finite-enumeration proof: interpret bs[i] as the coefficient of x^(start + i) in a packed GF2Poly.

        Equations
        Instances For

          Internal builder for the finite-enumeration proof: interpret bs[i] as the coefficient of x^i in a packed GF2Poly.

          Equations
          Instances For
            theorem Hex.GF2Poly.Internal.coeff_ofBoolListFrom_lt (start : Nat) (bs : List Bool) (n : Nat) :
            n < start(ofBoolListFrom start bs).coeff n = false

            The packed polynomial built from a coefficient list shifted by start has no coefficient set strictly below start.

            theorem Hex.GF2Poly.Internal.coeff_ofBoolListFrom_ge (start : Nat) (bs : List Bool) (n : Nat) :
            start n(ofBoolListFrom start bs).coeff n = bs[n - start]?.getD false

            The packed polynomial built from a coefficient list shifted by start reads back the matching list entry, defaulting to false past the end.

            Coefficient correctness for ofBoolList: indices below the length read the matching list entry, indices at or above the length read false.

            Indices at or above the list length read false.

            The packed polynomial built from a length-d Boolean coefficient list is either zero or has degree strictly below d.

            structure Hex.GF2nPoly (f : GF2Poly) (hirr : f.Irreducible) :

            GF(2^n) for arbitrary n, represented by reduced GF2Poly residues modulo an irreducible polynomial.

            • val : GF2Poly

              The canonical residue representing this field element, reduced modulo f.

            • val_reduced : self.val.IsZero self.val.natDegree < f.natDegree

              The representative is reduced modulo f: it is either zero or of degree below the modulus, so each field element has exactly one packed spelling. Zero is called out separately because the packed degree of the zero polynomial is 0, not -∞.

            Instances For
              structure Hex.GF2n (n : Nat) (irr : UInt64) (hn : 0 < n) (hn64 : n < 64) (hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible) :

              GF(2^n) packed into one machine word. The modulus stores only the lower n coefficients; the leading x^n term is implicit in GF2Poly.ofUInt64Monic irr n.

              • val : UInt64

                The packed canonical representative: the lower n coefficients of the residue modulo the implicit modulus x^n + irr.

              • val_lt : self.val.toNat < 2 ^ n

                The representative is reduced: only the lower n bits are set, so each field element has exactly one packed spelling and equality of elements is equality of words.

              Instances For
                def Hex.GF2n.modulus {n : Nat} {irr : UInt64} :

                The packed irreducible modulus polynomial defining this extension field.

                Equations
                Instances For

                  The low-word mask selecting canonical representatives of degree < n.

                  Equations
                  Instances For

                    Convert a machine word into its packed polynomial representative.

                    Equations
                    Instances For

                      Convert a UInt64 × UInt64 carry-less product into a packed polynomial.

                      Equations
                      Instances For
                        def Hex.GF2n.reducePoly {n : Nat} {irr : UInt64} (p : GF2Poly) :

                        Reduce a packed polynomial modulo the fixed irreducible and read back the single-word representative.

                        Equations
                        Instances For
                          def Hex.GF2n.canonicalWord {n : Nat} {hn64 : n < 64} (w : UInt64) :

                          Repackage a word as a canonical representative below 2^n.

                          Equations
                          Instances For
                            theorem Hex.GF2n.canonicalWord_lt {n : Nat} {hn64 : n < 64} (w : UInt64) :

                            Canonical words are bounded by the extension degree.

                            def Hex.GF2n.reduce {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (w : UInt64) :
                            GF2n n irr hn hn64 hirr

                            Canonical constructor from a raw word by reduction modulo the field modulus.

                            Equations
                            Instances For
                              def Hex.GF2n.reduceWide {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (hi lo : UInt64) :
                              GF2n n irr hn hn64 hirr

                              Canonical constructor from a packed 128-bit carry-less product.

                              Equations
                              Instances For
                                def Hex.GF2n.natCast {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (k : Nat) :
                                GF2n n irr hn hn64 hirr

                                Natural-number literals in characteristic two reduce to their parity.

                                Equations
                                Instances For
                                  def Hex.GF2n.zero {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                  GF2n n irr hn hn64 hirr

                                  Canonical additive identity.

                                  Equations
                                  Instances For
                                    @[instance_reducible]
                                    instance Hex.GF2n.instZero {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                    Zero (GF2n n irr hn hn64 hirr)
                                    Equations
                                    def Hex.GF2n.one {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                    GF2n n irr hn hn64 hirr

                                    Canonical multiplicative identity.

                                    Equations
                                    Instances For
                                      @[instance_reducible]
                                      instance Hex.GF2n.instOne {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                      One (GF2n n irr hn hn64 hirr)
                                      Equations
                                      @[instance_reducible]
                                      instance Hex.GF2n.instNatCast {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                      NatCast (GF2n n irr hn hn64 hirr)
                                      Equations
                                      @[instance_reducible]
                                      instance Hex.GF2n.instOfNat {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (k : Nat) :
                                      OfNat (GF2n n irr hn hn64 hirr) k
                                      Equations
                                      def Hex.GF2n.add {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a b : GF2n n irr hn hn64 hirr) :
                                      GF2n n irr hn hn64 hirr

                                      Addition in characteristic two is word-wise XOR followed by canonical reduction.

                                      Equations
                                      Instances For
                                        @[instance_reducible]
                                        instance Hex.GF2n.instAdd {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                        Add (GF2n n irr hn hn64 hirr)
                                        Equations
                                        def Hex.GF2n.neg {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a : GF2n n irr hn hn64 hirr) :
                                        GF2n n irr hn hn64 hirr

                                        Negation is the identity in characteristic two.

                                        Equations
                                        Instances For
                                          @[instance_reducible]
                                          instance Hex.GF2n.instNeg {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                          Neg (GF2n n irr hn hn64 hirr)
                                          Equations
                                          def Hex.GF2n.sub {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a b : GF2n n irr hn hn64 hirr) :
                                          GF2n n irr hn hn64 hirr

                                          Subtraction coincides with addition in characteristic two.

                                          Equations
                                          Instances For
                                            @[instance_reducible]
                                            instance Hex.GF2n.instSub {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                            Sub (GF2n n irr hn hn64 hirr)
                                            Equations
                                            def Hex.GF2n.nsmul {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (k : Nat) (a : GF2n n irr hn hn64 hirr) :
                                            GF2n n irr hn hn64 hirr

                                            Natural scalar multiplication in characteristic two depends only on the parity of the scalar.

                                            Equations
                                            Instances For
                                              @[instance_reducible]
                                              instance Hex.GF2n.instSMulNat {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                              SMul Nat (GF2n n irr hn hn64 hirr)
                                              Equations
                                              def Hex.GF2n.mul {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a b : GF2n n irr hn hn64 hirr) :
                                              GF2n n irr hn hn64 hirr

                                              Multiplication uses the carry-less word primitive followed by reduction modulo the packed irreducible.

                                              Equations
                                              Instances For
                                                @[instance_reducible]
                                                instance Hex.GF2n.instMul {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                                Mul (GF2n n irr hn hn64 hirr)
                                                Equations
                                                def Hex.GF2n.pow {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a : GF2n n irr hn hn64 hirr) (k : Nat) :
                                                GF2n n irr hn hn64 hirr

                                                Natural power in GF(2^n) by repeated squaring.

                                                Equations
                                                Instances For
                                                  @[irreducible]
                                                  def Hex.GF2n.pow.go {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (acc base : GF2n n irr hn hn64 hirr) (k : Nat) :
                                                  GF2n n irr hn hn64 hirr

                                                  Square-and-multiply accumulator loop for GF2n.pow: go acc base k computes acc * base ^ k.

                                                  Equations
                                                  Instances For
                                                    @[instance_reducible]
                                                    instance Hex.GF2n.instPowNat {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                                    Pow (GF2n n irr hn hn64 hirr) Nat
                                                    Equations
                                                    def Hex.GF2n.intCast {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (k : Int) :
                                                    GF2n n irr hn hn64 hirr

                                                    Integer literals also reduce to parity because -1 = 1 in characteristic two.

                                                    Equations
                                                    Instances For
                                                      @[instance_reducible]
                                                      instance Hex.GF2n.instIntCast {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                                      IntCast (GF2n n irr hn hn64 hirr)
                                                      Equations
                                                      def Hex.GF2n.zsmul {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (k : Int) (a : GF2n n irr hn hn64 hirr) :
                                                      GF2n n irr hn hn64 hirr

                                                      Integer scalar multiplication depends only on parity as well.

                                                      Equations
                                                      Instances For
                                                        @[instance_reducible]
                                                        instance Hex.GF2n.instSMulInt {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                                        SMul Int (GF2n n irr hn hn64 hirr)
                                                        Equations
                                                        def Hex.GF2n.invWord {n : Nat} {irr : UInt64} (w : UInt64) :

                                                        The extended Euclidean witness supplies an inverse candidate modulo the packed irreducible.

                                                        Equations
                                                        Instances For
                                                          def Hex.GF2n.inv {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a : GF2n n irr hn hn64 hirr) :
                                                          GF2n n irr hn hn64 hirr

                                                          Inversion follows the packed extended-GCD path and uses the usual junk value 0⁻¹ = 0.

                                                          Equations
                                                          Instances For
                                                            @[instance_reducible]
                                                            instance Hex.GF2n.instInv {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                                            Inv (GF2n n irr hn hn64 hirr)
                                                            Equations
                                                            def Hex.GF2n.div {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a b : GF2n n irr hn hn64 hirr) :
                                                            GF2n n irr hn hn64 hirr

                                                            Division is multiplication by the inverse candidate.

                                                            Equations
                                                            Instances For
                                                              @[instance_reducible]
                                                              instance Hex.GF2n.instDiv {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                                              Div (GF2n n irr hn hn64 hirr)
                                                              Equations
                                                              def Hex.GF2n.zpow {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a : GF2n n irr hn hn64 hirr) :
                                                              IntGF2n n irr hn hn64 hirr

                                                              Integer exponentiation uses inversion for negative exponents.

                                                              Equations
                                                              Instances For
                                                                @[instance_reducible]
                                                                instance Hex.GF2n.instHPowInt {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                                                HPow (GF2n n irr hn hn64 hirr) Int (GF2n n irr hn hn64 hirr)
                                                                Equations
                                                                theorem Hex.GF2n.div_eq_mul_inv {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a b : GF2n n irr hn hn64 hirr) :
                                                                a / b = a * b⁻¹

                                                                Division in GF2n unfolds to multiplication by the multiplicative inverse.

                                                                @[simp]
                                                                theorem Hex.GF2n.inv_zero {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} :
                                                                0⁻¹ = 0

                                                                The inverse of 0 in GF2n is 0 (the field convention that makes inversion total).

                                                                theorem Hex.GF2n.mul_inv_cancel {n : Nat} {irr : UInt64} {hn : 0 < n} {hn64 : n < 64} {hirr : (GF2Poly.ofUInt64Monic irr n).Irreducible} (a : GF2n n irr hn hn64 hirr) (ha : a 0) :
                                                                a * a⁻¹ = 1

                                                                Every nonzero element of GF2n cancels against its inverse, witnessing that GF2n is a field.