Basic Theorems About Bitvectors #
This file contains theorems about bitvectors and their coercions to
Nat
and Fin
.
theorem
Bitvec.toNat_append
{m : ℕ}
(xs : Bitvec m)
(b : Bool)
:
Bitvec.toNat (Vector.append xs (b ::ᵥ Vector.nil)) = Bitvec.toNat xs * 2 + Bitvec.toNat (b ::ᵥ Vector.nil)
theorem
Bitvec.ofNat_succ
{k : ℕ}
{n : ℕ}
:
Bitvec.ofNat (Nat.succ k) n = Vector.append (Bitvec.ofNat k (n / 2)) (decide (n % 2 = 1) ::ᵥ Vector.nil)
theorem
Bitvec.addLsb_eq_twice_add_one
{x : ℕ}
{b : Bool}
:
Bitvec.addLsb x b = 2 * x + bif b then 1 else 0
theorem
Bitvec.toNat_eq_foldr_reverse
{n : ℕ}
(v : Bitvec n)
:
Bitvec.toNat v = List.foldr (flip Bitvec.addLsb) 0 (List.reverse (Vector.toList v))
theorem
Bitvec.toFin_le_toFin_of_le
{n : ℕ}
{v₀ : Bitvec n}
{v₁ : Bitvec n}
(h : v₀ ≤ v₁)
:
Bitvec.toFin v₀ ≤ Bitvec.toFin v₁