Documentation

CslibFrontier.Foundations.Data.Code.HammingCode

Shortened binary Hamming codes and distance-3 cube partitions #

If a binary parity-check matrix H : Matrix κ ι Bool has nonzero, pairwise distinct columns, every nonzero word in parityCheckCode H has Hamming weight at least 3, so parityCheckCode H and all of its syndrome cosets syndrome H ⁻¹' {s} have minimum distance at least 3 (three_le_minDist_parityCheckCode_of_injective, minDist_parityCheckCode_le_syndrome_preimage).

Taking column i : Fin n to be the ⌈log₂ (n + 1)⌉-bit binary numeral of i + 1 gives the shortened binary Hamming parity-check matrix hammingCheckMatrix n (at n = 2 ^ m - 1, the classic [2 ^ m - 1, 2 ^ m - 1 - m, 3] Hamming code [MacWilliamsSloane1977, Chapter 1, §7]). Its 2 ^ ⌈log₂ (n + 1)⌉ ≤ max 1 (2 * n) syndrome fibers partition the Boolean cube Fin n → Bool into pairwise-disjoint codes of minimum distance at least 3, formalizing Lemma 1 of [Sergeev2026UniqueDisjointness, §2, p. 3] (exists_partition_minDist_three). Transporting the syndrome coloring along Finset.equivFin colors the subsets of any finite set S : Finset α with at most max 1 (2 * S.card) colors so that distinct subsets of S in the same color class have symmetric difference of size at least 3 (three_le_card_symmDiff_of_finsetHammingSyndrome_eq).

Main definitions #

Main results #

References #

theorem Cslib.Code.minDist_parityCheckCode_le_syndrome_preimage {κ : Type u_1} {ι : Type u_2} {R : Type u_3} [Fintype ι] [CommRing R] [DecidableEq R] (H : Matrix κ ι R) (s : κ → R) :

Every syndrome coset syndrome H ⁻¹' {s} of a parity-check matrix over a commutative ring has minimum distance at least that of parityCheckCode H.

theorem Cslib.Code.three_le_minDist_parityCheckCode_of_injective {κ : Type u_1} {ι : Type u_2} [Fintype ι] {H : Matrix κ ι Bool} (hne : ∀ (i : ι), (fun (k : κ) => H k i) ≠ 0) (hinj : Function.Injective fun (i : ι) (k : κ) => H k i) :

If a binary parity-check matrix H : Matrix κ ι Bool has nonzero, pairwise distinct columns, then parityCheckCode H has minimum distance at least 3.

The parity-check matrix of the shortened binary Hamming code of length n: column i is the ⌈log₂ (n + 1)⌉-bit binary numeral of i + 1 (nonzero and injective). At n = 2 ^ m - 1 (m ≥ 1) this is the standard [2 ^ m - 1, 2 ^ m - 1 - m, 3] binary Hamming parity-check matrix [MacWilliamsSloane1977, Chapter 1, §7]; for general n, its syndrome fibers realize the coset restriction (c, 0⃗) ∈ C_s of [Sergeev2026UniqueDisjointness, §2, Lemma 1, p. 3].

The shortened binary Hamming code parityCheckCode (hammingCheckMatrix n) has minimum distance at least 3.

Every syndrome fiber of hammingCheckMatrix n has minimum distance at least 3.

theorem Cslib.Code.two_pow_clog_succ_le_two_mul {n : ℕ} (hn : 1 ≤ n) :
2 ^ Nat.clog 2 (n + 1) ≤ 2 * n

For 1 ≤ n, the number of Hamming syndromes 2 ^ ⌈log₂ (n + 1)⌉ is at most 2 * n.

theorem Cslib.Code.two_pow_clog_succ_le_max (n : ℕ) :
2 ^ Nat.clog 2 (n + 1) ≤ max 1 (2 * n)

For every n : ℕ, 2 ^ ⌈log₂ (n + 1)⌉ ≤ max 1 (2 * n).

theorem Cslib.Code.exists_partition_minDist_three {n : ℕ} (hn : 1 ≤ n) :
∃ (P : Fin (2 * n) → Set (Fin n → Bool)), Pairwise (Function.onFun Disjoint P) ∧ ⋃ (i : Fin (2 * n)), P i = Set.univ ∧ ∀ (i : Fin (2 * n)), 3 ≤ minDist (P i)

Cube partition into 3-codes ([Sergeev2026UniqueDisjointness, §2, Lemma 1, p. 3]): for 1 ≤ n, the Boolean cube Fin n → Bool can be partitioned into 2 * n pairwise-disjoint subsets each having minimum Hamming distance at least 3.

noncomputable def Cslib.Code.finsetHammingSyndrome {α : Type u_1} [DecidableEq α] (S a : Finset α) :

Hamming syndrome of a subset a inside a finite ground set S : Finset α, obtained by transporting the indicator of a on S along S.equivFin.

theorem Cslib.Code.three_le_card_symmDiff_of_finsetHammingSyndrome_eq {α : Type u_1} [DecidableEq α] {S a b : Finset α} (ha : a ⊆ S) (hb : b ⊆ S) (hab : a ≠ b) (hsyn : finsetHammingSyndrome S a = finsetHammingSyndrome S b) :
3 ≤ (symmDiff a b).card

Two distinct subsets a, b ⊆ S with the same finsetHammingSyndrome S differ on at least 3 elements: 3 ≤ (symmDiff a b).card.