@@ -66,7 +66,7 @@ namespace BVLems
6666 have hle := of_decide_eq_true hdec
6767 rw [Bool.dite_eq_true (proof:=hle), toNat_zeroExtend']
6868 rw [Nat.mod_eq_of_lt]; rcases a with ⟨⟨a, isLt⟩⟩;
69- apply Nat.le_trans isLt; apply Nat.pow_le_pow_right (Nat.le_step .refl) hle
69+ apply Nat.le_trans isLt; apply Nat.pow_le_pow_right (Nat.le_succ_of_le .refl) hle
7070
7171 theorem toNat_sub (a b : BitVec n) : (a - b).toNat = (2 ^ n - b.toNat + a.toNat) % (2 ^ n) := rfl
7272
@@ -93,12 +93,12 @@ namespace BVLems
9393 theorem ushiftRight_ge_length_eq_zero (a : BitVec n) (i : Nat) : i ≥ n → a >>> i = 0 #n := by
9494 intro h; apply eq_of_val_eq; rw [toNat_ushiftRight, toNat_ofNat]
9595 apply (Nat.le_iff_div_eq_zero (Nat.two_pow_pos _)).mpr
96- apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (.step .refl) h)
96+ apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (Nat.lt_succ_of_lt .refl) h)
9797
9898 theorem ushiftRight_ge_length_eq_zero' (a : BitVec n) (i : Nat) : i ≥ n → BitVec.ofNat n (a.toNat >>> i) = 0 #n := by
9999 intro h; apply congrArg (@BitVec.ofNat n)
100100 rw [Nat.shiftRight_eq_div_pow, Nat.le_iff_div_eq_zero (Nat.two_pow_pos _)]
101- apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (.step .refl) h)
101+ apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (Nat.lt_succ_of_lt .refl) h)
102102
103103 theorem msb_equiv_lt (a : BitVec n) : !a.msb ↔ a.toNat < 2 ^ (n - 1 ) := by
104104 dsimp [BitVec.msb, BitVec.getMsbD, BitVec.getLsbD]
@@ -116,32 +116,37 @@ namespace BVLems
116116 case succ n =>
117117 rw [Nat.succ_sub_one, Nat.pow_succ, Nat.mul_comm (m:=2 )]
118118 apply Iff.symm; apply Nat.mul_lt_mul_left
119- exact .step .refl
119+ exact Nat.lt_succ_of_lt .refl
120120
121121 theorem sshiftRight_ge_length_eq_msb (a : BitVec n) (i : Nat) : i ≥ n → a.sshiftRight i =
122122 if a.msb then (1 #n).neg else 0 #n := by
123123 intro h; simp only [sshiftRight, BitVec.toInt, ← msb_equiv_lt']
124- cases hmsb : a.msb <;> simp only [Int.shiftRight_def] <;> dsimp
124+ cases hmsb : a.msb <;> simp only [Int.shiftRight_def]
125125 case false =>
126+ dsimp only [Bool.not_false, ↓dreduceIte, Int.ofNat_eq_natCast, Int.natCast_shiftRight, Bool.false_eq_true]
126127 rw [BitVec.ofNat]
127128 apply ushiftRight_ge_length_eq_zero'; exact h
128129 case true =>
129130 rw [← Int.subNatNat_eq_coe, Int.subNatNat_of_lt (toNat_le _)]
130- simp only [BitVec.ofInt]; dsimp
131+ simp only [BitVec.ofInt]
132+ dsimp only [Bool.not_true, Bool.false_eq_true, ↓dreduceIte,
133+ Nat.pred_eq_sub_one, Int.ofNat_eq_natCast, Int.natCast_shiftRight, Int.natCast_pow,
134+ Int.cast_ofNat_Int, neg_eq]
131135 have hzero : (2 ^ n - BitVec.toNat a - 1 ) >>> i = 0 := by
132136 rw [Nat.shiftRight_eq_div_pow]; apply (Nat.le_iff_div_eq_zero (Nat.two_pow_pos _)).mpr
133137 rw [Nat.sub_one, Nat.pred_lt_iff_le (Nat.two_pow_pos _)]
134- apply Nat.le_trans (Nat.sub_le _ _) (Nat.pow_le_pow_right (.step .refl) h)
138+ apply Nat.le_trans (Nat.sub_le _ _) (Nat.pow_le_pow_right (Nat.lt_succ_of_lt .refl) h)
135139 apply eq_of_val_eq; rw [toNat_ofNatLt, hzero]
136140 rw [toNat_neg, Int.mod_def', Int.emod]
137- rw [Nat.zero_mod, Int.natAbs_natCast, Nat.succ_eq_add_one, Nat.zero_add]
138- rw [Int.subNatNat_of_sub_eq_zero ((Nat.sub_eq_zero_iff_le).mpr (Nat.two_pow_pos _) )]
141+ rw [Nat.zero_mod, Nat.succ_eq_add_one, Nat.zero_add]
142+ rw [Int.subNatNat_of_sub_eq_zero (by grind )]
139143 rw [Int.toNat_natCast, BitVec.toNat_ofNat]
140144 cases n <;> try rfl
141145 case succ n =>
142- have hlt : 2 ≤ 2 ^ Nat.succ n := @Nat.pow_le_pow_right 2 (.step .refl) 1 (.succ n) (Nat.succ_le_succ (Nat.zero_le _))
146+ have hlt : 2 ≤ 2 ^ Nat.succ n := @Nat.pow_le_pow_right 2 (Nat.lt_succ_of_lt .refl) 1 (.succ n) (Nat.succ_le_succ (Nat.zero_le _))
143147 rw [Nat.mod_eq_of_lt (a:=1 ) hlt]
144- rw [Nat.mod_eq_of_lt]; apply Nat.sub_lt (Nat.le_trans (.step .refl) hlt) .refl
148+ rw [Nat.mod_eq_of_lt (by grind)]
149+ grind
145150
146151 theorem shiftRight_eq_zero_iff (a : BitVec n) (b : Nat) : a >>> b = 0 #n ↔ a.toNat < 2 ^ b := by
147152 rw [ushiftRight_def]; rcases a with ⟨⟨a, isLt⟩⟩;
@@ -201,7 +206,7 @@ namespace BVLems
201206
202207 theorem shl_toNat_equiv_short (a : BitVec n) (b : BitVec m) (h : m ≤ n) : a <<< b.toNat = a <<< (zeroExtend n b) := by
203208 apply eq_of_val_eq; rw [toNat_shiftLeft, smtshiftLeft_def, toNat_shiftLeft, toNat_zeroExtend, Nat.mod_eq_of_lt (a:=BitVec.toNat b)]
204- apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (.step .refl) h)
209+ apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (Nat.lt_succ_of_lt .refl) h)
205210
206211 theorem shl_toNat_equiv_long (a : BitVec n) (b : BitVec m) (h : m > n) : a <<< b.toNat =
207212 if (b >>> (BitVec.ofNat m n)) = 0 #m then a <<< (zeroExtend n b) else 0 := by
@@ -244,7 +249,7 @@ namespace BVLems
244249
245250 theorem lshr_toNat_equiv_short (a : BitVec n) (b : BitVec m) (h : m ≤ n) : a >>> b.toNat = a >>> (zeroExtend n b) := by
246251 apply eq_of_val_eq; rw [toNat_ushiftRight, smtushiftRight_def, toNat_ushiftRight, toNat_zeroExtend, Nat.mod_eq_of_lt]
247- apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (.step .refl) h)
252+ apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (Nat.lt_succ_of_lt .refl) h)
248253
249254 theorem lshr_toNat_equiv_long (a : BitVec n) (b : BitVec m) (h : m > n) : a >>> b.toNat =
250255 if (b >>> (BitVec.ofNat m n)) = 0 #m then a >>> (zeroExtend n b) else 0 := by
@@ -289,7 +294,7 @@ namespace BVLems
289294
290295 theorem ashr_toNat_equiv_short (a : BitVec n) (b : BitVec m) (h : m ≤ n) : a.sshiftRight b.toNat = a.sshiftRight (zeroExtend n b).toNat := by
291296 apply eq_of_val_eq; rw [toNat_zeroExtend, Nat.mod_eq_of_lt]
292- apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (.step .refl) h)
297+ apply Nat.le_trans (toNat_le _) (Nat.pow_le_pow_right (Nat.lt_succ_of_lt .refl) h)
293298
294299 theorem ashr_toNat_equiv_long (a : BitVec n) (b : BitVec m) (h : m > n) : a.sshiftRight b.toNat =
295300 if (b >>> (BitVec.ofNat m n)) = 0 #m then a.sshiftRight (zeroExtend n b).toNat else (if a.msb then (1 #n).neg else 0 #n) := by
0 commit comments