Hamming spaces #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
The Hamming metric counts the number of places two members of a (finite) Pi type differ. The Hamming norm is the same as the Hamming metric over additive groups, and counts the number of places a member of a (finite) Pi type differs from zero.
This is a useful notion in various applications, but in particular it is relevant in coding theory, in which it is fundamental for defining the minimum distance of a code.
Main definitions #
hamming_dist x y
: the Hamming distance betweenx
andy
, the number of entries which differ.hamming_norm x
: the Hamming norm ofx
, the number of non-zero entries.hamming β
: a type synonym forΠ i, β i
withdist
andnorm
provided by the above.hamming.to_hamming
,hamming.of_hamming
: functions for casting betweenhamming β
andΠ i, β i
.hamming.normed_add_comm_group
: the Hamming norm forms a normed group onhamming β
.
The Hamming distance function to the naturals.
Equations
- hamming_dist x y = (finset.filter (λ (i : ι), x i ≠ y i) finset.univ).card
Corresponds to dist_self
.
Corresponds to dist_nonneg
.
Corresponds to dist_comm
.
Corresponds to dist_triangle
.
Corresponds to dist_triangle_left
.
Corresponds to dist_triangle_right
.
Corresponds to swap_dist
.
Corresponds to eq_of_dist_eq_zero
.
Corresponds to dist_eq_zero
.
Corresponds to zero_eq_dist
.
Corresponds to dist_ne_zero
.
Corresponds to dist_pos
.
Corresponds to dist_smul
with the discrete norm on α
.
The Hamming weight function to the naturals.
Equations
- hamming_norm x = (finset.filter (λ (i : ι), x i ≠ 0) finset.univ).card
Corresponds to dist_zero_right
.
Corresponds to dist_zero_left
.
Corresponds to norm_nonneg
.
Corresponds to norm_zero
.
Corresponds to norm_eq_zero
.
Corresponds to norm_ne_zero_iff
.
Corresponds to norm_pos_iff
.
Corresponds to dist_eq_norm
.
Type synonym for a Pi type which inherits the usual algebraic instances, but is equipped with
the Hamming metric and norm, instead of pi.normed_add_comm_group
which uses the sup norm.
Instances for hamming
- hamming.inhabited
- hamming.fintype
- hamming.nontrivial
- hamming.has_zero
- hamming.has_neg
- hamming.has_add
- hamming.has_sub
- hamming.has_smul
- hamming.smul_with_zero
- hamming.add_monoid
- hamming.add_comm_monoid
- hamming.add_comm_group
- hamming.module
- hamming.has_dist
- hamming.pseudo_metric_space
- hamming.metric_space
- hamming.has_norm
- hamming.seminormed_add_comm_group
- hamming.normed_add_comm_group
Instances inherited from normal Pi types.
Equations
- hamming.inhabited = {default := λ (i : ι), inhabited.default}
Equations
Equations
Equations
Equations
Equations
API to/from the type synonym.
to_hamming
is the identity function to the hamming
of a type.
Equations
- hamming.to_hamming = equiv.refl (Π (i : ι), β i)
of_hamming
is the identity function from the hamming
of a type.
Equations
Instances equipping hamming
with hamming_norm
and hamming_dist
.
Equations
- hamming.has_dist = {dist := λ (x y : hamming β), ↑(hamming_dist (⇑hamming.of_hamming x) (⇑hamming.of_hamming y))}
Equations
- hamming.pseudo_metric_space = {to_has_dist := {dist := has_dist.dist hamming.has_dist}, dist_self := _, dist_comm := _, dist_triangle := _, edist := λ (x y : hamming β), ↑⟨has_dist.dist x y, _⟩, edist_dist := _, to_uniform_space := ⊥, uniformity_dist := _, to_bornology := {cobounded := ⊥, le_cofinite := _}, cobounded_sets := _}
Equations
- hamming.metric_space = {to_pseudo_metric_space := {to_has_dist := pseudo_metric_space.to_has_dist hamming.pseudo_metric_space, dist_self := _, dist_comm := _, dist_triangle := _, edist := pseudo_metric_space.edist hamming.pseudo_metric_space, edist_dist := _, to_uniform_space := pseudo_metric_space.to_uniform_space hamming.pseudo_metric_space, uniformity_dist := _, to_bornology := pseudo_metric_space.to_bornology hamming.pseudo_metric_space, cobounded_sets := _}, eq_of_dist_eq_zero := _}
Equations
- hamming.has_norm = {norm := λ (x : hamming β), ↑(hamming_norm (⇑hamming.of_hamming x))}
Equations
- hamming.seminormed_add_comm_group = {to_has_norm := hamming.has_norm (λ (i : ι), add_zero_class.to_has_zero (β i)), to_add_comm_group := {add := add_comm_group.add pi.add_comm_group, add_assoc := _, zero := add_comm_group.zero pi.add_comm_group, zero_add := _, add_zero := _, nsmul := add_comm_group.nsmul pi.add_comm_group, nsmul_zero' := _, nsmul_succ' := _, neg := add_comm_group.neg pi.add_comm_group, sub := add_comm_group.sub pi.add_comm_group, sub_eq_add_neg := _, zsmul := add_comm_group.zsmul pi.add_comm_group, zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _, add_comm := _}, to_pseudo_metric_space := hamming.pseudo_metric_space (λ (i : ι) (a b : β i), _inst_2 i a b), dist_eq := _}
Equations
- hamming.normed_add_comm_group = {to_has_norm := seminormed_add_comm_group.to_has_norm hamming.seminormed_add_comm_group, to_add_comm_group := seminormed_add_comm_group.to_add_comm_group hamming.seminormed_add_comm_group, to_metric_space := hamming.metric_space (λ (i : ι) (a b : β i), _inst_2 i a b), dist_eq := _}