@@ -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
@@ -140,12 +141,6 @@ May be asserted to be true in an unsafe context via `Array.unsafe_sizeFitsUsize`
140141-/
141142private abbrev SizeFitsUSize (a : Array α) : Prop := a.size < USize.size
142143
143- @ [grind .]
144- private theorem SizeFitsUSize.toNat_ofNat_eq {n : Nat} {a : Array α}
145- (h : a.SizeFitsUSize) (hn : n ≤ a.size) :
146- (USize.ofNat n).toNat = n :=
147- USize.toNat_ofNat_of_lt' (Nat.lt_of_le_of_lt ‹_› ‹_›)
148-
149144/-
150145This is guaranteed by the Array docs but it is unprovable.
151146Can be used in unsafe functions to write more efficient implementations
@@ -224,13 +219,13 @@ private theorem scanlM_loop_eq_scanlMFast_loop [Monad m]
224219 {h_stop : stop ≤ as.size} {acc : Array β} :
225220 scanlM.loop f init as start stop h_stop acc
226221 = scanlMFast.loop f init as (USize.ofNat start) (USize.ofNat stop)
227- (by rw [USize.toNat_ofNat_of_lt' (Nat.lt_of_le_of_lt h_stop h_size) ]; exact h_stop) acc := by
222+ (by rw [USize.toNat_ofNat_of_le_of_lt h_size h_stop]; exact h_stop) acc := by
228223 generalize h_n : stop - start = n
229224 induction n using Nat.strongRecOn generalizing start acc init
230225 rename_i n ih
231226 rw [scanlM.loop, scanlMFast.loop]
232- have h_stop_usize := h_size.toNat_ofNat_eq h_stop
233- have h_start_usize := h_size.toNat_ofNat_eq h_start
227+ have h_stop_usize := USize.toNat_ofNat_of_le_of_lt h_size h_stop
228+ have h_start_usize := USize.toNat_ofNat_of_le_of_lt h_size h_start
234229 split
235230 case isTrue h_lt =>
236231 simp_all only [USize.toNat_ofNat', ↓reduceDIte, uget,
@@ -239,7 +234,7 @@ private theorem scanlM_loop_eq_scanlMFast_loop [Monad m]
239234 intro next
240235 have h_start_succ : USize.ofNat start + 1 = USize.ofNat (start + 1 ) := by
241236 simp_all only [← USize.toNat_inj, USize.toNat_add]
242- grind only [USize.size_eq, SizeFitsUSize.toNat_ofNat_eq ]
237+ grind only [USize.size_eq, USize.toNat_ofNat_of_le_of_lt ]
243238 rw [h_start_succ]
244239 apply ih (stop - (start + 1 )) <;> omega
245240 case isFalse h_nlt => grind [USize.lt_iff_toNat_lt]
@@ -265,7 +260,7 @@ private def scanrMFast [Monad m] (f : α → β → m β) (init : β) (as : Arra
265260 (start := USize.ofNat start) (stop := USize.ofNat stop)
266261 (h_start := by grind only [USize.size_eq, USize.ofNat_eq_iff_mod_eq_toNat, = Nat.min_def])
267262 (acc := Array.replicate (start - stop + 1 ) init)
268- (by grind only [!Array.size_replicate, = Nat.min_def, SizeFitsUSize.toNat_ofNat_eq ])
263+ (by grind only [!Array.size_replicate, = Nat.min_def, USize.toNat_ofNat_of_le_of_lt ])
269264where
270265 @[specialize]
271266 loop (f : α → β → m β) (init : β) (as : Array α)
0 commit comments