Skip to content

Commit

Permalink
feat: add BitVec.neg_neg
Browse files Browse the repository at this point in the history
.. as well as neg_neq_iff_neq_neg.
  • Loading branch information
tobiasgrosser committed Aug 9, 2024
1 parent 6dd5023 commit 1a90574
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Init/Data/BitVec/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,24 @@ theorem neg_eq_not_add (x : BitVec w) : -x = ~~~x + 1 := by
have hx : x.toNat < 2^w := x.isLt
rw [Nat.sub_sub, Nat.add_comm 1 x.toNat, ← Nat.sub_sub, Nat.sub_add_cancel (by omega)]

@[simp]
theorem neg_neg {x : BitVec w} : - - x = x := by
by_cases h : x = 0
· subst h
simp
· simp only [toNat_eq, toNat_neg]
rw [toNat_eq] at h
simp only [ofNat_eq_ofNat, toNat_ofNat, Nat.zero_mod] at h
rw [Nat.mod_eq_of_lt (a := 2 ^ w - x.toNat) (by omega)]
rw [Nat.mod_eq_of_lt (by omega)]
omega

theorem neg_neq_iff_neq_neg {x y : BitVec w} : -x ≠ y ↔ x ≠ -y:= by
constructor
<;> intro h h'
<;> subst h'
<;> simp [BitVec.neg_neg] at h

/-! ### mul -/

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

0 comments on commit 1a90574

Please sign in to comment.