Counting, numbering and adding bit strings #
There are 2 ^ n strings of n bits (BitString.card), numbered 0, …, 2 ^ n - 1 by reading
their bits as binary digits, least significant first (BitString.equivFin).
Bits form the two-element Boolean ring (Mathlib's BooleanRing Bool), in which a + b = (a ^^ b)
and a * b = (a && b), so bit strings ι → Bool form an additive group under coordinatewise
exclusive or, the vector space 𝔽₂ⁿ of O'Donnell, Chapter 1:
(x + y) i = (x i ^^ y i) holds by definition. Every bit string is its own negative
(BitString.add_self). Translating by a fixed string is the permutation Equiv.addLeft x.
Throughout the library, bit strings are added with +, while single bits, such as the values of
Boolean functions, are combined with ^^.
Main definitions #
Cslib.BitString.equivFin: the numbering of the strings ofnbits byFin (2 ^ n).Cslib.BitString.fstBits,Cslib.BitString.sndBits: the two parts of an appended word.Cslib.BitString.indexBits: a finite index represented in⌈log₂ n⌉bits.
Main results #
Cslib.BitString.card: the number of strings ofnbits.Cslib.BitString.val_equivFin_eq_sum: the unsigned value as a sum of binary digits.Cslib.BitString.val_equivFin_cons: a new first bit is the least significant binary digit.Cslib.BitString.val_equivFin_succ,Cslib.BitString.decide_equivFin_le_succ: numbering and comparing words by their highest bit.Cslib.BitString.indexBits_injective: distinct finite indices have distinct encodings.Cslib.BitString.add_self,Cslib.BitString.add_cancel_left,Cslib.BitString.add_cancel_right: every bit string is its own negative.
References #
There are 2 ^ n strings of n bits.
The first a bits of Fin.append u v are u.
The last b bits of Fin.append u v are v.
Comparing words of n + 1 bits: x ≤ y when the last bit of x is below that of y, or when
they are equal and x ≤ y on the first n bits.
Distinct finite indices have distinct binary numerals.