Finite-field linear codes and Hamming weight enumerators
DefinitionCodingTheoryThis definition bundle establishes the common coding-theory vocabulary used by the mission and intended for reuse across later textbook missions.
A word over an alphabet with coordinate type is a function . When is a field, a linear code is an -submodule of this word space. The standard bilinear form is
and the dual code is the submodule of words orthogonal to every element of .
For a finite field and finite coordinate type, the homogeneous Hamming weight enumerator is defined symbolically over the integers by
Its complex-valued form is defined by evaluating this polynomial. A definitional evaluation lemma records that the two presentations agree.
Formalization Note. The common declarations use the book-wide CodingTheory namespace. The explicit hamming names leave room for later complete, Lee, exact, joint, and split weight enumerators without changing this interface.
import Mathlib.InformationTheory.Hamming
import Mathlib.LinearAlgebra.BilinearForm.Orthogonal
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.Data.Complex.Basic
import Mathlib.Algebra.MvPolynomial.Monad
import Mathlib.LinearAlgebra.Matrix.Notation
namespace CodingTheory
open scoped BigOperators
/-- A word over the alphabet `F`, with coordinates indexed by `ι`. -/
abbrev Word (F ι : Type*) := ι → F
/-- A linear code of length indexed by `ι` over the finite field `F`. -/
abbrev LinearCode (F ι : Type*) [Field F] := Submodule F (Word F ι)
/-- The standard coordinatewise bilinear form on words. -/
def dotForm (F ι : Type*) [Field F] [Fintype ι] :
LinearMap.BilinForm F (Word F ι) :=
dotProductBilin F F
/-- The dual of a linear code under the standard coordinatewise bilinear form. -/
def dualCode (F ι : Type*) [Field F] [Fintype ι]
(C : LinearCode F ι) : LinearCode F ι :=
(dotForm F ι).orthogonal C
/-- The homogeneous Hamming weight enumerator as a bivariate polynomial over `ℤ`. -/
noncomputable def hammingWeightEnumeratorPolynomial (F ι : Type*) [Field F] [Fintype F]
[DecidableEq F] [Fintype ι] [DecidableEq ι]
(C : LinearCode F ι) : MvPolynomial (Fin 2) ℤ :=
letI := Fintype.ofFinite C
∑ c : C,
MvPolynomial.X 0 ^ (Fintype.card ι - hammingNorm (c : ι → F)) *
MvPolynomial.X 1 ^ hammingNorm (c : ι → F)
/-- The homogeneous Hamming weight enumerator evaluated at two complex variables. -/
noncomputable def hammingWeightEnumerator (F ι : Type*) [Field F] [Fintype F]
[DecidableEq F] [Fintype ι] [DecidableEq ι]
(C : LinearCode F ι) (X Y : ℂ) : ℂ :=
MvPolynomial.eval₂Hom (Int.castRingHom ℂ) ![X, Y]
(hammingWeightEnumeratorPolynomial F ι C)
/-- Evaluating the polynomial weight enumerator gives the complex weight enumerator. -/
@[simp] theorem hammingWeightEnumeratorPolynomial_eval
(F ι : Type*) [Field F] [Fintype F] [DecidableEq F]
[Fintype ι] [DecidableEq ι]
(C : LinearCode F ι) (X Y : ℂ) :
MvPolynomial.eval₂Hom (Int.castRingHom ℂ) ![X, Y]
(hammingWeightEnumeratorPolynomial F ι C) =
hammingWeightEnumerator F ι C X Y := rfl
end CodingTheory
Read-back
What the Lean code literally says, in plain math · gpt-5.6-sol
Word. For arbitrary types and , a word over with coordinate set is defined to be an arbitrary function . No algebraic, finiteness, or decidable-equality assumptions are imposed. In particular, if is empty, there is exactly one such word, regardless of .
LinearCode. For arbitrary types and , assuming is a field, a linear code over with coordinate set is defined to be an -submodule of the function space . Neither nor is assumed finite here. Every such code contains the zero word and therefore is nonempty; if is empty, the word space has only its zero element.
dotForm. For arbitrary types and , assuming that is a field and that is finite, dotForm is the -bilinear form on words given by the coordinatewise sum . No decidable-equality assumption on is required. The quantification permits to be empty, in which case the sum is empty and the bilinear form is identically zero.
dualCode. For arbitrary types and , assuming that is a field and that is finite, and for every -submodule , the dual code is defined to be the orthogonal submodule of under the coordinatewise bilinear form: it consists of precisely those words such that for every . No finiteness or decidable-equality assumption on is imposed. Empty is included; then the word space has one element, every displayed sum is zero, and the orthogonal submodule is the whole one-element word space.
hammingWeightEnumeratorPolynomial. For arbitrary types and , assuming that is a field, that both and are finite, and that decidable equalities on both types are supplied, and for every linear code , this defines a polynomial with integer coefficients in two variables indexed by the two-element type , namely variables and . Writing for the Hamming norm of the word , i.e. the number of coordinates at which is nonzero, the polynomial is
The code is finite under the stated assumptions, and the sum ranges over all of its elements, each contributing one monomial; codewords of the same weight therefore contribute repeatedly and produce the corresponding integer coefficient. The subtraction in the first exponent is natural-number subtraction, which is a total operation truncated at zero. The assumptions allow to be empty; then the word space and its only linear code contain exactly one word of weight zero, so the polynomial is .
hammingWeightEnumerator. For arbitrary types and , assuming that is a field, that and are finite, and that decidable equalities on both types are supplied, for every linear code and every pair of complex numbers , the complex Hamming weight enumerator is defined by evaluating the preceding integer-coefficient polynomial after casting its coefficients into , substituting for the variable indexed by and for the variable indexed by . Equivalently, it is
There are no restrictions on or , so zero values are included and exponent-zero factors use the usual convention , including as a monoid power. Empty is included and gives value for every .
hammingWeightEnumeratorPolynomial_eval. For arbitrary types and , assuming that is a field, that and are finite, and that decidable equalities on both types are supplied, for every linear code and all complex numbers , evaluating the integer polynomial by casting integer coefficients into and substituting and for its two variables is equal to hammingWeightEnumerator applied to , which is defined to be that same evaluation. Thus the assertion is the defining equality and places no additional condition on the code or on ; it also includes the empty-coordinate and zero-evaluation cases.
Confirmed by the mission captain (proposal self-audit).