Documentation

CslibFrontier.Foundations.Data.Code.Linear

Linear codes, rate, puncturing, and shortening #

A linear code is a submodule C of the words ι → M, usually with M = F a field MacWilliams and Sloane, Chapter 1. The Hamming distance between two words is the Hamming weight hammingNorm of their difference, and the difference of two codewords is a codeword, so the minimum distance of a linear code is the least weight of a nonzero codeword (Cslib.Code.le_minDist_iff_hammingNorm, Cslib.Code.minDist_eq_iInf_hammingNorm).

This module also provides the finite-code rate (log_|α| |C| / |ι|, equal to finrank F C / |ι| for linear codes over a finite field F), coordinate restriction / puncturing (Code.puncture, Code.punctureLinear), zero-extension along an embedding (Code.extend, Code.extendLinearMap), and shortening (Code.shorten, Code.shortenLinear), together with cardinality/rate bounds for kernels of linear maps.

Main definitions #

Main results #

References #

theorem Cslib.Code.le_minDist_iff_hammingNorm {ι : Type u_1} {R : Type u_2} {M : Type u_3} [Fintype ι] [Ring R] [AddCommGroup M] [Module R M] [DecidableEq M] (C : Submodule R (ι → M)) {d : ℕ∞} :
d ≤ minDist ↑C ↔ ∀ x ∈ C, x ≠ 0 → d ≤ ↑(hammingNorm x)

The minimum distance of a linear code is at least d iff every nonzero codeword has weight at least d.

theorem Cslib.Code.minDist_eq_iInf_hammingNorm {ι : Type u_1} {R : Type u_2} {M : Type u_3} [Fintype ι] [Ring R] [AddCommGroup M] [Module R M] [DecidableEq M] (C : Submodule R (ι → M)) :
minDist ↑C = ⨅ x ∈ C, ⨅ (_ : x ≠ 0), ↑(hammingNorm x)

Minimum weight. The minimum distance of a linear code is the least weight of a nonzero codeword, and ⊤ for the zero code.

noncomputable def Cslib.Code.rate {ι : Type u_1} {α : Type u_2} [Fintype ι] [Fintype α] (C : Set (ι → α)) :

The rate of a code C : Set (ι → α) over a finite alphabet α: log_|α| |C| / |ι|.

theorem Cslib.Code.card_linearCode_eq_pow_finrank {ι : Type u_1} {F : Type u_2} [Finite ι] [Field F] [Fintype F] (C : Submodule F (ι → F)) :

A linear code over a finite field F has cardinality |F| ^ dim F C.

theorem Cslib.Code.rate_linearCode_eq_finrank_div_card {ι : Type u_1} {F : Type u_2} [Fintype ι] [Field F] [Fintype F] (C : Submodule F (ι → F)) :
rate ↑C = ↑(Module.finrank F ↥C) / ↑(Fintype.card ι)

The rate of a linear code over a finite field F equals dim F C / |ι|.

theorem Cslib.Code.card_pow_le_card_ker_mul {ι : Type u_1} {κ : Type u_2} {R : Type u_3} [Fintype ι] [Fintype κ] [Ring R] [Fintype R] (f : (ι → R) →ₗ[R] κ → R) :

Over a finite ring R, |R| ^ |ι| ≤ |ker f| * |R| ^ |κ| for any linear map f : (ι → R) →ₗ[R] (κ → R).

theorem Cslib.Code.pow_sub_le_card_ker {ι : Type u_1} {κ : Type u_2} {R : Type u_3} [Fintype ι] [Fintype κ] [Ring R] [Fintype R] (f : (ι → R) →ₗ[R] κ → R) :

Over a finite ring R (|R| ≥ 1), |R| ^ (|ι| - |κ|) ≤ |ker f|.

theorem Cslib.Code.one_sub_card_div_card_le_rate_ker {ι : Type u_1} {κ : Type u_2} {R : Type u_3} [Fintype ι] [Fintype κ] [Ring R] [Fintype R] [Nontrivial R] (hι : 0 < Fintype.card ι) (f : (ι → R) →ₗ[R] κ → R) :
1 - ↑(Fintype.card κ) / ↑(Fintype.card ι) ≤ rate ↑f.ker

Over a finite nontrivial ring R, rate (ker f) ≥ 1 - |κ| / |ι|.

noncomputable def Cslib.Code.extend {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Zero M] (emb : κ ↪ ι) (z : κ → M) :
ι → M

Extending a word z : κ → M by zero outside the image of an embedding emb : κ ↪ ι.

@[simp]
theorem Cslib.Code.extend_emb {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Zero M] (emb : κ ↪ ι) (z : κ → M) (j : κ) :
extend emb z (emb j) = z j

Extension agrees with z on the retained coordinates.

theorem Cslib.Code.extend_of_notMem {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Zero M] (emb : κ ↪ ι) (z : κ → M) {i : ι} (hi : ∀ (j : κ), emb j ≠ i) :
extend emb z i = 0

Extension vanishes outside the image of emb.

theorem Cslib.Code.extend_eq_sum {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Fintype κ] [DecidableEq ι] [AddCommMonoid M] (emb : κ ↪ ι) (z : κ → M) (i : ι) :
extend emb z i = ∑ j : κ, if emb j = i then z j else 0

Finite-sum representation of extend emb z as an indicator sum over emb.

