Documentation

HexModArith.Ntt.Plan

Executable characterization of a nonzero power of two.

Equations
Instances For
    def Hex.ZMod64.ExactOrder {p : Nat} [Bounds p] (root : ZMod64 p) (n : Nat) :

    Exact-order certificate specialized to a power-of-two order. For a power-of-two n, an nth root has exact order n precisely when it is not already an (n / 2)th root (with the order-one case separated).

    Equations
    Instances For
      @[instance_reducible]
      instance Hex.ZMod64.instDecidableExactOrder {p : Nat} [Bounds p] (root : ZMod64 p) (n : Nat) :
      Equations
      theorem Hex.ZMod64.ExactOrder.pow_eq_one {p n : Nat} [Bounds p] {root : ZMod64 p} (h : root.ExactOrder n) :
      root ^ n = 1

      An exact-order certificate includes the root-of-unity equation.

      theorem Hex.ZMod64.ExactOrder.half {p n : Nat} [Bounds p] {root : ZMod64 p} (h : root.ExactOrder n) :
      n = 1 root ^ (n / 2) 1

      The nontrivial half-order clause of a power-of-two exact-order certificate.

      structure Hex.ZMod64.NttTwiddle (p : Nat) [Bounds p] :

      A transform twiddle and the quotient preconditioner floor(value * 2^64 / p) used by Shoup multiplication.

      Instances For

        Build a twiddle and its Shoup preconditioner.

        Equations
        Instances For
          @[simp]
          theorem Hex.ZMod64.NttTwiddle.precon_toNat {p : Nat} [Bounds p] (value : ZMod64 p) :

          The Shoup quotient fits in one word and is stored without wraparound.

          structure Hex.ZMod64.NttPlan (p n : Nat) [Bounds p] [PrimeModulus p] :

          A reusable radix-two NTT plan.

          • length_pow_two : (k : Nat), n = 2 ^ k

            The requested transform length is a power of two.

          • length_dvd : n p - 1

            The transform length divides the order of the prime field's unit group.

          • root : ZMod64 p

            Primitive transform root.

          • root_order : self.root.ExactOrder n

            The root has exact power-of-two order n.

          • invRoot : ZMod64 p

            Inverse transform root.

          • invRoot_eq : self.invRoot = self.root⁻¹

            The stored inverse root is the multiplicative inverse of root.

          • invLength : ZMod64 p

            Inverse of the transform length modulo p.

          • invLength_eq : self.invLength = (↑n)⁻¹

            The stored length inverse is the inverse of the natural cast of n.

          • forwardTwiddles : Array (NttTwiddle p)

            Reusable forward root powers and Shoup preconditioners.

          • forward_size : self.forwardTwiddles.size = n

            There is one forward power for every exponent below n.

          • forward_value (i : Nat) (hi : i < n) : self.forwardTwiddles[i].value = self.root ^ i

            Every stored forward twiddle is the corresponding root power.

          • inverseTwiddles : Array (NttTwiddle p)

            Reusable inverse-root powers and Shoup preconditioners.

          • inverse_size : self.inverseTwiddles.size = n

            There is one inverse power for every exponent below n.

          • inverse_value (i : Nat) (hi : i < n) : self.inverseTwiddles[i].value = self.invRoot ^ i

            Every stored inverse twiddle is the corresponding inverse-root power.

          Instances For
            def Hex.ZMod64.NttPlan.Valid {p : Nat} [Bounds p] (n : Nat) (root : ZMod64 p) :

            Everything checked by NTT plan construction.

            Equations
            Instances For
              def Hex.ZMod64.NttPlan.twiddles {p : Nat} [Bounds p] (root : ZMod64 p) (n : Nat) :

              Table of the first n powers of a root, with Shoup preconditioners.

              Equations
              Instances For
                @[simp]
                theorem Hex.ZMod64.NttPlan.twiddles_size {p : Nat} [Bounds p] (root : ZMod64 p) (n : Nat) :
                (twiddles root n).size = n

                The twiddle table has the requested length.

                @[simp]
                theorem Hex.ZMod64.NttPlan.twiddles_value {p : Nat} [Bounds p] (root : ZMod64 p) (n i : Nat) (hi : i < n) :
                (twiddles root n)[i].value = root ^ i

                Looking up a twiddle exposes the corresponding root power.

                def Hex.ZMod64.NttPlan.build? {p n : Nat} [Bounds p] [PrimeModulus p] (root : ZMod64 p) :

                Validate a requested root and build all reusable transform data.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  theorem Hex.ZMod64.NttPlan.build?_isSome {p n : Nat} [Bounds p] [PrimeModulus p] (root : ZMod64 p) :
                  (build? root).isSome = decide (Valid n root)

                  Plan construction succeeds exactly when the requested length and root pass all validation checks.

                  theorem Hex.ZMod64.NttPlan.build?_root {p n : Nat} [Bounds p] [PrimeModulus p] {root : ZMod64 p} {plan : NttPlan p n} (h : build? root = some plan) :
                  plan.root = root

                  A successful plan records the supplied root.

                  theorem Hex.ZMod64.NttPlan.invRoot_mul_root {p n : Nat} [Bounds p] [PrimeModulus p] (plan : NttPlan p n) (hroot : plan.root 0) :
                  plan.invRoot * plan.root = 1

                  A successful plan exposes the validated inverse root.