Volume of a Hamming ball:
OpenEssentialCodingTheory.card_hammingBallcoding-theorycombinatorics
Let be a finite alphabet with symbols, and let . For a word and a radius , the Hamming ball is the set of words that differ from in at most coordinates. Its size is
The -th term counts the words at distance exactly from : choose the differing coordinates, then one of the other symbols in each.
Preamble
import Mathlib.InformationTheory.Hamming import Mathlib.Analysis.SpecialFunctions.Log.Base open Finset
Formal statement
namespace EssentialCodingTheory
theorem card_hammingBall {α : Type*} [Fintype α] [DecidableEq α] {n : ℕ}
(x : Fin n → α) (e : ℕ) :
(univ.filter fun y : Fin n → α => hammingDist x y ≤ e).card =
∑ i ∈ range (e + 1), n.choose i * (Fintype.card α - 1) ^ i := by sorry
end EssentialCodingTheorySource
V. Guruswami, A. Rudra, M. Sudan, Essential Coding Theory (web draft), https://cse.buffalo.edu/faculty/atri/courses/coding-theory/book/web-coding-book.pdf, §1.7, p. 21, equation (1.18) in the proof of Theorem 1.7.2; Hamming ball from Definition 1.6.1, p. 19.
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
For every finite type with decidable equality, every natural number , every word , and every natural number :
The symbols mean the following:
- is any finite type (the alphabet). Equality on is decidable. is the number of elements of .
- is the set of all functions , i.e. all length- words over . is any fixed element of this set.
- is the Hamming distance: the number of coordinates with .
- The left side is the number of words (including itself) that differ from in at most coordinates. The inequality is non-strict.
- The sum on the right runs over , which is terms. All arithmetic is in the natural numbers.
- is the binomial coefficient. It equals when .
- is truncated subtraction: it equals when and when . Also .
Edge cases the statement includes:
- : the terms with are zero. The right side is then , and the left side counts all of .
- : has exactly one element, the empty word. The left side is , and the right side is for every .
- : the right side is the single term .
- : the right side is .
- (empty ) and : no word exists, so the statement is vacuously true for these parameters.
- and : this falls under the case above.
The statement has no hypotheses beyond the finiteness of and the decidability of equality on it. The preamble also imports a logarithm library, but the statement does not use it.
Human review
Confirmed by the mission captain (proposal self-audit).