Skip to content

Commit

Permalink
bitvec_neg_neg
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasgrosser committed Aug 9, 2024
1 parent 6dd5023 commit df4e4cb
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 {a : BitVec w} : - - a = a := by
by_cases h : a = 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 - a.toNat) (by omega)]
rw [Nat.mod_eq_of_lt (by omega)]
omega

theorem neg_neq_iff_neq_neg {a b : BitVec w} : -a ≠ b ↔ a ≠ -b:= 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 df4e4cb

Please sign in to comment.