diff --git a/src/Init/Data/BitVec/Lemmas.lean b/src/Init/Data/BitVec/Lemmas.lean index f9ff5a6a7a..7a779cbcf3 100644 --- a/src/Init/Data/BitVec/Lemmas.lean +++ b/src/Init/Data/BitVec/Lemmas.lean @@ -1391,6 +1391,11 @@ theorem shiftLeft_ofNat_eq {x : BitVec w} {k : Nat} : x <<< (BitVec.ofNat w k) = /-! ### ushiftRight -/ +@[simp] theorem ushiftRight_eq' (x : BitVec w₁) (y : BitVec w₂) : + x >>> y = x >>> y.toNat := by rfl + +theorem ushiftRight_ofNat_eq {x : BitVec w} {k : Nat} : x >>> (BitVec.ofNat w k) = x >>> (k % 2^w) := rfl + @[simp, bv_toNat] theorem toNat_ushiftRight (x : BitVec n) (i : Nat) : (x >>> i).toNat = x.toNat >>> i := rfl @@ -1514,13 +1519,9 @@ theorem msb_ushiftRight {x : BitVec w} {n : Nat} : case succ nn ih => simp [BitVec.ushiftRight_eq, getMsbD_ushiftRight, BitVec.msb, ih, show nn + 1 > 0 by omega] -/-! ### ushiftRight reductions from BitVec to Nat -/ - @[simp] -theorem ushiftRight_eq' (x : BitVec w₁) (y : BitVec w₂) : - x >>> y = x >>> y.toNat := by rfl - -theorem ushiftRight_ofNat_eq {x : BitVec w} {k : Nat} : x >>> (BitVec.ofNat w k) = x >>> (k % 2^w) := rfl +theorem ushiftRight_self (n : BitVec w) : n >>> n.toNat = 0#w := by + simp [BitVec.toNat_eq, Nat.shiftRight_eq_div_pow, Nat.lt_two_pow_self, Nat.div_eq_of_lt] /-! ### sshiftRight -/ diff --git a/src/Std/Tactic/BVDecide/Normalize/BitVec.lean b/src/Std/Tactic/BVDecide/Normalize/BitVec.lean index 6b77a93d1e..864843c6b1 100644 --- a/src/Std/Tactic/BVDecide/Normalize/BitVec.lean +++ b/src/Std/Tactic/BVDecide/Normalize/BitVec.lean @@ -278,6 +278,10 @@ theorem BitVec.ushiftRight_zero' (n : BitVec w) : n >>> 0#w' = n := by simp only [(· >>> ·)] simp +@[bv_normalize] +theorem BitVec.ushiftRight_self (n : BitVec w) : n >>> n = 0#w := by + simp + theorem BitVec.zero_lt_iff_zero_neq (a : BitVec w) : (0#w < a) ↔ (a ≠ 0#w) := by constructor <;> simp_all only [BitVec.lt_def, BitVec.toNat_ofNat, Nat.zero_mod, ne_eq, BitVec.toNat_eq] <;> diff --git a/tests/lean/run/bv_decide_rewriter.lean b/tests/lean/run/bv_decide_rewriter.lean index 20e7cac962..b29811ca0f 100644 --- a/tests/lean/run/bv_decide_rewriter.lean +++ b/tests/lean/run/bv_decide_rewriter.lean @@ -101,6 +101,9 @@ example (x : BitVec 16) : !(x.ult 0) := by bv_normalize example (x : BitVec 16) : (x < 1) ↔ (x = 0) := by bv_normalize example (x : BitVec 16) : (x.ult 1) = (x == 0) := by bv_normalize +-- ushiftRight_self +example (x : BitVec 16) : (x >>> x) == 0 := by bv_normalize + section example (x y : BitVec 256) : x * y = y * x := by