Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Batteries/Data/BitVec/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public import Batteries.Data.Int

namespace BitVec

@[simp]
theorem toNat_pow (b : BitVec w) (n : Nat) : (b ^ n).toNat = (b.toNat ^ n) % (2 ^ w) := by
induction n <;> simp_all [Lean.Grind.Semiring.pow_succ]

theorem ofNat_pow (n : Nat) (x d : Nat) : BitVec.ofNat n (x ^ d) = BitVec.ofNat n x ^ d := by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish BitVec functions were more consistent using w for bit width.

Suggested change
theorem ofNat_pow (n : Nat) (x d : Nat) : BitVec.ofNat n (x ^ d) = BitVec.ofNat n x ^ d := by
theorem ofNat_pow (w x d : Nat) : BitVec.ofNat w (x ^ d) = BitVec.ofNat w x ^ d := by

Why isn't this simp?

rw [← toNat_inj, toNat_ofNat, toNat_pow, toNat_ofNat, Nat.pow_mod]

@[simp] theorem toNat_ofFnLEAux (m : Nat) (f : Fin n → Bool) :
(ofFnLEAux m f).toNat = Nat.ofBits f % 2 ^ m := by
simp only [ofFnLEAux]
Expand Down