Documentation

CompPoly.Fields.Binary.AdditiveNTT.Executable

Executable additive NTT algorithms #

Generic function-backed and array-backed additive NTT implementations over a finite field, with an explicitly supplied binary-subfield algebra and independent basis vectors. The function-backed transform mirrors the abstract stages; the array-backed transform caches subspace-polynomial constants and twiddle tables.

CompPoly.Fields.Binary.AdditiveNTT.Correctness relates these implementations to the abstract algorithm and its evaluation specification. Concrete tower instances and the compatibility entry point remain in CompPoly.Fields.Binary.AdditiveNTT.Impl.

The coefficient tiling, twiddle factors, and descending butterfly stages follow the Lin–Chung–Han additive NTT presentation in [DP24], Algorithm 2. The array-backed path caches quantities used by these same stages.

References #

def AdditiveNTT.Array.toFinVec {α : Type u_1} (n : ) (arr : Array α) (h : arr.size = n) :
Fin nα

Read an array of length n as a function on Fin n.

Instances For
    def AdditiveNTT.arrayToFinFunction {α : Type u_1} [Zero α] (n : ) (arr : Array α) :
    Fin nα

    Converts an array to a Fin n function, using 0 for missing entries.

    Instances For
      theorem AdditiveNTT.List.prod_finRange_eq_finset_prod {M : Type u_1} [CommMonoid M] {n : } (f : Fin nM) :
      (List.map f (List.finRange n)).prod = i : Fin n, f i

      The product of a function over the list of finite indices equals its finite product.

      def AdditiveNTT.bitsToU {r : } [NeZero r] {L : Type} [Field L] {𝔽q : Type} [Field 𝔽q] [Algebra 𝔽q L] (β : Fin rL) {R_rate : } (i : Fin r) (k : Fin (2 ^ i)) :
      (U 𝔽q β i)

      Map the numeric mask k to the sum of the first i basis vectors selected by its bits, as an element of their linear span.

      Instances For
        def AdditiveNTT.getUElements {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (i : Fin r) :

        Computes the elements of the subspace: U_i = span({β_0, ..., β_{i-1}}).

        Instances For
          def AdditiveNTT.evalWAt {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (i : Fin r) (x : L) :
          L

          Evaluates the subspace vanishing polynomial W_i(x) = ∏_{u ∈ U_i} (x - u).

          Instances For
            def AdditiveNTT.evalNormalizedWAt {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (i : Fin r) (x : L) :
            L

            Evaluates the normalized subspace vanishing polynomial Ŵ_i(x) = W_i(x) / W_i(β_i).

            Instances For
              def AdditiveNTT.computableTwiddleFactor {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (h_ℓ_add_R_rate : + R_rate < r) (i : Fin ) (u : Fin (2 ^ ( + R_rate - i - 1))) :
              L

              Compute the stage-i twiddle factor by summing normalized subspace-polynomial evaluations selected by the bits of u.

              Instances For
                def AdditiveNTT.computableNTTStage {r : } {L : Type} [Field L] {𝔽q : Type} [Field 𝔽q] [Algebra 𝔽q L] (β : Fin rL) {R_rate : } (h_ℓ_add_R_rate : + R_rate < r) [Fact (LinearIndependent 𝔽q β)] (i : Fin ) (b : Fin (2 ^ ( + R_rate))L) :
                Fin (2 ^ ( + R_rate))L

                Perform stage i on the coefficient buffer b, pairing entries whose indices differ in bit i and applying the corresponding twiddle factor.

                Instances For
                  def AdditiveNTT.computableAdditiveNTT {r : } {L : Type} [Field L] {𝔽q : Type} [Field 𝔽q] [Algebra 𝔽q L] (β : Fin rL) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)] {R_rate : } (h_ℓ_add_R_rate : + R_rate < r) (a : Fin (2 ^ )L) :
                  Fin (2 ^ ( + R_rate))L

                  Transform 2 ^ ℓ novel-basis coefficients into 2 ^ (ℓ + R_rate) values by first tiling the coefficients and then applying stages ℓ - 1 down to 0. The basis has length r, and ℓ + R_rate < r bounds the evaluation domain.

                  Instances For
                    def AdditiveNTT.tileCoeffsArray {L : Type} { : } (R_rate : ) (a : Fin (2 ^ )L) :

                    Array-backed coefficient tiling for the fast additive NTT path.

                    Instances For
                      @[irreducible]
                      def AdditiveNTT.evalWAtCachedConstantsLoop {L : Type} [Field L] (constants : Array L) (j : ) (acc : L) :
                      L

                      Starting from acc, iterate acc ↦ acc * (acc + constants[k]) for indices k from j to constants.size - 1. Return acc unchanged when constants.size ≤ j.

                      For j ≤ constants.size, if the initial accumulator is W_j(x) and the remaining constants are W_k(β_k), the result is W_{constants.size}(x).

                      Instances For
                        def AdditiveNTT.evalWAtCachedConstants {L : Type} [Field L] (constants : Array L) (x : L) :
                        L

                        Evaluate a subspace polynomial using cached constants W_k(β_k).

                        Starting from W_0(x) = x, each cached constant advances the recurrence W_{k+1}(x) = W_k(x) * (W_k(x) + W_k(β_k)).

                        Instances For
                          @[irreducible]
                          def AdditiveNTT.subspacePolynomialConstantsArrayLoop {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (i : Fin r) (k : ) (constants : Array L) :

                          Extend the supplied constants array, starting at index k and stopping before i. Each step evaluates the polynomial recurrence encoded by the current array at β_k and appends the result. Return the array unchanged when i ≤ k.

                          If the supplied array has length k and entry j is W_j(β_j) for every j < k, each appended entry has the same interpretation at its index.

                          Instances For
                            def AdditiveNTT.subspacePolynomialConstantsArray {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (i : Fin r) :

                            Precompute the constants W_k(β_k) needed by the recursive subspace polynomial evaluator up to stage i.

                            Instances For
                              def AdditiveNTT.computableNormalizedWValuesArray {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (h_ℓ_add_R_rate : + R_rate < r) (i : Fin ) :

                              Precompute normalized vanishing evaluations used by one stage's twiddle factors.

                              Instances For
                                def AdditiveNTT.computableTwiddleTableArray {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (h_ℓ_add_R_rate : + R_rate < r) (i : Fin ) :

                                Precompute all twiddle factors for one additive NTT stage.

                                The table entry for u is the subset sum of the cached normalized values selected by the set bits of u.

                                Instances For
                                  def AdditiveNTT.computableNTTStageArray {L : Type} [Field L] {R_rate : } (i : Fin ) (twiddles b : Array L) :

                                  Array update for one additive NTT stage.

                                  The twiddles array is intended to store the values of computableTwiddleFactor for this stage, indexed by u. Missing entries in either input array are read as zero.

                                  Instances For
                                    def AdditiveNTT.computableAdditiveNTTFastStages {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (h_ℓ_add_R_rate : + R_rate < r) :

                                    Fast additive NTT stage driver over an Array L state.

                                    The state is expected to contain the initialized output buffer. Each stage updates that buffer using the array transition from computableNTTStageArray.

                                    Instances For
                                      def AdditiveNTT.computableAdditiveNTTFastAction {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (h_ℓ_add_R_rate : + R_rate < r) (a : Fin (2 ^ )L) :

                                      Fast additive NTT array producer as a state action.

                                      Instances For
                                        def AdditiveNTT.computableAdditiveNTTFast {r : } {L : Type} [Field L] (β : Fin rL) {R_rate : } (h_ℓ_add_R_rate : + R_rate < r) (a : Fin (2 ^ )L) :

                                        Fast additive NTT array producer.

                                        Instances For