Documentation

Complexity.Foundations.Data.Code.HammingBound

Hamming balls, the Hamming bound and the Gilbert–Varshamov bound #

The words ∀ i, β i at Hamming distance exactly r from a word x are obtained by choosing the r positions where they differ and a different letter at each, so there are ∑_{|S| = r} ∏_{i ∈ S} (|β i| - 1) of them, whatever x is (Cslib.Code.card_filter_hammingDist_eq); over an alphabet of q letters at each of n positions this is C(n, r) (q - 1) ^ r (Cslib.Code.card_filter_hammingDist_eq_choose_mul_pow). Balls of radius r around the words of a code of minimum distance Cslib.Code.minDist more than 2 r are disjoint, so the code has at most q ^ n / V words, where V is the size of a ball: the Hamming bound (Cslib.Code.card_mul_card_filter_hammingDist_le_le_prod, Cslib.Code.card_mul_sum_choose_le_of_two_mul_lt_minDist) [Ham50], MacWilliams and Sloane, Chapter 1, Theorem 6. Conversely, the balls of radius d - 1 around a largest code of minimum distance at least d cover every word, so some code of minimum distance at least d has at least q ^ n / V words, where V is the size of a ball of radius d - 1: the Gilbert–Varshamov bound (Cslib.Code.exists_le_minDist_and_prod_le_card_mul_card_filter_hammingDist_lt, Cslib.Code.exists_le_minDist_and_pow_le_card_mul_sum_choose) [Gil52], by Gilbert's greedy argument; Varshamov proved the same bound for linear codes [Var57].

Main results #

References #

theorem Cslib.Code.card_filter_filter_ne_eq {ι : Type u_1} [Fintype ι] [DecidableEq ι] {β : ι → Type u_2} [(i : ι) → Fintype (β i)] [(i : ι) → DecidableEq (β i)] (x : (i : ι) → β i) (S : Finset ι) :
{y : (i : ι) → β i | {i : ι | x i ≠ y i} = S}.card = ∏ i ∈ S, (Fintype.card (β i) - 1)

The words differing from x exactly at the positions S: a different letter at each position of S.

theorem Cslib.Code.card_filter_hammingDist_eq {ι : Type u_1} [Fintype ι] [DecidableEq ι] {β : ι → Type u_2} [(i : ι) → Fintype (β i)] [(i : ι) → DecidableEq (β i)] (x : (i : ι) → β i) (r : ℕ) :
{y : (i : ι) → β i | hammingDist x y = r}.card = ∑ S ∈ Finset.powersetCard r Finset.univ, ∏ i ∈ S, (Fintype.card (β i) - 1)

The size of a Hamming sphere: the words at distance r from x. It does not depend on x.

theorem Cslib.Code.card_filter_hammingDist_eq_choose_mul_pow {ι : Type u_1} [Fintype ι] [DecidableEq ι] {β : ι → Type u_2} [(i : ι) → Fintype (β i)] [(i : ι) → DecidableEq (β i)] {q : ℕ} (hq : ∀ (i : ι), Fintype.card (β i) = q) (x : (i : ι) → β i) (r : ℕ) :
{y : (i : ι) → β i | hammingDist x y = r}.card = (Fintype.card ι).choose r * (q - 1) ^ r

Over an alphabet of q letters at each of n positions, a Hamming sphere of radius r has C(n, r) (q - 1) ^ r words.

theorem Cslib.Code.card_filter_hammingDist_le_eq_sum {ι : Type u_1} [Fintype ι] [DecidableEq ι] {β : ι → Type u_2} [(i : ι) → Fintype (β i)] [(i : ι) → DecidableEq (β i)] (x : (i : ι) → β i) (r : ℕ) :
{y : (i : ι) → β i | hammingDist x y ≤ r}.card = ∑ j ∈ Finset.range (r + 1), {y : (i : ι) → β i | hammingDist x y = j}.card

The size of a Hamming ball is the sum of the sizes of the spheres.

theorem Cslib.Code.card_mul_card_filter_hammingDist_le_le_prod {ι : Type u_1} [Fintype ι] [DecidableEq ι] {β : ι → Type u_2} [(i : ι) → Fintype (β i)] [(i : ι) → DecidableEq (β i)] {C : Finset ((i : ι) → β i)} {r : ℕ} (hC : 2 * ↑r < minDist ↑C) (x₀ : (i : ι) → β i) :
C.card * {y : (i : ι) → β i | hammingDist x₀ y ≤ r}.card ≤ ∏ i : ι, Fintype.card (β i)

The Hamming bound: a code of minimum distance more than 2 r has at most ∏ i, |β i| words in all of its balls of radius r together.

theorem Cslib.Code.card_mul_sum_choose_le_of_two_mul_lt_minDist {ι : Type u_1} [Fintype ι] {β : ι → Type u_2} [(i : ι) → Fintype (β i)] [(i : ι) → DecidableEq (β i)] {q : ℕ} (hq : ∀ (i : ι), Fintype.card (β i) = q) {C : Finset ((i : ι) → β i)} {r : ℕ} (hC : 2 * ↑r < minDist ↑C) :
C.card * ∑ j ∈ Finset.range (r + 1), (Fintype.card ι).choose j * (q - 1) ^ j ≤ q ^ Fintype.card ι

The Hamming bound [Ham50] over a q-letter alphabet at each of n positions: a code of minimum distance more than 2 r has at most q ^ n / V words, where V = ∑_{j ≤ r} C(n, j) (q - 1) ^ j is the size of a ball of radius r.

theorem Cslib.Code.exists_le_minDist_and_prod_le_card_mul_card_filter_hammingDist_lt {ι : Type u_1} [Fintype ι] [DecidableEq ι] {β : ι → Type u_2} [(i : ι) → Fintype (β i)] [(i : ι) → DecidableEq (β i)] {d : ℕ} (hd : 0 < d) (x₀ : (i : ι) → β i) :
∃ (C : Finset ((i : ι) → β i)), ↑d ≤ minDist ↑C ∧ ∏ i : ι, Fintype.card (β i) ≤ C.card * {y : (i : ι) → β i | hammingDist x₀ y < d}.card

The Gilbert–Varshamov bound [Gil52]: for d ≥ 1 there is a code of minimum distance at least d which has at least ∏ i, |β i| / V words, where V is the size of a ball of radius d - 1. A largest such code works: its balls of radius d - 1 cover every word, since a word at distance at least d from every codeword could be added to it.

theorem Cslib.Code.exists_le_minDist_and_pow_le_card_mul_sum_choose {ι : Type u_1} [Fintype ι] {β : ι → Type u_2} [(i : ι) → Fintype (β i)] [(i : ι) → DecidableEq (β i)] {q : ℕ} (hq : ∀ (i : ι), Fintype.card (β i) = q) {d : ℕ} (hd : 0 < d) :
∃ (C : Finset ((i : ι) → β i)), ↑d ≤ minDist ↑C ∧ q ^ Fintype.card ι ≤ C.card * ∑ j ∈ Finset.range d, (Fintype.card ι).choose j * (q - 1) ^ j

The Gilbert–Varshamov bound [Gil52] over a q-letter alphabet at each of n positions: for d ≥ 1 some code of minimum distance at least d has at least q ^ n / V words, where V = ∑_{j < d} C(n, j) (q - 1) ^ j is the size of a ball of radius d - 1.