Documentation

CslibFrontier.Foundations.Data.BitString.BitVec

Bit strings as BitVec words #

Both Cslib.BitString w (Fin w → Bool, numbered via Cslib.BitString.equivFin w) and Lean's BitVec w index bits from the least significant position 0. The computable equivalence Cslib.BitString.equivBitVec identifies the two representations (getLsbD_equivBitVec, getElem_equivBitVec, equivBitVec_symm_apply, equivBitVec_getLsbD), preserves unsigned natural values (toNat_equivBitVec_eq_equivFin), and relates the BooleanRing zero and complement on BitString w to 0#w and bitwise complement ~~~ (equivBitVec_zero, equivBitVec_symm_zero, equivBitVec_compl).

Main definitions #

Main results #

Computable equivalence BitString w ≃ BitVec w, reading bit i of x : BitString w as least-significant bit i of BitVec w.

theorem Cslib.BitString.getLsbD_equivBitVec {w : ℕ} (x : BitString w) (i : Fin w) :
(equivBitVec x).getLsbD ↑i = x i

Bit i (least significant first) of equivBitVec x is x i.

@[simp]
theorem Cslib.BitString.getElem_equivBitVec {w : ℕ} (x : BitString w) (i : ℕ) (hi : i < w) :
(equivBitVec x)[i] = x ⟨i, hi⟩

Indexing equivBitVec x at i < w returns x ⟨i, hi⟩.

@[simp]
theorem Cslib.BitString.equivBitVec_symm_apply {w : ℕ} (v : BitVec w) (i : Fin w) :
equivBitVec.symm v i = v[↑i]

Bit i of equivBitVec.symm v is v[i.val].

theorem Cslib.BitString.equivBitVec_getLsbD {w : ℕ} (v : BitVec w) :
(equivBitVec fun (i : Fin w) => v.getLsbD ↑i) = v

Rebuilding a BitVec w from the bits v.getLsbD i.val via equivBitVec recovers v.

equivBitVec and equivFin assign the same unsigned natural value to every w-bit string.

@[simp]

equivBitVec maps the zero bit string (all false) to 0#w.

@[simp]

equivBitVec.symm maps 0#w to the zero bit string.

@[simp]

equivBitVec maps Boolean complement xᶜ to BitVec bitwise complement ~~~.