Documentation

CslibFrontier.Foundations.Data.BitString.Binary

Bridges between BitString.equivFin and binary numeral views #

Cslib.BitString.equivFin n numbers n-bit strings Fin n → Bool with 0 as the least significant coordinate. This module connects equivFin n to the list-based numeral views Cslib.BitString.lsbValue (least significant bit first) and Cslib.BitString.binaryValue (most significant bit first), as well as Nat.ofBits and Nat.testBit, without adding a BitString.Basic dependency to the list-level modules BitString.Counter or BitString.List.Binary.

Main results #

equivFin agrees with Nat.ofBits on n-bit words.

@[simp]
theorem Cslib.BitString.equivFin_symm_apply {n : ℕ} (k : Fin (2 ^ n)) (i : Fin n) :
(equivFin n).symm k i = (↑k).testBit ↑i

The i-th bit of (equivFin n).symm k is the i-th binary digit of k.

theorem Cslib.BitString.testBit_equivFin {n : ℕ} (x : BitString n) (i : Fin n) :
(↑((equivFin n) x)).testBit ↑i = x i

The i-th binary digit of equivFin n x is x i.

Reading the bits of an n-bit word in order gives its number in equivFin n.

Reading the bits of an input, least significant first, gives its number in the order of BitString.equivFin.

Reading little-endian digits (lsbValue) is reading the reversed digits most significant first (binaryValue).

The fixed-width word lowBits n k equals the bits of (equivFin n).symm k.

@[simp]
theorem Cslib.BitString.lsbValue_lowBits {n x : ℕ} (hx : x < 2 ^ n) :

For any x < 2 ^ n, reading lowBits n x with lsbValue recovers x.

@[simp]

Converting a bit word to a natural with lsbValue and re-encoding with lowBits of the same length recovers the original word.

theorem Cslib.BitString.val_equivFin_add {n : ℕ} (a b : BitString n) :
↑((equivFin n) (a + b)) = ↑((equivFin n) a) ^^^ ↑((equivFin n) b)

Addition in BitString n is bitwise XOR (^^^) on equivFin n coordinates.