feat: add BitVec add_self/self_add lemmas (#6848)
This PR adds simp lemmas proving `x + y = x ↔ x = 0` for BitVec, along with symmetries, and then adds these to the bv_normalize simpset.
This commit is contained in:
parent
3c8cf7a905
commit
0c43f05047
3 changed files with 48 additions and 0 deletions
|
|
@ -2586,6 +2586,28 @@ protected theorem sub_left_inj {x y : BitVec w} (z : BitVec w) : (x - z = y - z)
|
|||
protected theorem sub_right_inj {x y : BitVec w} (z : BitVec w) : (z - x = z - y) ↔ x = y := by
|
||||
simp [sub_toAdd]
|
||||
|
||||
/-! ### add self -/
|
||||
|
||||
@[simp]
|
||||
protected theorem add_left_eq_self {x y : BitVec w} : x + y = y ↔ x = 0#w := by
|
||||
conv => lhs; rhs; rw [← BitVec.zero_add y]
|
||||
exact BitVec.add_left_inj y
|
||||
|
||||
@[simp]
|
||||
protected theorem add_right_eq_self {x y : BitVec w} : x + y = x ↔ y = 0#w := by
|
||||
rw [BitVec.add_comm]
|
||||
exact BitVec.add_left_eq_self
|
||||
|
||||
@[simp]
|
||||
protected theorem self_eq_add_right {x y : BitVec w} : x = x + y ↔ y = 0#w := by
|
||||
rw [Eq.comm]
|
||||
exact BitVec.add_right_eq_self
|
||||
|
||||
@[simp]
|
||||
protected theorem self_eq_add_left {x y : BitVec w} : x = y + x ↔ y = 0#w := by
|
||||
rw [BitVec.add_comm]
|
||||
exact BitVec.self_eq_add_right
|
||||
|
||||
/-! ### fill -/
|
||||
|
||||
@[simp]
|
||||
|
|
|
|||
|
|
@ -45,5 +45,25 @@ theorem BitVec.add_right_inj (a b c : BitVec w) : (c + a == c + b) = (a == b) :=
|
|||
theorem BitVec.add_right_inj' (a b c : BitVec w) : (c + a == b + c) = (a == b) := by
|
||||
rw [BitVec.add_comm b c, add_right_inj]
|
||||
|
||||
@[bv_normalize]
|
||||
theorem BitVec.add_left_eq_self (a b : BitVec w) : (a + b == b) = (a == 0#w) := by
|
||||
rw [Bool.eq_iff_iff]
|
||||
simp
|
||||
|
||||
@[bv_normalize]
|
||||
theorem BitVec.add_right_eq_self (a b : BitVec w) : (a + b == a) = (b == 0#w) := by
|
||||
rw [Bool.eq_iff_iff]
|
||||
simp
|
||||
|
||||
@[bv_normalize]
|
||||
theorem BitVec.self_eq_add_right (a b : BitVec w) : (a == a + b) = (b == 0#w) := by
|
||||
rw [Bool.eq_iff_iff]
|
||||
simp
|
||||
|
||||
@[bv_normalize]
|
||||
theorem BitVec.self_eq_add_left (a b : BitVec w) : (a == b + a) = (b == 0#w) := by
|
||||
rw [Bool.eq_iff_iff]
|
||||
simp
|
||||
|
||||
end Frontend.Normalize
|
||||
end Std.Tactic.BVDecide
|
||||
|
|
|
|||
|
|
@ -110,6 +110,12 @@ example (x y z : BitVec 16) : (x + z == z + y) = (x == y) := by bv_normalize
|
|||
example (x y z : BitVec 16) : (z + x == y + z) = (x == y) := by bv_normalize
|
||||
example (x y z : BitVec 16) : (z + x == z + y) = (x == y) := by bv_normalize
|
||||
|
||||
-- add_left_eq_self / add_right_eq_self
|
||||
example (x y : BitVec 16) : (x + y == x) = (y == 0) := by bv_normalize
|
||||
example (x y : BitVec 16) : (x + y == y) = (x == 0) := by bv_normalize
|
||||
example (x y : BitVec 16) : (x == x + y) = (y == 0) := by bv_normalize
|
||||
example (x y : BitVec 16) : (x == y + x) = (y == 0) := by bv_normalize
|
||||
|
||||
section
|
||||
|
||||
example (x y : BitVec 256) : x * y = y * x := by
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue