Linear codes
AbbreviationLinear code#✓fully proved
Let \(F\) be a field and \(\iota\) an index set, not necessarily finite. A linear code over \(F\) with coordinates indexed by \(\iota\) is an \(F\)-linear subspace of the space of words, the functions \(\iota \to F\).
Used by 35
Generator and parity-check matrices
DefinitionEncoder of a generator matrix#✓fully proved
Let \(G\) be a \(\kappa \times \iota\) matrix over a field \(F\), with \(\kappa\) finite. The encoder of \(G\) sends a message \(m \in F^\kappa\) to the word \(mG \in F^\iota\) given by \((mG)_j = \sum_{k \in \kappa} m_k G_{kj}\), the combination of the rows of \(G\) with coefficients \(m\).
def encode (G : Matrix κ ι F) (m : κ → F) : ι → F := m ᵥ* G
Used by 8
DefinitionCode generated by a matrix#✓fully proved
Let \(F\) be a field, \(\kappa\) a finite index set, \(\iota\) any index set and \(G\) a \(\kappa \times \iota\) matrix over \(F\). The code generated by \(G\) is the linear code of all words \(m G\) with \(m : \kappa \to F\), the image of the encoder \(m \mapsto m G\); equivalently, the span of the rows of \(G\).
def ofGenerator (G : Matrix κ ι F) : LinearCode F ι := LinearMap.range G.vecMulLinear
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 1 · Used by 8
DefinitionSyndrome#✓fully proved
Let \(F\) be a field, \(\iota\) a finite set and \(\rho\) a set. For a matrix \(H \in F^{\rho \times \iota}\) (a parity-check matrix) and a word \(y \in F^\iota\), the syndrome of \(y\) is the vector \(Hy \in F^\rho\).
def syndrome (H : Matrix ρ ι F) (y : ι → F) : ρ → F := H *ᵥ y
Used by 13
DefinitionCode with a given parity-check matrix#✓fully proved
Let \(F\) be a field, \(\iota\) a finite index set, \(\rho\) any index set and \(H\) a \(\rho \times \iota\) matrix over \(F\). The code with parity-check matrix \(H\) is the linear code of all words \(c : \iota \to F\) whose syndrome \(H c\) is zero, that is, the kernel of \(c \mapsto H c\).
def ofParityCheck (H : Matrix ρ ι F) : LinearCode F ι := LinearMap.ker H.mulVecLin
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 1 · Used by 9
TheoremThe syndrome depends only on the error#✓fully proved
Let \(F\) be a field, \(\iota\) a finite set and \(H\) a parity-check matrix over \(F\) with columns indexed by \(\iota\). If \(c \in F^\iota\) is a codeword of the code with parity-check matrix \(H\) and \(e \in F^\iota\) is any word, then the received word \(c + e\) has the same syndrome as \(e\), that is, \(H(c + e) = He\).
theorem syndrome_add_of_mem {H : Matrix ρ ι F} {c : ι → F} (hc : c ∈ ofParityCheck H)
(e : ι → F) : syndrome H (c + e) = syndrome H e
def ofParityCheck (H : Matrix ρ ι F) : LinearCode F ι := LinearMap.ker H.mulVecLin
CSLibExt/Coding/LinearCode.lean:96
def syndrome (H : Matrix ρ ι F) (y : ι → F) : ρ → F := H *ᵥ y
CSLibExt/Coding/LinearCode.lean:93
Uses 3 · Used by 1
TheoremGenerator/parity-check duality#✓fully proved
Let \(F\) be a field, \(\kappa\) and \(\iota\) finite index sets and \(\rho\) any index set, and let \(G\) be a \(\kappa \times \iota\) matrix and \(H\) a \(\rho \times \iota\) matrix over \(F\). The code generated by \(G\) equals the code with parity-check matrix \(H\) if and only if \(G H^{\mathsf{T}} = 0\) and \(\operatorname{rank} G + \operatorname{rank} H\) equals \(|\iota|\), the length of the code.
theorem ofGenerator_eq_ofParityCheck_iff {G : Matrix κ ι F}
{H : Matrix ρ ι F} :
ofGenerator G = ofParityCheck H ↔ G * Hᵀ = 0 ∧ G.rank + H.rank = Fintype.card ι
def ofGenerator (G : Matrix κ ι F) : LinearCode F ι := LinearMap.range G.vecMulLinear
CSLibExt/Coding/LinearCode.lean:78
def ofParityCheck (H : Matrix ρ ι F) : LinearCode F ι := LinearMap.ker H.mulVecLin
CSLibExt/Coding/LinearCode.lean:96
Uses 5 · Used by 2
Systematic form
TheoremThe systematic encoder copies the message#✓fully proved
Let \(F\) be a field, \(\kappa\) a finite set and \(A\) a \(\kappa \times \rho\) matrix over \(F\). For the systematic generator matrix \(G = [I \mid A]\), whose columns are indexed by the disjoint union \(\kappa \sqcup \rho\), the encoding \(mG\) of every message \(m \in F^\kappa\) agrees with \(m\) on the coordinates in \(\kappa\): \((mG)_i = m_i\) for every \(i \in \kappa\).
theorem encode_fromCols_one_inl (A : Matrix κ ρ F) (m : κ → F) (i : κ) :
encode (fromCols 1 A) m (Sum.inl i) = m i
def encode (G : Matrix κ ι F) (m : κ → F) : ι → F := m ᵥ* G
CSLibExt/Coding/LinearCode.lean:75
Uses 1 · Used by 1
TheoremSystematic generator and parity-check matrices#✓fully proved
Let \(F\) be a field, \(\kappa\) and \(\rho\) finite sets, and \(A\) a \(\kappa \times \rho\) matrix over \(F\). Then the code generated by \(G = [I_\kappa \mid A]\) equals the code with parity-check matrix \(H = [-A^{\mathsf{T}} \mid I_\rho]\), both being codes whose coordinates are indexed by the disjoint union of \(\kappa\) and \(\rho\).
theorem systematic_eq [Fintype ρ] [DecidableEq ρ] (A : Matrix κ ρ F) :
ofGenerator (fromCols (1 : Matrix κ κ F) A) =
ofParityCheck (fromCols (-Aᵀ) (1 : Matrix ρ ρ F))
def ofGenerator (G : Matrix κ ι F) : LinearCode F ι := LinearMap.range G.vecMulLinear
CSLibExt/Coding/LinearCode.lean:78
def ofParityCheck (H : Matrix ρ ι F) : LinearCode F ι := LinearMap.ker H.mulVecLin
CSLibExt/Coding/LinearCode.lean:96
Uses 6
The dual code
AbbreviationDot product bilinear form#✓fully proved
Let \(F\) be a field and \(\iota\) a finite set. The dot product form is the bilinear form on \(F^\iota\) that sends a pair of words \((x, y)\) to \(x \cdot y = \sum_{i \in \iota} x_i y_i\).
abbrev _root_.Cslib.CodingTheory.dotForm : LinearMap.BilinForm F (ι → F) := dotProductBilin F F
DefinitionDual code#✓fully proved
Let \(F\) be a field and \(\iota\) a finite set. The dual \(C^\perp\) of a linear code \(C \subseteq F^\iota\) is the linear code of all words \(x \in F^\iota\) with \(x \cdot c = \sum_{i \in \iota} x_i c_i = 0\) for every codeword \(c \in C\).
noncomputable def dual (C : LinearCode F ι) : LinearCode F ι := dotForm.orthogonal C
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
abbrev _root_.Cslib.CodingTheory.dotForm : LinearMap.BilinForm F (ι → F) := dotProductBilin F F
CSLibExt/Coding/LinearCode.lean:215
Uses 2 · Used by 3
TheoremDimension of the dual code#✓fully proved
Let \(F\) be a field and \(\iota\) a finite set. For every linear code \(C \subseteq F^\iota\), \(\dim C + \dim C^\perp = |\iota|\), where \(C^\perp\) is the dual code.
theorem finrank_add_finrank_dual (C : LinearCode F ι) :
finrank F C + finrank F (dual C) = Fintype.card ι
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
noncomputable def dual (C : LinearCode F ι) : LinearCode F ι := dotForm.orthogonal C
CSLibExt/Coding/LinearCode.lean:233
Uses 3
TheoremDual of the code generated by a matrix#✓fully proved
Let \(G\) be a matrix over a field \(F\) with finitely many rows and finitely many columns. Then the dual of the code generated by \(G\) (the span of its rows) is the code with parity-check matrix \(G\) (the words \(x\) with \(Gx = 0\)).
theorem dual_ofGenerator [Fintype κ] (G : Matrix κ ι F) :
dual (ofGenerator G) = ofParityCheck G
noncomputable def dual (C : LinearCode F ι) : LinearCode F ι := dotForm.orthogonal C
CSLibExt/Coding/LinearCode.lean:233
def ofGenerator (G : Matrix κ ι F) : LinearCode F ι := LinearMap.range G.vecMulLinear
CSLibExt/Coding/LinearCode.lean:78
def ofParityCheck (H : Matrix ρ ι F) : LinearCode F ι := LinearMap.ker H.mulVecLin
CSLibExt/Coding/LinearCode.lean:96
Uses 7 · Used by 1
TheoremDual of the code with a given parity-check matrix#✓fully proved
Let \(H\) be a matrix over a field \(F\) with finitely many rows and finitely many columns. Then the dual of the code with parity-check matrix \(H\) (the words \(x\) with \(Hx = 0\)) is the code generated by \(H\) (the span of its rows).
theorem dual_ofParityCheck [Fintype ρ] (H : Matrix ρ ι F) :
dual (ofParityCheck H) = ofGenerator H
noncomputable def dual (C : LinearCode F ι) : LinearCode F ι := dotForm.orthogonal C
CSLibExt/Coding/LinearCode.lean:233
def ofParityCheck (H : Matrix ρ ι F) : LinearCode F ι := LinearMap.ker H.mulVecLin
CSLibExt/Coding/LinearCode.lean:96
def ofGenerator (G : Matrix κ ι F) : LinearCode F ι := LinearMap.range G.vecMulLinear
CSLibExt/Coding/LinearCode.lean:78
Uses 6
Minimum distance and minimum weight
DefinitionMinimum distance#✓fully proved
The minimum distance of a linear code \(C\) of finite length is the least Hamming distance (number of coordinates where they differ) between two distinct codewords of \(C\), taken in \(\mathbb{N} \cup \{\infty\}\); it is \(\infty\) if \(C\) has at most one codeword.
noncomputable def minDist (C : LinearCode F ι) : ℕ∞ :=
⨅ (c₁ ∈ C) (c₂ ∈ C) (_ : c₁ ≠ c₂), (hammingDist c₁ c₂ : ℕ∞)
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 1 · Used by 14
DefinitionMinimum weight#✓fully proved
The minimum weight of a linear code \(C\) of finite length is the least weight of a nonzero codeword of \(C\), where the weight of a word is its number of nonzero coordinates; it is taken in \(\mathbb{N} \cup \{\infty\}\) and is \(\infty\) if \(C\) has no nonzero codeword.
noncomputable def minWeight (C : LinearCode F ι) : ℕ∞ :=
⨅ (c ∈ C) (_ : c ≠ 0), (hammingNorm c : ℕ∞)
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 1 · Used by 5
TheoremHamming distance is the weight of the difference#✓fully proved
Let \(F\) be a field and \(\iota\) a finite set. For all words \(x, y \in F^\iota\), the Hamming distance between \(x\) and \(y\) (the number of coordinates where they differ) equals the Hamming weight of \(x - y\) (its number of nonzero coordinates).
theorem _root_.Cslib.CodingTheory.hammingDist_eq_hammingNorm_sub (x y : ι → F) :
hammingDist x y = hammingNorm (x - y)
TheoremMinimum distance equals minimum weight#✓fully proved
For a linear code of finite length over a field, the minimum distance equals the minimum weight.
theorem minDist_eq_minWeight (C : LinearCode F ι) : C.minDist = C.minWeight
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 4 · Used by 3
Syndrome decoding
DefinitionSyndrome decoding#✓fully proved
Syndrome decoding with a lookup table from syndromes to error patterns: subtract the
error pattern the table assigns to the syndrome of the received word.
def syndromeDecode (H : Matrix ρ ι F) (table : (ρ → F) → ι → F) (y : ι → F) : ι → F :=
y - table (syndrome H y)
def syndrome (H : Matrix ρ ι F) (y : ι → F) : ρ → F := H *ᵥ y
CSLibExt/Coding/LinearCode.lean:93
Uses 1 · Used by 2
DefinitionSyndrome table correct up to a radius#✓fully proved
Let \(H\) be a \(\rho \times \iota\) matrix over a field \(F\), with \(\iota\) finite, and let \(t\) be a natural number. A syndrome table for \(H\), that is, a map \(T\) from syndromes \(s \in F^\rho\) to error patterns \(T(s) \in F^\iota\), is correct up to radius \(t\) when, for every word \(e \in F^\iota\) of Hamming weight at most \(t\), the word \(T(He)\) has the same syndrome as \(e\), that is \(H \, T(He) = He\), and has Hamming weight at most \(t\).
This is weaker than asking for minimum-weight coset leaders, and equivalent to it inside the radius when \(2t < d\), where \(d\) is the minimum distance of the code with parity-check matrix \(H\) (each coset then holds at most one word of weight at most \(t\)). Outside the radius the table is unconstrained, so for heavier errors the decoder's output need not even be a codeword.
def IsSyndromeTable (H : Matrix ρ ι F) (t : ℕ) (table : (ρ → F) → ι → F) : Prop :=
∀ e : ι → F, hammingNorm e ≤ t →
syndrome H (table (syndrome H e)) = syndrome H e ∧ hammingNorm (table (syndrome H e)) ≤ t
def syndrome (H : Matrix ρ ι F) (y : ι → F) : ρ → F := H *ᵥ y
CSLibExt/Coding/LinearCode.lean:93
TheoremSyndrome decoding corrects every error of weight at most \(t\)#✓fully proved
Let \(H\) be a parity-check matrix over a field \(F\), let \(C\) be the code with parity-check matrix \(H\), let \(d \in \mathbb{N} \cup \{\infty\}\) be its minimum distance, and let \(t \in \mathbb{N}\) with \(2t < d\). If a syndrome table is correct up to radius \(t\) for \(H\), then for every codeword \(c \in C\) and every word \(e\) of Hamming weight at most \(t\), syndrome decoding with this table sends the received word \(c + e\) to \(c\).
The error pattern the table returns differs from the true error by a codeword of weight at most \(2t\), which must be zero.
theorem syndromeDecode_add_of_hammingNorm_le {H : Matrix ρ ι F} {t : ℕ} {table : (ρ → F) → ι → F}
(hT : IsSyndromeTable H t table) (ht : (2 * t : ℕ∞) < (ofParityCheck H).minDist)
{c e : ι → F} (hc : c ∈ ofParityCheck H) (he : hammingNorm e ≤ t) :
syndromeDecode H table (c + e) = c
def IsSyndromeTable (H : Matrix ρ ι F) (t : ℕ) (table : (ρ → F) → ι → F) : Prop :=
∀ e : ι → F, hammingNorm e ≤ t →
syndrome H (table (syndrome H e)) = syndrome H e ∧ hammingNorm (table (syndrome H e)) ≤ t
CSLibExt/Coding/LinearCode.lean:349
def ofParityCheck (H : Matrix ρ ι F) : LinearCode F ι := LinearMap.ker H.mulVecLin
CSLibExt/Coding/LinearCode.lean:96
def syndromeDecode (H : Matrix ρ ι F) (table : (ρ → F) → ι → F) (y : ι → F) : ι → F :=
y - table (syndrome H y)
CSLibExt/Coding/LinearCode.lean:341
Uses 10 · Used by 1
TheoremSyndrome decoding up to half the minimum distance#✓fully proved
Let \(H\) be a parity-check matrix over a field \(F\) such that the code \(C\) with parity-check matrix \(H\) has finite minimum distance \(d\), and let \(t = \lfloor (d - 1)/2 \rfloor\). If a syndrome table is correct up to radius \(t\) for \(H\), then for every codeword \(c \in C\) and every word \(e\) of Hamming weight at most \(t\), syndrome decoding with this table sends the received word \(c + e\) to \(c\).
theorem syndromeDecode_add_of_minDist_eq {H : Matrix ρ ι F} {d : ℕ}
(hd : (ofParityCheck H).minDist = d) {table : (ρ → F) → ι → F}
(hT : IsSyndromeTable H ((d - 1) / 2) table) {c e : ι → F} (hc : c ∈ ofParityCheck H)
(he : hammingNorm e ≤ (d - 1) / 2) : syndromeDecode H table (c + e) = c
def ofParityCheck (H : Matrix ρ ι F) : LinearCode F ι := LinearMap.ker H.mulVecLin
CSLibExt/Coding/LinearCode.lean:96
def IsSyndromeTable (H : Matrix ρ ι F) (t : ℕ) (table : (ρ → F) → ι → F) : Prop :=
∀ e : ι → F, hammingNorm e ≤ t →
syndrome H (table (syndrome H e)) = syndrome H e ∧ hammingNorm (table (syndrome H e)) ≤ t
CSLibExt/Coding/LinearCode.lean:349
def syndromeDecode (H : Matrix ρ ι F) (table : (ρ → F) → ι → F) (y : ι → F) : ι → F :=
y - table (syndrome H y)
CSLibExt/Coding/LinearCode.lean:341
Uses 6 · Used by 1
TheoremExistence of correct syndrome tables#✓fully proved
Let \(H\) be a matrix over a field \(F\) whose columns are indexed by a finite set. For every natural number \(t\) there is a syndrome table for \(H\) that is correct up to radius \(t\).
theorem exists_isSyndromeTable (H : Matrix ρ ι F) (t : ℕ) : ∃ table, IsSyndromeTable H t table
def IsSyndromeTable (H : Matrix ρ ι F) (t : ℕ) (table : (ρ → F) → ι → F) : Prop :=
∀ e : ι → F, hammingNorm e ≤ t →
syndrome H (table (syndrome H e)) = syndrome H e ∧ hammingNorm (table (syndrome H e)) ≤ t
CSLibExt/Coding/LinearCode.lean:349
Uses 2
DefinitionSyndrome table by exhaustive search#✓fully proved
Let \(F\) be a field, \(\iota\) and \(\rho\) finite sets, \(H\) a \(\rho \times \iota\) parity-check matrix over \(F\), and \(t \in \mathbb{N}\), where the words \(F^\iota\) come with a fixed enumeration. The search table sends a syndrome \(s \in F^\rho\) to the first word \(e \in F^\iota\) in the enumeration with Hamming weight at most \(t\) and syndrome \(He = s\), and to \(0\) if there is no such word.
def searchTable [FinEnum (ι → F)] [Fintype ρ] (H : Matrix ρ ι F) (t : ℕ) (s : ρ → F) : ι → F :=
((FinEnum.toList (ι → F)).find? fun e ↦ decide (hammingNorm e ≤ t ∧ syndrome H e = s)).getD 0
def syndrome (H : Matrix ρ ι F) (y : ι → F) : ρ → F := H *ᵥ y
CSLibExt/Coding/LinearCode.lean:93
Uses 1
The Singleton and Hamming bounds for linear codes
TheoremNumber of codewords of a linear code#✓fully proved
If \(C\) is a linear code of length \(n\) over a finite field \(F\), then exactly \(|F|^{\dim C}\) of the \(|F|^n\) words of length \(n\) lie in \(C\), where \(\dim C\) is the dimension of \(C\) over \(F\).
theorem card_filter_mem (C : LinearCode F (Fin n)) [DecidablePred (· ∈ C)] :
(Finset.univ.filter (· ∈ C)).card = Fintype.card F ^ finrank F C
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 1 · Used by 2
TheoremSingleton bound for linear codes, dimension form#✓fully proved
Let \(C\) be a linear code of length \(n\) over a finite field \(F\), and let \(d \le n\) be a natural number that is at most the minimum distance of \(C\). Then \(\dim C + d \le n + 1\).
The hypothesis \(d \le n\) matters only for the zero code, whose minimum distance is \(\infty\).
theorem finrank_add_le_of_le_minDist [Finite F] {C : LinearCode F (Fin n)} {d : ℕ}
(hdn : d ≤ n) (hd : (d : ℕ∞) ≤ C.minDist) : finrank F C + d ≤ n + 1
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 4 · Used by 1
TheoremMinimum distance is at most the length#✓fully proved
If \(C\) is a linear code of length \(n\) over a field and \(C\) is not the zero subspace, then the minimum distance of \(C\) is finite and at most \(n\).
theorem minDist_le_length {C : LinearCode F (Fin n)} (hC : C ≠ ⊥) : C.minDist ≤ n
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 2 · Used by 1
TheoremSingleton bound for linear codes#✓fully proved
Let \(F\) be a finite field and \(C\) a linear code of length \(n\) and dimension \(k\) over \(F\) that is not the zero subspace. Then the minimum distance of \(C\) is at most \(n - k + 1\).
theorem minDist_le_of_ne_bot [Finite F] {C : LinearCode F (Fin n)} (hC : C ≠ ⊥) :
C.minDist ≤ (n - finrank F C + 1 : ℕ)
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 4 · Used by 1
TheoremHamming bound for linear codes#✓fully proved
Let \(F\) be a finite field with \(q\) elements and \(C\) a linear code of length \(n\) and dimension \(k\) over \(F\). If \(t\) is a natural number such that \(2t\) is less than the minimum distance of \(C\), then
theorem pow_finrank_mul_sum_le_of_lt_minDist {C : LinearCode F (Fin n)} {t : ℕ}
(ht : (2 * t : ℕ∞) < C.minDist) :
Fintype.card F ^ finrank F C *
∑ i ∈ Finset.range (t + 1), n.choose i * (Fintype.card F - 1) ^ i ≤
Fintype.card F ^ n
abbrev LinearCode (F : Type*) [Field F] (ι : Type*) := Submodule F (ι → F)
CSLibExt/Coding/LinearCode.lean:61
Uses 4 · Used by 1
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.