Skip to content

feat(InformationTheory): linear codes over finite fields and minimum distance properties#38014

Open
cduenasnavarro wants to merge 8 commits intoleanprover-community:masterfrom
cduenasnavarro:my-feature-branch
Open

feat(InformationTheory): linear codes over finite fields and minimum distance properties#38014
cduenasnavarro wants to merge 8 commits intoleanprover-community:masterfrom
cduenasnavarro:my-feature-branch

Conversation

@cduenasnavarro
Copy link
Copy Markdown

@cduenasnavarro cduenasnavarro commented Apr 13, 2026

Define linear codes over a finite field F as finite-dimensional subspaces of Fin n → F,
together with their minimum Hamming distance.

Main definitions:

  • LinearCode
  • minDist
  • LinearCodeWithDist
  • hammingSphere

Main results:

  • minDist_eq_sInf_pairwiseDist: characterisation of the minimum distance via pairwise distances
  • disjoint_spheres: Hamming spheres of radius t around distinct codewords are disjoint
    if 2 * t < d

Pending:

  • Choosing an adequate book reference

Open in Gitpod

@github-actions github-actions bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Apr 13, 2026
@github-actions
Copy link
Copy Markdown

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 awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 13, 2026

PR summary 00dbc4ec64

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.InformationTheory.Coding.LinearCode (new file) 1531

Declarations diff

+ LinearCode
+ LinearCodeWithDist
+ disjoint_spheres
+ hammingSphere
+ minDist
+ minDist_eq_sInf_pairwiseDist

You can run this locally as follows
## summary with just the declaration names:
./scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions bot added the t-measure-probability Measure theory / Probability theory label Apr 13, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 13, 2026

✅ PR Title Formatted Correctly

The title of this PR has been updated to match our commit style conventions.
Thank you!

@cduenasnavarro cduenasnavarro changed the title Creation of InformationTheory/Coding/LinearCode.lean feat(InformationTheory): linear codes over finite fields and minimum distance properties Apr 13, 2026
Copy link
Copy Markdown
Collaborator

@vihdzp vihdzp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursory remarks, not all too familiar with the maths.


namespace InformationTheory

variable (F : Type*) [Field F] [Fintype F] [DecidableEq F]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Fintype instead of Finite? And why DecidableEq?

/-- 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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we might generally use carrier for something like this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

/-- 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}
Copy link
Copy Markdown
Collaborator

@vihdzp vihdzp Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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


/-- An **$[n, k, d]$-linear code** is an $[n, k]$-linear code with minimum distance at least
`d`. -/
structure LinearCodeWithDist (n k d : ℕ) where
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to extend LinearCode F n k?

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) :
Copy link
Copy Markdown
Collaborator

@vihdzp vihdzp Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@rkirov
Copy link
Copy Markdown
Contributor

rkirov commented Apr 14, 2026

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.

@rkirov
Copy link
Copy Markdown
Contributor

rkirov commented Apr 14, 2026

oh also, c₁ ∈ C.code.space could be c₁ ∈ C.code or even c₁ ∈ C if you add the right typeclass instances, leaving to the mathlib experts to decide what is more ideomatic, but it would read better.


## Main definitions

* `LinearCode`: An $[n, k]_q$-linear code, i.e., a $k$-dimensional subspace of $\mathbb{F}_q^n$.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `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}$.

namespace InformationTheory

variable (F : Type*) [Field F] [Fintype F] [DecidableEq F]
variable {q : ℕ} (hq : Fintype.card F = q)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like q and hq are used

/-- 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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-measure-probability Measure theory / Probability theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants