Skip to content

Commit

Permalink
chore: show how to show equivalence between defns for add
Browse files Browse the repository at this point in the history
  • Loading branch information
bollu committed Jan 6, 2025
1 parent caa4016 commit b9b33c2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Init/Data/BitVec/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3569,6 +3569,25 @@ instance instDecidableExistsBitVec :

/-! ### Overflow Theorems -/

theorem uaddOverflow_iff (x y : BitVec w) :
uaddOverflow x y ↔ (x.toNat + y.toNat ≥ 2^w) := by
simp [uaddOverflow, UnsignedOverflow]
have h : x.toNat + y.toNat < 2^ (w + 1) := by
rw [Nat.pow_succ, Nat.mul_two]
apply Nat.add_lt_add <;> omega
rw [Nat.mod_eq_of_lt h]
constructor
· intros hmod
apply Classical.byContradiction
intros hcontra
simp at hcontra
rw [Nat.mod_eq_of_lt hcontra] at hmod
simp at hmod
· intros h'
rw [Nat.mod_eq_sub_mod h']
rw [Nat.mod_eq_of_lt (by omega)]
omega

-- theorem udiv_overflow (x y : BitVec w) : ¬ NatOverflows w (x.toNat / y.toNat) := by sorry

/-! ### Deprecations -/
Expand Down

0 comments on commit b9b33c2

Please sign in to comment.