@@ -5,6 +5,7 @@ Authors: Arthur Paulino, Floris van Doorn, Jannis Limperg
55-/
66module
77import Batteries.Tactic.Alias
8+ import Batteries.Data.UInt
89
910@[expose] public section
1011
@@ -130,12 +131,6 @@ May be asserted to be true in an unsafe context via `Array.unsafe_sizeFitsUsize`
130131-/
131132private abbrev SizeFitsUSize (a : Array α) : Prop := a.size < USize.size
132133
133- @ [grind .]
134- private theorem SizeFitsUSize.toNat_ofNat_eq {n : Nat} {a : Array α}
135- (h : a.SizeFitsUSize) (hn : n ≤ a.size) :
136- (USize.ofNat n).toNat = n :=
137- USize.toNat_ofNat_of_lt' (Nat.lt_of_le_of_lt ‹_› ‹_›)
138-
139134/-
140135This is guaranteed by the Array docs but it is unprovable.
141136Can be used in unsafe functions to write more efficient implementations
@@ -214,13 +209,13 @@ private theorem scanlM_loop_eq_scanlMFast_loop [Monad m]
214209 {h_stop : stop ≤ as.size} {acc : Array β} :
215210 scanlM.loop f init as start stop h_stop acc
216211 = scanlMFast.loop f init as (USize.ofNat start) (USize.ofNat stop)
217- (by rw [USize.toNat_ofNat_of_lt' (Nat.lt_of_le_of_lt h_stop h_size) ]; exact h_stop) acc := by
212+ (by rw [USize.toNat_ofNat_of_le_of_lt h_size h_stop]; exact h_stop) acc := by
218213 generalize h_n : stop - start = n
219214 induction n using Nat.strongRecOn generalizing start acc init
220215 rename_i n ih
221216 rw [scanlM.loop, scanlMFast.loop]
222- have h_stop_usize := h_size.toNat_ofNat_eq h_stop
223- have h_start_usize := h_size.toNat_ofNat_eq h_start
217+ have h_stop_usize := USize.toNat_ofNat_of_le_of_lt h_size h_stop
218+ have h_start_usize := USize.toNat_ofNat_of_le_of_lt h_size h_start
224219 split
225220 case isTrue h_lt =>
226221 simp_all only [USize.toNat_ofNat', ↓reduceDIte, uget,
@@ -229,7 +224,7 @@ private theorem scanlM_loop_eq_scanlMFast_loop [Monad m]
229224 intro next
230225 have h_start_succ : USize.ofNat start + 1 = USize.ofNat (start + 1 ) := by
231226 simp_all only [← USize.toNat_inj, USize.toNat_add]
232- grind only [USize.size_eq, SizeFitsUSize.toNat_ofNat_eq ]
227+ grind only [USize.size_eq, USize.toNat_ofNat_of_le_of_lt ]
233228 rw [h_start_succ]
234229 apply ih (stop - (start + 1 )) <;> omega
235230 case isFalse h_nlt => grind [USize.lt_iff_toNat_lt]
@@ -255,7 +250,7 @@ private def scanrMFast [Monad m] (f : α → β → m β) (init : β) (as : Arra
255250 (start := USize.ofNat start) (stop := USize.ofNat stop)
256251 (h_start := by grind only [USize.size_eq, USize.ofNat_eq_iff_mod_eq_toNat, = Nat.min_def])
257252 (acc := Array.replicate (start - stop + 1 ) init)
258- (by grind only [!Array.size_replicate, = Nat.min_def, SizeFitsUSize.toNat_ofNat_eq ])
253+ (by grind only [!Array.size_replicate, = Nat.min_def, USize.toNat_ofNat_of_le_of_lt ])
259254where
260255 @[specialize]
261256 loop (f : α → β → m β) (init : β) (as : Array α)
0 commit comments