Skip to content

Commit ad0cb28

Browse files
committed
address remarks
1 parent ed73cdd commit ad0cb28

File tree

4 files changed

+28
-38
lines changed

4 files changed

+28
-38
lines changed

src/Init/Data/Iterators/Consumers/Loop.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Steps through the whole iterator, counting the number of outputs emitted.
260260
261261
**Performance**:
262262
263-
linear in the number of steps taken by the iterator
263+
This function's runtime is linear in the number of steps taken by the iterator.
264264
-/
265265
@[always_inline, inline, expose]
266266
def Iter.count {α : Type w} {β : Type w} [Iterator α Id β] [Finite α Id] [IteratorLoop α Id Id]
@@ -272,7 +272,7 @@ Steps through the whole iterator, counting the number of outputs emitted.
272272
273273
**Performance**:
274274
275-
linear in the number of steps taken by the iterator
275+
This function's runtime is linear in the number of steps taken by the iterator.
276276
-/
277277
@[always_inline, inline, expose, deprecated Iter.count (since := "2025-10-29")]
278278
def Iter.size {α : Type w} {β : Type w} [Iterator α Id β] [Finite α Id] [IteratorLoop α Id Id]
@@ -284,7 +284,7 @@ Steps through the whole iterator, counting the number of outputs emitted.
284284
285285
**Performance**:
286286
287-
linear in the number of steps taken by the iterator
287+
This function's runtime is linear in the number of steps taken by the iterator.
288288
-/
289289
@[always_inline, inline, expose]
290290
def Iter.Partial.count {α : Type w} {β : Type w} [Iterator α Id β] [IteratorLoopPartial α Id Id]
@@ -296,7 +296,7 @@ Steps through the whole iterator, counting the number of outputs emitted.
296296
297297
**Performance**:
298298
299-
linear in the number of steps taken by the iterator
299+
This function's runtime is linear in the number of steps taken by the iterator.
300300
-/
301301
@[always_inline, inline, expose, deprecated Iter.Partial.count (since := "2025-10-29")]
302302
def Iter.Partial.size {α : Type w} {β : Type w} [Iterator α Id β] [IteratorLoopPartial α Id Id]

