feat(InformationTheory): linear codes over finite fields and minimum distance properties#38014
feat(InformationTheory): linear codes over finite fields and minimum distance properties#38014cduenasnavarro wants to merge 11 commits intoleanprover-community:masterfrom
Conversation
Welcome new contributor!Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests. We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR. Thank you again for joining our community. |
PR summary 2a556ee342Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
✅ PR Title Formatted CorrectlyThe title of this PR has been updated to match our commit style conventions. |
https://github.com/cduenasnavarro/mathlib4 into my-feature-branch fix pr
…/mathlib4 into my-feature-branch
vihdzp
left a comment
There was a problem hiding this comment.
Cursory remarks, not all too familiar with the maths.
|
|
||
| namespace InformationTheory | ||
|
|
||
| variable (F : Type*) [Field F] [Fintype F] [DecidableEq F] |
There was a problem hiding this comment.
Why Fintype instead of Finite? And why DecidableEq?
There was a problem hiding this comment.
Hi! Thank you for reviewing. Feel free to correct me if I'm missing anything; I'm quite new to lean.
- I used Fintype because it seems to be what is used for finite fields:
https://leanprover-community.github.io/mathlib4_docs/Mathlib/FieldTheory/Finite/Basic.html#FiniteField
Also, Mathlib's Fintype.finite states that Fintypes are Finite:
theorem Fintype.finite{α : Type u_4} (_inst : Fintype α) :
Finite α
- I added DecidableEq because minDist wouldn't compile otherwise due to the requirements of hammingNorm, showing this error:
failed to synthesize instance of type class Fin n → DecidableEq F
| /-- An **$[n, k]_q$-linear code** is a $k$-dimensional subspace of $\mathbb{F}_q^n$. -/ | ||
| structure LinearCode (n k : ℕ) where | ||
| /-- The underlying $k$-dimensional subspace of $\mathbb{F}_q^n$, encoded as `Fin n → F`. -/ | ||
| space : Subspace F (Fin n → F) |
There was a problem hiding this comment.
I believe we might generally use carrier for something like this?
There was a problem hiding this comment.
This reminds me of Module.Grassmannian, which is defined by restricting the rank on the quotient, but there is a TODO to recover the alternative definition that restricts the rank on the space itself. Perhaps this is too far but I would like to see a unified definition of "collection of submodules of the same rank"
There was a problem hiding this comment.
I don't have concrete suggestion as the unification with Module.Grassmannian might be controversial and beyond the scope. I think it is fine to just change it to carrier for now
| /-- The **minimum distance** $d(C)$ of a code $C$ is the infimum of the Hamming weights of its | ||
| non-zero elements. -/ | ||
| noncomputable def minDist {n k : ℕ} (C : LinearCode F n k) : ℕ := | ||
| sInf {w | ∃ x : Fin n → F, x ∈ C.space ∧ x ≠ 0 ∧ w = hammingNorm x} |
There was a problem hiding this comment.
| sInf {w | ∃ x : Fin n → F, x ∈ C.space ∧ x ≠ 0 ∧ w = hammingNorm x} | |
| ⨅ {x : Fin n → F // x ∈ C.space ∧ x ≠ 0}, hammingNorm x.1 |
There was a problem hiding this comment.
The right syntax would be ⨅ x : {x : Fin n → F // x ∈ C.space ∧ x ≠ 0}, hammingNorm x.1, right? But when I change it to that, I can't use ext in the lemma.
|
|
||
| /-- An **$[n, k, d]$-linear code** is an $[n, k]$-linear code with minimum distance at least | ||
| `d`. -/ | ||
| structure LinearCodeWithDist (n k d : ℕ) where |
There was a problem hiding this comment.
Does it make sense to extend LinearCode F n k?
There was a problem hiding this comment.
Okay, I've managed to make that work. It does look cleaner!
| omit [Fintype F] in | ||
| /-- The minimum distance of a code coincides with the infimum of pairwise Hamming distances | ||
| between distinct codewords. -/ | ||
| lemma minDist_eq_sInf_pairwiseDist {n k : ℕ} (C : LinearCode F n k) : |
There was a problem hiding this comment.
Instead of a sInf theorem, I think it might be more reasonable to split this into two: a theorem minDist F C ≤ hammingDist x y, and a theorem ∃ x ∈ C.space, ∃ y ∈ C.space, x ≠ y ∧ hammingDist x y = minDist F C.
There was a problem hiding this comment.
I think this theorem is useful for comparing the pairwise minimum (it's a minimum since the set is finite) and minDist. Anyhow, I'm adding these other two results, in case they are needed.
| rw [hammingDist_eq_hammingNorm x y] | ||
| exact hammingDist_zero_right (-x + y) | ||
|
|
||
| /-- The **Hamming sphere** $S_t(c)$ is the set of all vectors in $\mathbb{F}_q^n$ at Hamming |
There was a problem hiding this comment.
This seems suggestive of some kind of metric space... would it make sense to define a type alias for Fin n → F with the Hamming distance?
There was a problem hiding this comment.
So would adding this
/-- A **word** of length `n` over the field `F`: an arbitrary vector in $\mathbb{F}_q^n$,
equipped with the Hamming distance. -/
abbrev Word (n : ℕ) : Type _ := Hamming (fun _ : Fin n ↦ F)
for future usage be enough?
There was a problem hiding this comment.
I think you need to specify the vector space, just Hamming doesn't compile, if that's what you mean
|
Happy to provide second opinion on the theory of error-correcting codes if needed (also feel free to ignore me as I am not a mathlib contributor). In terms of the theory these are the right first steps. Only questions to consider:
I assume you are working up to hamming bound, which is also the first result in the theory usually. |
|
oh also, |
|
|
||
| ## Main definitions | ||
|
|
||
| * `LinearCode`: An $[n, k]_q$-linear code, i.e., a $k$-dimensional subspace of $\mathbb{F}_q^n$. |
There was a problem hiding this comment.
| * `LinearCode`: An $[n, k]_q$-linear code, i.e., a $k$-dimensional subspace of $\mathbb{F}_q^n$. | |
| * `LinearCode`: An $[n, k]_q$-linear code, i.e., a $k$-dimensional subspace of $\mathbb{F}_{q^n}$. |
There was a problem hiding this comment.
I've always seen it written as (F_q)^n, it's the vector space of n elements, with the elements belonging to F_q
There was a problem hiding this comment.
Oh sorry, I misread this part. I think you are right. Please ignore this
| namespace InformationTheory | ||
|
|
||
| variable (F : Type*) [Field F] [Fintype F] [DecidableEq F] | ||
| variable {q : ℕ} (hq : Fintype.card F = q) |
There was a problem hiding this comment.
It doesn't look like q and hq are used
There was a problem hiding this comment.
They are not used (for now); I added it in case it is needed in the future. In the notation I've seen, it's a explicit parameter in the definition of linear code, so I thought I would explicitly define it
| /-- An **$[n, k]_q$-linear code** is a $k$-dimensional subspace of $\mathbb{F}_q^n$. -/ | ||
| structure LinearCode (n k : ℕ) where | ||
| /-- The underlying $k$-dimensional subspace of $\mathbb{F}_q^n$, encoded as `Fin n → F`. -/ | ||
| space : Subspace F (Fin n → F) |
There was a problem hiding this comment.
This reminds me of Module.Grassmannian, which is defined by restricting the rank on the quotient, but there is a TODO to recover the alternative definition that restricts the rank on the space itself. Perhaps this is too far but I would like to see a unified definition of "collection of submodules of the same rank"
It now looks a bit better ( |
cduenasnavarro
left a comment
There was a problem hiding this comment.
Mostly changes from the comments I've received so far
Define linear codes over a finite field
Fas finite-dimensional subspaces ofFin n → F,together with their minimum Hamming distance.
Main definitions:
LinearCodeminDistLinearCodeWithDisthammingSphereMain results:
minDist_eq_sInf_pairwiseDist: characterisation of the minimum distance via pairwise distancesdisjoint_spheres: Hamming spheres of radiustaround distinct codewords are disjointif
2 * t < dPending: