Documentation

TauCeti.InformationTheory.Hamming

Hamming support, and Hamming data under coordinate decompositions and reindexing #

This file builds on hammingNorm, hammingDist, and hammingDist_eq_hammingNorm from Mathlib.InformationTheory.Hamming.

The Hamming support of a word x : ι → A is Function.support x, the set of its nonzero coordinates, and its Hamming weight is the number of elements of that support. The first part of this file relates Function.support, its finset version, hammingNorm and hammingDist: the distance from x to y is the weight of y - x, and the weight of a sum is governed by

wt(x + y) + #(supp x ∩ supp y) + #(supp x \ supp (x + y)) = wt x + wt y,

where the last set consists of the coordinates at which y cancels x. It follows that weight is additive on words with disjoint supports; weight is also subadditive. Scaling coordinatewise by c intersects the support with supp c.

The file also records that Hamming weight and distance on a function whose domain is a disjoint union split as sums over the two coordinate types. Weight also splits over a retained coordinate set and its complement. These identities let constructions assembled from independent coordinate blocks reduce their Hamming data to the data of the blocks.

It also proves that Hamming distance and Hamming weight are invariant under relabelling a finite coordinate type along an equivalence, and evaluates a product over the coordinates of a word which only depends on which coordinates vanish; this is how weight monomials X^(n - wt x) Y^(wt x) factor over the coordinates.

Hamming support #

theorem TauCeti.hammingNorm_eq_ncard_support {ι : Type u_1} {A : Type u_2} [Fintype ι] [Zero A] [DecidableEq A] (x : ι → A) :

The Hamming weight of a word is the number of elements of its support.

The Hamming weight of a word is the cardinality of its support, viewed as a finset.

theorem TauCeti.hammingNorm_le_hammingNorm_of_support_subset {ι : Type u_1} {A : Type u_2} [Fintype ι] [Zero A] [DecidableEq A] {B : Type u_3} [Zero B] [DecidableEq B] {x : ι → A} {y : ι → B} (h : Function.support x ⊆ Function.support y) :

A word whose support is contained in the support of another word has at most its weight.

theorem TauCeti.hammingNorm_eq_hammingNorm_of_support_eq {ι : Type u_1} {A : Type u_2} [Fintype ι] [Zero A] [DecidableEq A] {B : Type u_3} [Zero B] [DecidableEq B] {x : ι → A} {y : ι → B} (h : Function.support x = Function.support y) :

Two words with the same support have the same Hamming weight.

theorem TauCeti.hammingDist_eq_ncard_setOf_ne {ι : Type u_1} {β : ι → Type u_3} [Fintype ι] [(i : ι) → DecidableEq (β i)] (x y : (i : ι) → β i) :
hammingDist x y = {i : ι | x i ≠ y i}.ncard

The Hamming distance between two words is the number of coordinates at which they differ.

@[simp]
theorem TauCeti.hammingNorm_neg {ι : Type u_1} {β : ι → Type u_3} [Fintype ι] [(i : ι) → SubtractionMonoid (β i)] [(i : ι) → DecidableEq (β i)] (x : (i : ι) → β i) :

Negation preserves Hamming weight.

theorem TauCeti.hammingDist_eq_hammingNorm_sub {ι : Type u_1} {β : ι → Type u_3} [Fintype ι] [(i : ι) → AddGroup (β i)] [(i : ι) → DecidableEq (β i)] (x y : (i : ι) → β i) :

The Hamming distance from x to y is the Hamming weight of x - y.

theorem TauCeti.hammingDist_eq_hammingNorm_sub' {ι : Type u_1} {β : ι → Type u_3} [Fintype ι] [(i : ι) → AddGroup (β i)] [(i : ι) → DecidableEq (β i)] (x y : (i : ι) → β i) :

The Hamming distance from x to y is the Hamming weight of y - x.

theorem TauCeti.hammingDist_eq_ncard_support_sub {ι : Type u_1} {A : Type u_2} [Fintype ι] [AddGroup A] [DecidableEq A] (x y : ι → A) :

The Hamming distance from x to y is the number of elements of the support of y - x.

theorem TauCeti.hammingNorm_add_le {ι : Type u_1} {β : ι → Type u_3} [Fintype ι] [(i : ι) → AddZeroClass (β i)] [(i : ι) → DecidableEq (β i)] (x y : (i : ι) → β i) :

Hamming weight is subadditive.

The weight of a sum. Coordinates in the support of both words are counted twice on the right, and the coordinates at which y cancels x are lost from the support of x + y.

Words with disjoint supports have additive Hamming weight.

theorem TauCeti.hammingNorm_smul_eq_ncard_inter {ι : Type u_1} {A : Type u_2} [Fintype ι] {R : Type u_3} [Semiring R] [IsCancelMulZero R] [AddCommMonoid A] [Module R A] [Module.IsTorsionFree R A] [DecidableEq A] (c : ι → R) (x : ι → A) :

The weight of a coordinatewise scaling c • x is the number of coordinates at which both c and x are nonzero.

@[simp]
theorem TauCeti.hammingNorm_const {ι : Type u_1} {A : Type u_4} [Fintype ι] [Zero A] [DecidableEq A] (a : A) :

A constant word has full weight unless its constant value is zero.

@[simp]
theorem TauCeti.hammingDist_sumRec {ι : Type u_1} {κ : Type u_2} {β : ι ⊕ κ → Type u_3} [Fintype ι] [Fintype κ] [(z : ι ⊕ κ) → DecidableEq (β z)] (x x' : (i : ι) → β (Sum.inl i)) (y y' : (j : κ) → β (Sum.inr j)) :

The Hamming distance between two pairs of words combined on a disjoint union is the sum of the distances between the respective words.

@[simp]
theorem TauCeti.hammingNorm_sumRec {ι : Type u_1} {κ : Type u_2} {β : ι ⊕ κ → Type u_3} [Fintype ι] [Fintype κ] [(z : ι ⊕ κ) → DecidableEq (β z)] [(z : ι ⊕ κ) → Zero (β z)] (x : (i : ι) → β (Sum.inl i)) (y : (j : κ) → β (Sum.inr j)) :

The Hamming weight of two words combined on a disjoint union is the sum of their weights.

@[simp]
theorem TauCeti.hammingDist_sumElim {ι : Type u_1} {κ : Type u_2} {A : Type u_4} [Fintype ι] [Fintype κ] [DecidableEq A] (x x' : ι → A) (y y' : κ → A) :

The Hamming distance between two pairs of words over a common alphabet, combined on a disjoint union, is the sum of the distances between the respective words.

@[simp]
theorem TauCeti.hammingNorm_sumElim {ι : Type u_1} {κ : Type u_2} {A : Type u_4} [Fintype ι] [Fintype κ] [DecidableEq A] [Zero A] (x : ι → A) (y : κ → A) :

The Hamming weight of two words over a common alphabet, combined on a disjoint union, is the sum of their weights.

theorem TauCeti.hammingNorm_eq_domRestrict_add_domRestrict_compl {ι : Type u_1} {A : ι → Type u_4} [Fintype ι] [(i : ι) → Zero (A i)] [(i : ι) → DecidableEq (A i)] (s : Set ι) [DecidablePred fun (x : ι) => x ∈ s] (x : (i : ι) → A i) :

Hamming weight splits over a retained coordinate set and its complement.

@[simp]
theorem TauCeti.prod_ite_eq_zero_eq_pow_mul_pow_hammingNorm {ι : Type u_1} {M : Type u_4} {β : ι → Type u_5} [Fintype ι] [(i : ι) → Zero (β i)] [(i : ι) → DecidableEq (β i)] [CommMonoid M] (x : (i : ι) → β i) (a b : M) :
(∏ i : ι, if x i = 0 then a else b) = a ^ (Fintype.card ι - hammingNorm x) * b ^ hammingNorm x

A product over the coordinates which takes the value a at the zero coordinates of a word and b elsewhere is a ^ (n - wt x) * b ^ (wt x), where n is the length and wt is the Hamming weight.

theorem Equiv.hammingDist_comp {α : Type u_1} {ι : Type u_2} {κ : Type u_3} [Fintype ι] [Fintype κ] [DecidableEq α] (e : κ ≃ ι) (x y : ι → α) :
hammingDist (x ∘ ⇑e) (y ∘ ⇑e) = hammingDist x y

Relabelling coordinates along an equivalence preserves the Hamming distance.

theorem Equiv.hammingNorm_comp {α : Type u_1} {ι : Type u_2} {κ : Type u_3} [Fintype ι] [Fintype κ] [DecidableEq α] [Zero α] (e : κ ≃ ι) (x : ι → α) :

Relabelling coordinates along an equivalence preserves the Hamming weight.

@[simp]
theorem Equiv.hammingNorm_funLeft {ι : Type u_2} {κ : Type u_3} [Fintype ι] [Fintype κ] {R : Type u_4} {M : Type u_5} [Semiring R] [AddCommMonoid M] [Module R M] [DecidableEq M] (e : κ ≃ ι) (x : ι → M) :

Relabelling a word along an equivalence of finite coordinate types preserves its Hamming weight, when the relabelling is expressed as a linear map between function spaces.

@[simp]
theorem Equiv.hammingDist_funLeft {ι : Type u_2} {κ : Type u_3} [Fintype ι] [Fintype κ] {R : Type u_4} {M : Type u_5} [Semiring R] [AddCommMonoid M] [Module R M] [DecidableEq M] (e : κ ≃ ι) (x y : ι → M) :
hammingDist ((LinearMap.funLeft R M ⇑e) x) ((LinearMap.funLeft R M ⇑e) y) = hammingDist x y

Relabelling two words along an equivalence of finite coordinate types preserves their Hamming distance, when the relabelling is expressed as a linear map between function spaces.