Documentation

CompPoly.Fields.Binary.AdditiveNTT.Impl

Additive NTT Implementation #

Concrete implementation of the Additive NTT algorithm.

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

Converts an Array to a Fin function of a specific size 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
      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)

      Define the mapping explicitly from the index k to the Submodule U.

      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

              Computes the twiddle factor used in the butterfly operation. Corresponds to AdditiveNTT.twiddleFactor.

              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

                Performs one stage of the Additive NTT. This corresponds to NTTStage in the abstract definition: b is the array of coefficients. i is the stage index (0 to r-1).

                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

                  The main computable Additive NTT function. a is the input array of coefficients. r is the number of stages (dimension of the domain). The input array size must be at least 2^r.

                  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

                      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
                        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) :

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

                          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 stores the values of computableTwiddleFactor for this stage, indexed by u.

                                  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

                                          Computable basis for ConcreteBTField k over ConcreteBTField 0. This is the explicit product of Z's.

                                          Instances For
                                            @[reducible, inline]
                                            Instances For
                                              @[implicit_reducible]
                                              @[implicit_reducible]

                                              Test of the computable additive NTT over BTF₃ (an 8-bit binary tower field BTF₃). Input polynomial: p(x) = x (novel coefficients [7, 1, 0, 0]) of size 2^ℓ in BTF₃

                                              • ℓ = 2
                                              • R_rate = 2: Repetition rate, evaluating at S₀ of size 2^(ℓ + R_rate) = 16 points
                                              • r = 2^3 = 8: Dimension of the basis for BTF₃ over GF(2) Output: A function Fin 16 → BTF₃ giving the evaluations of p(x) = x at 16 points in the evaluation domain S₀ defined by the spanning basis elements {β₀, ..., β_{ℓ + 𝓡 - 1}} of BTF₃ over GF(2).
                                              Instances For