Skip to content

Commit b5bbc57

Browse files
authored
feat: prove that intMin is indeed the smallest signed bitvector (#5778)
1 parent 4714f84 commit b5bbc57

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Init/Data/BitVec/Lemmas.lean

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,6 +2921,21 @@ theorem toInt_intMin {w : Nat} :
29212921
rw [Nat.mul_comm]
29222922
simp [w_pos]
29232923

2924+
theorem toInt_intMin_le (x : BitVec w) :
2925+
(intMin w).toInt ≤ x.toInt := by
2926+
cases w
2927+
case zero => simp [@of_length_zero x]
2928+
case succ w =>
2929+
simp only [toInt_intMin, Nat.add_one_sub_one, Int.ofNat_emod]
2930+
have : 0 < 2 ^ w := Nat.two_pow_pos w
2931+
rw [Int.emod_eq_of_lt (by omega) (by omega)]
2932+
rw [BitVec.toInt_eq_toNat_bmod]
2933+
rw [show (2 ^ w : Nat) = ((2 ^ (w + 1) : Nat) : Int) / 2 by omega]
2934+
apply Int.le_bmod (by omega)
2935+
2936+
theorem intMin_sle (x : BitVec w) : (intMin w).sle x := by
2937+
simp only [BitVec.sle, toInt_intMin_le x, decide_True]
2938+
29242939
@[simp]
29252940
theorem neg_intMin {w : Nat} : -intMin w = intMin w := by
29262941
by_cases h : 0 < w

0 commit comments

Comments
 (0)