theorem Cslib.Code.extend_injective {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Zero M] (emb : κ ↪ ι) :

Zero-extension along an embedding is injective.

noncomputable def Cslib.Code.extendLinearMap {κ : Type u_1} {ι : Type u_2} (R : Type u_3) (M : Type u_4) [Semiring R] [AddCommMonoid M] [Module R M] (emb : κ ↪ ι) :
(κ → M) →ₗ[R] ι → M

Zero-extension as an R-linear map (κ → M) →ₗ[R] (ι → M).

@[simp]
theorem Cslib.Code.extendLinearMap_apply {κ : Type u_1} {ι : Type u_2} (R : Type u_3) (M : Type u_4) [Semiring R] [AddCommMonoid M] [Module R M] (emb : κ ↪ ι) (z : κ → M) :
(extendLinearMap R M emb) z = extend emb z

Applying extendLinearMap agrees with extend.

theorem Cslib.Code.hammingNorm_extend {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Fintype κ] [Fintype ι] [Zero M] [DecidableEq M] (emb : κ ↪ ι) (z : κ → M) :

Zero-extension preserves Hamming weight.

theorem Cslib.Code.hammingDist_extend {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Fintype κ] [Fintype ι] [AddCommGroup M] [DecidableEq M] (emb : κ ↪ ι) (z₁ z₂ : κ → M) :
hammingDist (extend emb z₁) (extend emb z₂) = hammingDist z₁ z₂

Zero-extension preserves Hamming distance.

def Cslib.Code.puncture {κ : Type u_1} {ι : Type u_2} {α : Type u_3} (C : Set (ι → α)) (emb : κ → ι) :
Set (κ → α)

Puncturing a code C along coordinate map emb : κ → ι: restricting words to emb.

def Cslib.Code.punctureLinear {κ : Type u_1} {ι : Type u_2} {R : Type u_3} {M : Type u_4} [Semiring R] [AddCommMonoid M] [Module R M] (C : Submodule R (ι → M)) (emb : κ → ι) :
Submodule R (κ → M)

Puncturing a linear code C along emb : κ → ι.

@[simp]
theorem Cslib.Code.mem_puncture {κ : Type u_1} {ι : Type u_2} {α : Type u_3} {C : Set (ι → α)} {emb : κ → ι} {y : κ → α} :
y ∈ puncture C emb ↔ ∃ x ∈ C, x ∘ emb = y

Membership in a punctured code puncture C emb.

@[simp]
theorem Cslib.Code.mem_punctureLinear {κ : Type u_1} {ι : Type u_2} {R : Type u_3} {M : Type u_4} [Semiring R] [AddCommMonoid M] [Module R M] {C : Submodule R (ι → M)} {emb : κ → ι} {y : κ → M} :
y ∈ punctureLinear C emb ↔ ∃ x ∈ C, x ∘ emb = y

Membership in a punctured linear code punctureLinear C emb.

@[simp]
theorem Cslib.Code.coe_punctureLinear {κ : Type u_1} {ι : Type u_2} {R : Type u_3} {M : Type u_4} [Semiring R] [AddCommMonoid M] [Module R M] (C : Submodule R (ι → M)) (emb : κ → ι) :
↑(punctureLinear C emb) = puncture (↑C) emb

Coercion of punctureLinear C emb agrees with puncture (C : Set _) emb.

def Cslib.Code.shorten {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Zero M] (C : Set (ι → M)) (emb : κ ↪ ι) :
Set (κ → M)

Shortening a code C along an embedding emb : κ ↪ ι: words whose zero-extension lies in C.

noncomputable def Cslib.Code.shortenLinear {κ : Type u_1} {ι : Type u_2} {R : Type u_3} {M : Type u_4} [Semiring R] [AddCommMonoid M] [Module R M] (C : Submodule R (ι → M)) (emb : κ ↪ ι) :
Submodule R (κ → M)

Shortening a linear code C along emb : κ ↪ ι.

@[simp]
theorem Cslib.Code.mem_shorten {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Zero M] (C : Set (ι → M)) (emb : κ ↪ ι) (z : κ → M) :
z ∈ shorten C emb ↔ extend emb z ∈ C

Membership in shorten C emb means the zero-extension lies in C.

@[simp]
theorem Cslib.Code.mem_shortenLinear {κ : Type u_1} {ι : Type u_2} {R : Type u_3} {M : Type u_4} [Semiring R] [AddCommMonoid M] [Module R M] (C : Submodule R (ι → M)) (emb : κ ↪ ι) (z : κ → M) :
z ∈ shortenLinear C emb ↔ extend emb z ∈ C

Membership in shortenLinear C emb means the zero-extension lies in C.

@[simp]
theorem Cslib.Code.coe_shortenLinear {κ : Type u_1} {ι : Type u_2} {R : Type u_3} {M : Type u_4} [Semiring R] [AddCommMonoid M] [Module R M] (C : Submodule R (ι → M)) (emb : κ ↪ ι) :
↑(shortenLinear C emb) = shorten (↑C) emb

As a set, shortenLinear C emb equals shorten (C : Set (ι → M)) emb.

theorem Cslib.Code.le_minDist_shorten {κ : Type u_1} {ι : Type u_2} {M : Type u_3} [Fintype κ] [Fintype ι] [AddCommGroup M] [DecidableEq M] (C : Set (ι → M)) (emb : κ ↪ ι) :

Shortening cannot decrease minimum distance.