Skip to content

Commit 3d98bfc

Browse files
committed
feat: add BitVec.neg_neg
.. as well as neg_neq_iff_neq_neg.
1 parent 6dd5023 commit 3d98bfc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Init/Data/BitVec/Lemmas.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,22 @@ theorem neg_eq_not_add (x : BitVec w) : -x = ~~~x + 1 := by
12481248
have hx : x.toNat < 2^w := x.isLt
12491249
rw [Nat.sub_sub, Nat.add_comm 1 x.toNat, ← Nat.sub_sub, Nat.sub_add_cancel (by omega)]
12501250

1251+
@[simp]
1252+
theorem neg_neg {x : BitVec w} : - - x = x := by
1253+
by_cases h : x = 0
1254+
· simp [h]
1255+
· simp only [toNat_eq, ofNat_eq_ofNat, toNat_ofNat, Nat.zero_mod] at h
1256+
simp only [toNat_eq, toNat_neg]
1257+
rw [Nat.mod_eq_of_lt (a := 2 ^ w - x.toNat) (by omega)]
1258+
rw [Nat.mod_eq_of_lt (by omega)]
1259+
omega
1260+
1261+
theorem neg_ne_iff_ne_neg {x y : BitVec w} : -x ≠ y ↔ x ≠ -y := by
1262+
constructor
1263+
<;> intro h h'
1264+
<;> subst h'
1265+
<;> simp [BitVec.neg_neg] at h
1266+
12511267
/-! ### mul -/
12521268

12531269
theorem mul_def {n} {x y : BitVec n} : x * y = (ofFin <| x.toFin * y.toFin) := by rfl

0 commit comments

Comments
 (0)