Documentation

CslibFrontier.Foundations.FieldTheory.Finite.HornerCoordinates

Horner evaluation of binary coordinate words #

hornerBits evaluates a polynomial whose coefficients are coordinate words, using a supplied multiplication operation. Coefficients are indexed in increasing degree; evaluation processes them from highest to lowest degree and retains one accumulator. This is the evaluator used by the Justesen code family, shared with its native workspace implementation.

fieldOfBits_hornerBits identifies the result with polynomial evaluation whenever the supplied multiplication agrees with multiplication in the chosen binary-field basis.

def Cslib.BinaryField.hornerBits (b : ℕ) (mul : List Bool → List Bool → List Bool) (x : List Bool) {k : ℕ} (coeff : Fin k → List Bool) :

Evaluate coefficient words in increasing-degree order using Horner's rule. Missing bits are zero and each addition returns exactly b coordinates; the empty polynomial returns [].

theorem Cslib.BinaryField.hornerBits_zero (b : ℕ) (mul : List Bool → List Bool → List Bool) (x : List Bool) (coeff : Fin 0 → List Bool) :
hornerBits b mul x coeff = []

The polynomial with no coefficients evaluates to [].

theorem Cslib.BinaryField.hornerBits_succ (b : ℕ) (mul : List Bool → List Bool → List Bool) (x : List Bool) {k : ℕ} (coeff : Fin (k + 1) → List Bool) :
hornerBits b mul x coeff = BitString.listXor b [coeff 0, mul (hornerBits b mul x fun (i : Fin k) => coeff i.succ) x]

Horner's step: the value is the constant coefficient plus x times the value of the remaining coefficients, with exactly b coordinates.

theorem Cslib.BinaryField.hornerBits_eq_iterate (b : ℕ) (mul : List Bool → List Bool → List Bool) (x : List Bool) (coeff : ℕ → List Bool) (k : ℕ) :
(hornerBits b mul x fun (i : Fin k) => coeff ↑i) = ((fun (s : ℕ × List Bool) => (s.1 - 1, BitString.listXor b [coeff (s.1 - 1), mul s.2 x]))^[k] (k, [])).2

Horner's fold can be executed with a descending counter and one accumulator. The coefficient function is queried only at indices below k; no list of indices is allocated.

theorem Cslib.BinaryField.fieldOfBits_hornerBits {F : Type u_1} [Field F] [Algebra (ZMod 2) F] {b k : ℕ} (B : Module.Basis (Fin b) (ZMod 2) F) {mul : List Bool → List Bool → List Bool} (hmul : ∀ (a b_1 : List Bool), fieldOfBits B (mul a b_1) = fieldOfBits B a * fieldOfBits B b_1) (x : List Bool) (coeff : Fin k → List Bool) :
fieldOfBits B (hornerBits b mul x coeff) = ∑ i : Fin k, fieldOfBits B (coeff i) * fieldOfBits B x ^ ↑i

Horner evaluation agrees with the sum of the represented monomials.