The Hamming geometry of the Boolean cube #
Points of the cube ι → Bool are compared by Mathlib's Hamming distance, the number of
coordinates where they differ. The Boolean operations act on points coordinatewise, and their
geometry is exact. For f g h : ι → Bool on a finite set ι:
- conjunction and disjunction sort a pair coordinatewise, so the distances from
f ∧ gandf ∨ gto anyhadd up to those fromfandg(Cslib.BitString.hammingDist_and_add_hammingDist_or); f ∧ gandf ∨ glie on geodesics fromftog(Cslib.BitString.hammingDist_add_hammingDist_and,Cslib.BitString.hammingDist_add_hammingDist_or), and both are1-Lipschitz in each argument;- adding a fixed point, which is the coordinatewise exclusive or, and negation are isometries
(
Cslib.BitString.hammingDist_add_right,Cslib.BitString.hammingDist_not); - the cube is a median algebra for the coordinatewise majority
m(f,g,h) = (f ∧ g) ∨ (g ∧ h) ∨ (h ∧ f)(Cslib.BitString.median), the lattice median of the distributive latticeι → Bool: it satisfies the majority law, symmetry and the associative law, and it distributes over itself. The median lies between any two of its arguments and minimizes the total distance to the three of them.
The truth tables of Boolean functions are points of the cube (ι → Bool) → Bool. The parities on
two distinct sets S and T disagree exactly where the parity on the symmetric difference
S ∆ T is true, which happens on half of the inputs, so they differ on exactly half of the inputs
(Cslib.BitString.two_mul_hammingDist_parityOn). Two distinct coordinate projections x ↦ x i
and x ↦ x j are the parities on {i} and {j}, so they differ on exactly half of the inputs
(Cslib.BitString.two_mul_hammingDist_proj), and so do their shifts f + x_i and f + x_j by
any common function f (Cslib.BitString.two_mul_hammingDist_add_proj), however complicated f
is.
Main definitions #
Cslib.BitString.median: the coordinatewise majority of three points.
Main results #
Cslib.BitString.hammingDist_and_add_hammingDist_or: conjunction and disjunction sort.Cslib.BitString.hammingDist_add_hammingDist_and,Cslib.BitString.hammingDist_add_hammingDist_or: geodesics.Cslib.BitString.hammingDist_and_le,Cslib.BitString.hammingDist_or_le: Lipschitz gates.Cslib.BitString.hammingDist_add_right,Cslib.BitString.hammingDist_add_left,Cslib.BitString.hammingDist_not: isometries.Cslib.BitString.median_self_left,Cslib.BitString.median_swap_left,Cslib.BitString.median_swap_right,Cslib.BitString.median_assoc: the median algebra laws.Cslib.BitString.median_median_distrib: distributivity.Cslib.BitString.hammingDist_add_hammingDist_median,Cslib.BitString.hammingDist_median_le: betweenness and minimality of the median.Cslib.BitString.two_mul_hammingDist_parityOn: distinct parities are half the cube apart.Cslib.BitString.two_mul_hammingDist_proj,Cslib.BitString.hammingDist_proj_div,Cslib.BitString.two_mul_hammingDist_add_proj: projections and their shifts are half the cube apart.
References #
- [F. J. MacWilliams, N. J. A. Sloane, The Theory of Error-Correcting Codes] [MWS77]
The median #
Conjunction and disjunction #
Conjunction and disjunction sort a pair, so their distances to any h add up to those of
the pair.
The conjunction lies on a geodesic from f to g.
The disjunction lies on a geodesic from f to g.
Conjunction is 1-Lipschitz in each argument.
Disjunction is 1-Lipschitz in each argument.
Isometries #
Adding a fixed point, coordinatewise the exclusive or, is an isometry.
Adding a fixed point on the left is an isometry.
Negation is an isometry.
Distances to the median #
The median lies between any two of its arguments.
The median minimizes the total distance to its three arguments.
Parities and coordinate projections #
Distinct parities differ on exactly half of the inputs: they disagree where the parity on the symmetric difference is true.
Two distinct coordinate projections differ on exactly half of the inputs: they are the
parities on {i} and {j}.
The relative Hamming distance between two distinct coordinate projections is one half.
Shifts of distinct projections by a common function differ on half of the inputs, however
complicated the common function f is.