src/Init/Data/Iterators/Consumers/Monadic/Loop.lean

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -614,43 +614,25 @@ def IterM.Partial.find? {α β : Type w} {m : Type w → Type w'} [Monad m] [Ite
614614

615615
section Count
616616

617-
/--
618-
This is the implementation of the default instance `IteratorSize.defaultImplementation`.
619-
-/
620-
@[always_inline, inline]
621-
def IterM.DefaultConsumers.count {α : Type w} {m : Type w → Type w'} [Monad m] {β : Type w}
622-
[Iterator α m β] [Finite α m] [IteratorLoop α m m] (it : IterM (α := α) m β) :
623-
m (ULift Nat) :=
624-
it.fold (init := .up 0) fun acc _ => .up (acc.down + 1)
625-
626-
/--
627-
This is the implementation of the default instance `IteratorSizePartial.defaultImplementation`.
628-
-/
629-
@[always_inline, inline]
630-
def IterM.DefaultConsumers.countPartial {α : Type w} {m : Type w → Type w'} [Monad m] {β : Type w}
631-
[Iterator α m β] [IteratorLoopPartial α m m] (it : IterM (α := α) m β) :
632-
m (ULift Nat) :=
633-
it.allowNontermination.fold (init := .up 0) fun acc _ => .up (acc.down + 1)
634-
635617
/--
636618
Steps through the whole iterator, counting the number of outputs emitted.
637619
638620
**Performance**:
639621
640-
linear in the number of steps taken by the iterator
622+
This function's runtime is linear in the number of steps taken by the iterator.
641623
-/
642624
@[always_inline, inline]
643625
def IterM.count {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β] [Finite α m]
644626
[IteratorLoop α m m]
645627
[Monad m] (it : IterM (α := α) m β) : m (ULift Nat) :=
646-
IterM.DefaultConsumers.count it
628+
it.fold (init := .up 0) fun acc _ => .up (acc.down + 1)
647629

648630
/--
649631
Steps through the whole iterator, counting the number of outputs emitted.
650632
651633
**Performance**:
652634
653-
linear in the number of steps taken by the iterator
635+
This function's runtime is linear in the number of steps taken by the iterator.
654636
-/
655637
@[always_inline, inline, deprecated IterM.count (since := "2025-10-29")]
656638
def IterM.size {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β] [Finite α m]
@@ -663,19 +645,19 @@ Steps through the whole iterator, counting the number of outputs emitted.
663645
664646
**Performance**:
665647
666-
linear in the number of steps taken by the iterator
648+
This function's runtime is linear in the number of steps taken by the iterator.
667649
-/
668650
@[always_inline, inline]
669651
def IterM.Partial.count {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β]
670652
[IteratorLoopPartial α m m] [Monad m] (it : IterM.Partial (α := α) m β) : m (ULift Nat) :=
671-
IterM.DefaultConsumers.countPartial it.it
653+
it.fold (init := .up 0) fun acc _ => .up (acc.down + 1)
672654

673655
/--
674656
Steps through the whole iterator, counting the number of outputs emitted.
675657
676658
**Performance**:
677659
678-
linear in the number of steps taken by the iterator
660+
This function's runtime is linear in the number of steps taken by the iterator.
679661
-/
680662
@[always_inline, inline, deprecated IterM.Partial.count (since := "2025-10-29")]
681663
def IterM.Partial.size {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β]

src/Std/Data/Iterators/Lemmas/Producers/Range.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ theorem Rcc.toArray_iter_eq_toArray [LE α] [DecidableLE α] [UpwardEnumerable
2727
rfl
2828

2929
@[simp]
30-
theorem Rcc.count_iter_eq_count [LE α] [DecidableLE α] [UpwardEnumerable α]
30+
theorem Rcc.count_iter_eq_size [LE α] [DecidableLE α] [UpwardEnumerable α]
3131
[LawfulUpwardEnumerableLE α] [Rxc.IsAlwaysFinite α] [LawfulUpwardEnumerable α]
3232
[Rxc.HasSize α] [Rxc.LawfulHasSize α]
3333
{r : Rcc α} :
@@ -47,7 +47,7 @@ theorem Rco.toArray_iter_eq_toArray [LT α] [DecidableLT α] [UpwardEnumerable
4747
rfl
4848

4949
@[simp]
50-
theorem Rco.count_iter_eq_count [LT α] [DecidableLT α] [UpwardEnumerable α]
50+
theorem Rco.count_iter_eq_size [LT α] [DecidableLT α] [UpwardEnumerable α]
5151
[LawfulUpwardEnumerableLT α] [Rxo.IsAlwaysFinite α] [LawfulUpwardEnumerable α]
5252
[Rxo.HasSize α] [Rxo.LawfulHasSize α]
5353
{r : Rco α} :
@@ -67,7 +67,7 @@ theorem Rci.toArray_iter_eq_toArray [UpwardEnumerable α]
6767
rfl
6868

6969
@[simp]
70-
theorem Rci.count_iter_eq_count [UpwardEnumerable α]
70+
theorem Rci.count_iter_eq_size [UpwardEnumerable α]
7171
[Rxi.IsAlwaysFinite α] [LawfulUpwardEnumerable α]
7272
[Rxi.HasSize α] [Rxi.LawfulHasSize α]
7373
{r : Rci α} :
@@ -87,7 +87,7 @@ theorem Roc.toArray_iter_eq_toArray [LE α] [DecidableLE α] [UpwardEnumerable
8787
rfl
8888

8989
@[simp]
90-
theorem Roc.count_iter_eq_count [LE α] [DecidableLE α] [UpwardEnumerable α]
90+
theorem Roc.count_iter_eq_size [LE α] [DecidableLE α] [UpwardEnumerable α]
9191
[LawfulUpwardEnumerableLE α] [Rxc.IsAlwaysFinite α] [LawfulUpwardEnumerable α]
9292
[Rxc.HasSize α] [Rxc.LawfulHasSize α]
9393
{r : Roc α} :
@@ -107,7 +107,7 @@ theorem Roo.toArray_iter_eq_toArray [LT α] [DecidableLT α] [UpwardEnumerable
107107
rfl
108108

109109
@[simp]
110-
theorem Roo.count_iter_eq_count [LT α] [DecidableLT α] [UpwardEnumerable α]
110+
theorem Roo.count_iter_eq_size [LT α] [DecidableLT α] [UpwardEnumerable α]
111111
[LawfulUpwardEnumerableLT α] [Rxo.IsAlwaysFinite α] [LawfulUpwardEnumerable α]
112112
[Rxo.HasSize α] [Rxo.LawfulHasSize α]
113113
{r : Roo α} :
@@ -127,7 +127,7 @@ theorem Roi.toArray_iter_eq_toArray [UpwardEnumerable α]
127127
rfl
128128

129129
@[simp]
130-
theorem Roi.count_iter_eq_count [UpwardEnumerable α]
130+
theorem Roi.count_iter_eq_size [UpwardEnumerable α]
131131
[Rxi.IsAlwaysFinite α] [LawfulUpwardEnumerable α]
132132
[Rxi.HasSize α] [Rxi.LawfulHasSize α]
133133
{r : Roi α} :
@@ -147,7 +147,7 @@ theorem Ric.toArray_iter_eq_toArray [Least? α] [LE α] [DecidableLE α] [Upward
147147
rfl
148148

149149
@[simp]
150-
theorem Ric.count_iter_eq_count [Least? α] [LE α] [DecidableLE α] [UpwardEnumerable α]
150+
theorem Ric.count_iter_eq_size [Least? α] [LE α] [DecidableLE α] [UpwardEnumerable α]
151151
[LawfulUpwardEnumerableLE α] [Rxc.IsAlwaysFinite α] [LawfulUpwardEnumerable α]
152152
[Rxc.HasSize α] [Rxc.LawfulHasSize α]
153153
{r : Ric α} :
@@ -167,7 +167,7 @@ theorem Rio.toArray_iter_eq_toArray [Least? α] [LT α] [DecidableLT α] [Upward
167167
rfl
168168

169169
@[simp]
170-
theorem Rio.count_iter_eq_count [Least? α] [LT α] [DecidableLT α] [UpwardEnumerable α]
170+
theorem Rio.count_iter_eq_size [Least? α] [LT α] [DecidableLT α] [UpwardEnumerable α]
171171
[LawfulUpwardEnumerableLT α] [Rxo.IsAlwaysFinite α] [LawfulUpwardEnumerable α]
172172
[Rxo.HasSize α] [Rxo.LawfulHasSize α]
173173
{r : Rio α} :
@@ -187,7 +187,7 @@ theorem Rii.toArray_iter_eq_toArray [Least? α] [UpwardEnumerable α]
187187
rfl
188188

189189
@[simp]
190-
theorem Rii.count_iter_eq_count [Least? α] [UpwardEnumerable α]
190+
theorem Rii.count_iter_eq_size [Least? α] [UpwardEnumerable α]
191191
[Rxi.IsAlwaysFinite α] [LawfulUpwardEnumerable α]
192192
[Rxi.HasSize α] [Rxi.LawfulHasSize α]
193193
{r : Rii α} :

src/Std/Data/Iterators/Lemmas/Producers/Slice.lean

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,22 @@ theorem iter_eq_toIteratorIter {γ : Type u} {s : Slice γ}
2727
s.iter = ToIterator.iter s := by
2828
simp [Internal.iter_eq_iter, Internal.iter_eq_toIteratorIter]
2929

30-
theorem size_eq_size_iter [∀ s : Slice γ, ToIterator s Id β]
30+
theorem size_eq_count_iter [∀ s : Slice γ, ToIterator s Id β]
3131
[∀ s : Slice γ, Iterator (ToIterator.State s Id) Id β] {s : Slice γ}
3232
[Finite (ToIterator.State s Id) Id]
3333
[IteratorLoop (ToIterator.State s Id) Id Id] [LawfulIteratorLoop (ToIterator.State s Id) Id Id]
3434
[SliceSize γ] [LawfulSliceSize γ] :
3535
s.size = s.iter.count := by
3636
simp [Internal.iter_eq_iter, Internal.size_eq_count_iter]
3737

38+
theorem count_iter_eq_size [∀ s : Slice γ, ToIterator s Id β]
39+
[∀ s : Slice γ, Iterator (ToIterator.State s Id) Id β] {s : Slice γ}
40+
[Finite (ToIterator.State s Id) Id]
41+
[IteratorLoop (ToIterator.State s Id) Id Id] [LawfulIteratorLoop (ToIterator.State s Id) Id Id]
42+
[SliceSize γ] [LawfulSliceSize γ] :
43+
s.iter.count = s.size :=
44+
size_eq_count_iter.symm
45+
3846
theorem toArray_eq_toArray_iter {s : Slice γ} [ToIterator s Id β]
3947
[Iterator (ToIterator.State s Id) Id β] [IteratorCollect (ToIterator.State s Id) Id Id]
4048
[Finite (ToIterator.State s Id) Id] :

0 commit comments

Comments
 (0)