Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Generalized Hamming bound: k≤n−log⁡q∑i≤⌊(d−1)/2⌋(ni)(q−1)ik \le n - \log_q \sum_{i \le \lfloor (d-1)/2 \rfloor} \binom{n}{i}(q-1)^ik≤n−logq​∑i≤⌊(d−1)/2⌋​(in​)(q−1)i

Proved
EssentialCodingTheory.generalized_hamming_bound

by chaikon · Oct 14, 2026 · Mathlib 0df444a (Lean v4.33.1)

coding-theorycombinatoricsinformation-theory

Let α\alphaα be a finite alphabet with q=∣α∣q = |\alpha|q=∣α∣ symbols, let n,d≥0n, d \ge 0n,d≥0, and let C⊆αnC \subseteq \alpha^nC⊆αn be a code in which any two distinct codewords differ in at least ddd coordinates. Then the dimension k=log⁡q∣C∣k = \log_q |C|k=logq​∣C∣ of CCC satisfies

k  ≤  n−log⁡q(∑i=0⌊(d−1)/2⌋(ni)(q−1)i).k \;\le\; n - \log_q \Bigl( \sum_{i=0}^{\lfloor (d-1)/2 \rfloor} \binom{n}{i} (q-1)^i \Bigr).k≤n−logq​(i=0∑⌊(d−1)/2⌋​(in​)(q−1)i).

In particular this holds for every (n,k,d)q(n, k, d)_q(n,k,d)q​ code, i.e. every code of minimum distance exactly ddd. Logarithms are real; the statement imposes no hypothesis q≥2q \ge 2q≥2 or C≠∅C \ne \emptysetC=∅, and with the convention log⁡qx=0\log_q x = 0logq​x=0 for q≤1q \le 1q≤1 or x=0x = 0x=0 it remains true in those degenerate cases.

Preamble
import Mathlib.InformationTheory.Hamming
import Mathlib.Analysis.SpecialFunctions.Log.Base
open Finset
Formal statement
namespace EssentialCodingTheory
theorem generalized_hamming_bound {α : Type*} [Fintype α] [DecidableEq α] {n d : ℕ}
    (C : Finset (Fin n → α))
    (hC : ∀ c₁ ∈ C, ∀ c₂ ∈ C, c₁ ≠ c₂ → d ≤ hammingDist c₁ c₂) :
    Real.logb (Fintype.card α) C.card ≤
      n - Real.logb (Fintype.card α)
        ((∑ i ∈ range ((d - 1) / 2 + 1), n.choose i * (Fintype.card α - 1) ^ i : ℕ) : ℝ) := by
  sorry
end EssentialCodingTheory
Source
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, Theorem 1.7.2 (Hamming Bound for any d); definitions: code 1.2.1 (p. 5), dimension 1.2.3 (p. 6), Hamming distance 1.3.3 (p. 8), minimum distance 1.4.1 (p. 12), (n,k,d)_q code 1.7.1 (p. 20).
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

The statement concerns a finite alphabet α\alphaα, with no further structure assumed beyond being finite and having decidable equality. Write q=∣α∣q = |\alpha|q=∣α∣ for its size. Note that qqq may be 000 or 111. The other inputs are:

  • natural numbers nnn and ddd, with no restrictions: d=0d = 0d=0, n=0n = 0n=0 and d>nd > nd>n are all allowed;
  • a finite set CCC of words of length nnn over α\alphaα, that is, C⊆αnC \subseteq \alpha^nC⊆αn.

The single hypothesis is that any two distinct words c1≠c2c_1 \neq c_2c1​=c2​ in CCC have Hamming distance dH(c1,c2)≥dd_H(c_1, c_2) \ge ddH​(c1​,c2​)≥d. Here dH(c1,c2)d_H(c_1, c_2)dH​(c1​,c2​) is the number of coordinates 1≤j≤n1 \le j \le n1≤j≤n where c1c_1c1​ and c2c_2c2​ differ. If d≤1d \le 1d≤1 this hypothesis holds for every CCC. If CCC has at most one element it holds for every ddd.

Set t=⌊(d−˙1)/2⌋t = \lfloor (d \mathbin{\dot-} 1)/2 \rfloort=⌊(d−˙​1)/2⌋, where −˙\dot-−˙​ is truncated natural-number subtraction, so t=0t = 0t=0 when d=0d = 0d=0 or d=1d = 1d=1. Define the natural number

V  =  ∑i=0t(ni) (q−˙1)i.V \;=\; \sum_{i=0}^{t} \binom{n}{i}\,(q \mathbin{\dot-} 1)^i .V=i=0∑t​(in​)(q−˙​1)i.

In this sum, q−˙1=0q \mathbin{\dot-} 1 = 0q−˙​1=0 when q=0q = 0q=0, and 00=10^0 = 100=1. Terms with i>ni > ni>n are 000 because (ni)=0\binom{n}{i} = 0(in​)=0 for them. Since the i=0i = 0i=0 term is 111, V≥1V \ge 1V≥1.

The theorem states the real-number inequality

log⁡q∣C∣  ≤  n−log⁡qV,where log⁡qx:=ln⁡xln⁡q.\log_q |C| \;\le\; n - \log_q V, \qquad\text{where } \log_q x := \frac{\ln x}{\ln q}.logq​∣C∣≤n−logq​V,where logq​x:=lnqlnx​.

This logarithm follows total-function conventions:

  • ln⁡0=0\ln 0 = 0ln0=0, so if C=∅C = \emptysetC=∅ the left side is 000 and the claim becomes log⁡qV≤n\log_q V \le nlogq​V≤n.
  • When q∈{0,1}q \in \{0, 1\}q∈{0,1}, ln⁡q=0\ln q = 0lnq=0 and division by zero gives 000. Every log⁡q\log_qlogq​ term is then 000, and the claim reduces to 0≤n0 \le n0≤n.
  • When q≥2q \ge 2q≥2 and C≠∅C \neq \emptysetC=∅, the inequality is equivalent to ∣C∣⋅V≤qn|C| \cdot V \le q^n∣C∣⋅V≤qn.
Human review
  • Endorsed by marwahaha · Oct 14, 2026

  • Endorsed by chaikon · Oct 14, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me