Documentation

CompPoly.Fields.KoalaBear.Fast

Fast KoalaBear Field Operations #

This module provides a native-word implementation of KoalaBear arithmetic as a sidecar to the canonical KoalaBear.Field := ZMod KoalaBear.fieldSize model.

Fast field values are stored as Montgomery UInt32 residues below KoalaBear.fieldSize, representing x * 2^32 modulo the KoalaBear prime. Addition, subtraction, and negation operate directly on Montgomery words; multiplication uses Montgomery reduction on a native UInt64 product.

KoalaBear modulus as a native word.

Instances For

    KoalaBear modulus as a 64-bit word for modular reduction.

    Instances For

      2^32 mod KoalaBear.fieldSize. This is the Montgomery representation of one.

      Instances For

        (2^32)^2 mod KoalaBear.fieldSize, used to enter Montgomery representation.

        Instances For

          -KoalaBear.fieldSize⁻¹ mod 2^32, used by Montgomery reduction.

          Instances For
            @[reducible, inline]

            The fast native-word KoalaBear field carrier, stored as a Montgomery residue.

            Instances For
              @[inline]

              The raw Montgomery word backing a fast KoalaBear element.

              Instances For
                @[simp]

                The native UInt32 modulus agrees with the mathematical KoalaBear modulus.

                @[simp]

                The native UInt64 modulus agrees with the mathematical KoalaBear modulus.

                @[inline]

                Montgomery reduction of a 64-bit word. Hot bounded callers use montgomeryReduceBounded.

                Instances For
                  @[inline]

                  Build a fast element from a canonical natural representative.

                  Instances For
                    @[inline]

                    Reduce a UInt64 modulo the KoalaBear prime and return a Montgomery fast element.

                    Instances For

                      The zero fast KoalaBear element.

                      Instances For

                        The one fast KoalaBear element.

                        Instances For
                          @[inline]

                          Convert a natural number into fast Montgomery representation.

                          Instances For
                            @[inline]

                            Convert a 32-bit word into fast Montgomery representation.

                            Instances For
                              @[inline]

                              Convert from the canonical ZMod KoalaBear field into fast Montgomery form.

                              Instances For
                                @[inline]

                                Convert an integer into fast Montgomery representation.

                                Instances For
                                  @[inline]

                                  Convert a fast element to its canonical native-word representative.

                                  Instances For
                                    @[inline]

                                    Convert a fast KoalaBear element to its canonical natural representative.

                                    Instances For
                                      @[inline]

                                      Convert a fast KoalaBear element to the canonical ZMod KoalaBear field.

                                      Instances For
                                        @[simp]

                                        Converting a canonical natural representative to fast form preserves its value.

                                        @[simp]

                                        ofCanonicalNat embeds a canonical representative into the canonical field.

                                        @[simp]

                                        Reducing a UInt64 gives the canonical natural residue modulo KoalaBear.

                                        @[simp]

                                        Reducing a UInt64 agrees with casting that word into the canonical field.

                                        @[inline]

                                        Fast modular addition in Montgomery form.

                                        Instances For
                                          @[inline]

                                          Fast modular negation in Montgomery form.

                                          Instances For
                                            @[inline]

                                            Fast modular subtraction in Montgomery form.

                                            Instances For
                                              @[inline]

                                              Fast modular multiplication in Montgomery form.

                                              Instances For
                                                @[inline]

                                                Fast squaring.

                                                Instances For
                                                  @[inline]

                                                  Exponentiation over the fast representation using repeated squaring.

                                                  Instances For

                                                    Fermat exponent used for inversion in the KoalaBear prime field.

                                                    Instances For
                                                      @[inline]

                                                      Inversion in Montgomery form by a fixed 4-bit Fermat chain.

                                                      Instances For
                                                        @[inline]

                                                        Division through inversion and fast multiplication.

                                                        Instances For
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[implicit_reducible]
                                                          @[simp]

                                                          Converting from the canonical field to fast form and back is the identity.

                                                          @[simp]

                                                          Converting from fast form to the canonical field and back is the identity.

                                                          The canonical-field interpretation distinguishes fast KoalaBear values.

                                                          @[simp]

                                                          toField maps fast zero to canonical zero.

                                                          @[simp]

                                                          toField maps fast one to canonical one.

                                                          @[simp]

                                                          Fast addition agrees with addition in the canonical KoalaBear field.

                                                          @[simp]

                                                          Fast subtraction agrees with subtraction in the canonical KoalaBear field.

                                                          @[simp]

                                                          Fast negation agrees with negation in the canonical KoalaBear field.

                                                          @[simp]

                                                          Fast multiplication agrees with multiplication in the canonical KoalaBear field.

                                                          Ring equivalence between the fast Montgomery representation and canonical KoalaBear.Field.

                                                          Instances For
                                                            @[simp]

                                                            Applying ringEquiv is the same as interpreting a fast value canonically.

                                                            @[simp]

                                                            Applying the inverse ringEquiv is conversion into fast Montgomery form.

                                                            @[simp]

                                                            Fast squaring agrees with multiplication by itself in the canonical field.

                                                            @[simp]
                                                            theorem KoalaBear.Fast.toField_pow (x : Field) (n : ) :
                                                            toField (pow x n) = toField x ^ n

                                                            Fast natural-power computation agrees with powers in the canonical field.

                                                            @[simp]

                                                            Fast inversion agrees with inversion in the canonical KoalaBear field.

                                                            @[simp]

                                                            Fast division agrees with division in the canonical KoalaBear field.

                                                            @[simp]
                                                            theorem KoalaBear.Fast.toField_natCast (n : ) :
                                                            toField n = n

                                                            Natural casts into fast form agree with natural casts into the canonical field.

                                                            @[simp]
                                                            theorem KoalaBear.Fast.toField_intCast (n : ) :
                                                            toField n = n

                                                            Integer casts into fast form agree with integer casts into the canonical field.

                                                            @[simp]
                                                            theorem KoalaBear.Fast.toField_nsmul (n : ) (x : Field) :
                                                            toField (n x) = n toField x

                                                            Natural scalar multiplication is preserved by toField.

                                                            @[simp]
                                                            theorem KoalaBear.Fast.toField_zsmul (n : ) (x : Field) :
                                                            toField (n x) = n toField x

                                                            Integer scalar multiplication is preserved by toField.

                                                            @[simp]
                                                            theorem KoalaBear.Fast.toField_npow (x : Field) (n : ) :
                                                            toField (x ^ n) = toField x ^ n

                                                            Natural powers through the Pow instance are preserved by toField.

                                                            @[simp]
                                                            theorem KoalaBear.Fast.toField_zpow (x : Field) (n : ) :
                                                            toField (x ^ n) = toField x ^ n

                                                            Integer powers through the Pow instance are preserved by toField.

                                                            @[simp]

                                                            Nonnegative rational casts into fast form agree with canonical-field casts.

                                                            @[simp]
                                                            theorem KoalaBear.Fast.toField_ratCast (q : ) :
                                                            toField q = q

                                                            Rational casts into fast form agree with canonical-field casts.

                                                            @[simp]

                                                            Nonnegative rational scalar multiplication is preserved by toField.

                                                            @[simp]
                                                            theorem KoalaBear.Fast.toField_qsmul (q : ) (x : Field) :
                                                            toField (q x) = q toField x

                                                            Rational scalar multiplication is preserved by toField.

                                                            @[implicit_reducible, instance 100]

                                                            Field instance transferred from canonical KoalaBear through toField.

                                                            @[implicit_reducible, instance 100]

                                                            Commutative-ring instance inherited from the transferred field structure.

                                                            @[implicit_reducible, instance 100]

                                                            Fast KoalaBear is a non-binary field.