File tree Expand file tree Collapse file tree 4 files changed +28
-3
lines changed
Iterators/Lemmas/Combinators/Monadic Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 77
88prelude
99public import Init.Data.Iterators.Combinators.Monadic.ULift
10- --import all Init.Data.Iterators.Combinators.Monadic.ULift
1110public import Init.Data.Iterators.Lemmas.Consumers.Monadic.Collect
1211public import Init.Data.Iterators.Lemmas.Consumers.Monadic.Loop
1312
Original file line number Diff line number Diff line change @@ -819,6 +819,23 @@ public theorem toArray_eq_if_roo [UpwardEnumerable α] [LT α] [DecidableLT α]
819819 #[] := by
820820 rw [Internal.toArray_eq_toArray_iter, Rxo.Iterator.toArray_eq_match]; rfl
821821
822+ public theorem toArray_eq_if_rco [UpwardEnumerable α] [LT α] [DecidableLT α]
823+ [LawfulUpwardEnumerable α] [Rxo.IsAlwaysFinite α] [LawfulUpwardEnumerableLT α] :
824+ r.toArray = if r.lower < r.upper then
825+ match UpwardEnumerable.succ? r.lower with
826+ | none => #[r.lower]
827+ | some next => #[r.lower] ++ (next...r.upper).toArray
828+ else
829+ #[] := by
830+ rw [Internal.toArray_eq_toArray_iter, Rxo.Iterator.toArray_eq_match]
831+ simp only [Internal.iter]
832+ split
833+ · split
834+ · simp [Rxo.Iterator.toArray_eq_match, *]
835+ · simp only [*]
836+ rfl
837+ · rfl
838+
822839@[deprecated toArray_eq_if_roo (since := " 2025-10-29" )]
823840def toArray_eq_if := @toArray_eq_if_roo
824841
Original file line number Diff line number Diff line change @@ -28,12 +28,22 @@ and use `Std.Slice.iter` instead.
2828def Internal.iter (s : Slice γ) [ToIterator s Id β] :=
2929 ToIterator.iter s
3030
31+ /--
32+ This type class provides support for the `Slice.size` function.
33+ -/
3134class SliceSize (α : Type u) where
35+ /-- Computes the slice of a `Slice`. Use `Slice.size` instead. -/
3236 size (slice : Slice α) : Nat
3337
38+ /--
39+ This type class states that the slice's iterator emits exactly `Slice.size` elements before
40+ terminating.
41+ -/
3442class LawfulSliceSize (α : Type u) [SliceSize α] [∀ s : Slice α, ToIterator s Id β]
3543 [∀ s : Slice α, Iterator (ToIterator.State s Id) Id β] where
44+ /-- The iterator for every `Slice α` is finite. -/
3645 [finite : ∀ s : Slice α, Finite (ToIterator.State s Id) Id]
46+ /-- The iterator of a slice `s` of type `Slice α` emits exactly `SliceSize.size s` elements. -/
3747 lawful :
3848 letI (s : Slice α) : IteratorLoop (ToIterator.State s Id) Id Id := .defaultImplementation
3949 ∀ s : Slice α, SliceSize.size s = (ToIterator.iter s).count
Original file line number Diff line number Diff line change @@ -39,8 +39,7 @@ open Std.Iterators
3939#eval (2 <...<15 ).iter.stepSize 2 |>.toList
4040
4141example : (1 ...5 ).size = 4 := by
42- rw [← Std.Rco.size_toArray]
43- simp [Std.Rco.toArray_eq_if, Std.Roo.toArray_eq_match_rco]
42+ simp [← Std.Rco.size_toArray, Std.Rco.toArray_eq_if_rco]
4443
4544/-- info: true -/
4645#guard_msgs in
You can’t perform that action at this time.
0 commit comments