Skip to content

Commit 38e8209

Browse files
doc: adds missing docstrings related to iterators and ranges
This PR adds some missing docstrings for identifiers that appear in the manual and enables the missing documentation linter for their modules.
1 parent bf51e1d commit 38e8209

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/Init/Data/Iterators/Basic.lean

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public import Init.Classical
1010
public import Init.Ext
1111

1212
set_option doc.verso true
13+
set_option linter.missingDocs true
1314

1415
public section
1516

@@ -352,7 +353,18 @@ In order to allow intrinsic termination proofs when iterating with the `step` fu
352353
step object is bundled with a proof that it is a "plausible" step for the given current iterator.
353354
-/
354355
class Iterator (α : Type w) (m : Type w → Type w') (β : outParam (Type w)) where
356+
/--
357+
The plausibility relation restricts the steps that are allowed from an iterator.
358+
359+
Plausibility relates an iterator to potential steps. Because steps include successor iterators, it
360+
also relates an iterator to its potential successor iterators. This allows the set of potential
361+
steps to be narrowed drastically, which can make many proofs possible.
362+
-/
355363
IsPlausibleStep : IterM (α := α) m β → IterStep (IterM (α := α) m β) β → Prop
364+
/--
365+
Takes a single step of iteration, which either yields a value, skips a step, or terminates
366+
iteration.
367+
-/
356368
step : (it : IterM (α := α) m β) → m (Shrink <| PlausibleIterStep <| IsPlausibleStep it)
357369

358370
section Monadic
@@ -449,8 +461,10 @@ number of steps.
449461
-/
450462
inductive IterM.IsPlausibleIndirectOutput {α β : Type w} {m : Type w → Type w'} [Iterator α m β]
451463
: IterM (α := α) m β → β → Prop where
464+
/-- The output is plausible in the next step of iteration. -/
452465
| direct {it : IterM (α := α) m β} {out : β} : it.IsPlausibleOutput out →
453466
it.IsPlausibleIndirectOutput out
467+
/-- The output is plausible in some future step of iteration. -/
454468
| indirect {it it' : IterM (α := α) m β} {out : β} : it'.IsPlausibleSuccessorOf it →
455469
it'.IsPlausibleIndirectOutput out → it.IsPlausibleIndirectOutput out
456470

@@ -460,7 +474,12 @@ finitely many steps. This relation is reflexive.
460474
-/
461475
inductive IterM.IsPlausibleIndirectSuccessorOf {α β : Type w} {m : Type w → Type w'}
462476
[Iterator α m β] : IterM (α := α) m β → IterM (α := α) m β → Prop where
477+
/-- Every step is a plausible indirect successor of itself. -/
463478
| refl (it : IterM (α := α) m β) : it.IsPlausibleIndirectSuccessorOf it
479+
/--
480+
Every plausible indirect successor of a plausible successor is itself a plausible indirect
481+
successor.
482+
-/
464483
| cons_right {it'' it' it : IterM (α := α) m β} (h' : it''.IsPlausibleIndirectSuccessorOf it')
465484
(h : it'.IsPlausibleSuccessorOf it) : it''.IsPlausibleIndirectSuccessorOf it
466485

@@ -585,8 +604,10 @@ number of steps.
585604
-/
586605
inductive Iter.IsPlausibleIndirectOutput {α β : Type w} [Iterator α Id β] :
587606
Iter (α := α) β → β → Prop where
607+
/-- The output is plausible in the next step of iteration. -/
588608
| direct {it : Iter (α := α) β} {out : β} : it.IsPlausibleOutput out →
589609
it.IsPlausibleIndirectOutput out
610+
/-- The output is plausible in some future step of iteration. -/
590611
| indirect {it it' : Iter (α := α) β} {out : β} : it'.IsPlausibleSuccessorOf it →
591612
it'.IsPlausibleIndirectOutput out → it.IsPlausibleIndirectOutput out
592613

@@ -617,7 +638,12 @@ finitely many steps. This relation is reflexive.
617638
-/
618639
inductive Iter.IsPlausibleIndirectSuccessorOf {α : Type w} {β : Type w} [Iterator α Id β] :
619640
Iter (α := α) β → Iter (α := α) β → Prop where
641+
/-- Every step is a plausible indirect successor of itself. -/
620642
| refl (it : Iter (α := α) β) : IsPlausibleIndirectSuccessorOf it it
643+
/--
644+
Every plausible indirect successor of a plausible successor is itself a plausible indirect
645+
successor.
646+
-/
621647
| cons_right {it'' it' it : Iter (α := α) β} (h' : it''.IsPlausibleIndirectSuccessorOf it')
622648
(h : it'.IsPlausibleSuccessorOf it) : it''.IsPlausibleIndirectSuccessorOf it
623649

@@ -691,6 +717,7 @@ recursion over finite iterators. See also `IterM.finitelyManySteps` and `Iter.fi
691717
-/
692718
structure IterM.TerminationMeasures.Finite
693719
(α : Type w) (m : Type w → Type w') {β : Type w} [Iterator α m β] where
720+
/-- The wrapped finite iterator that will be used as a termination measure. -/
694721
it : IterM (α := α) m β
695722

696723
/--
@@ -816,6 +843,7 @@ recursion over productive iterators. See also `IterM.finitelyManySkips` and `Ite
816843
-/
817844
structure IterM.TerminationMeasures.Productive
818845
(α : Type w) (m : Type w → Type w') {β : Type w} [Iterator α m β] where
846+
/-- The wrapped productive iterator that will be used as a termination measure. -/
819847
it : IterM (α := α) m β
820848

821849
/--
@@ -917,6 +945,7 @@ library.
917945
-/
918946
class LawfulDeterministicIterator (α : Type w) (m : Type w → Type w') [Iterator α m β]
919947
where
948+
/-- Every iterator state has a unique plausible successor. -/
920949
isPlausibleStep_eq_eq : ∀ it : IterM (α := α) m β, ∃ step, it.IsPlausibleStep = (· = step)
921950

922951
end Iterators

src/Init/Data/Range/Polymorphic/UpwardEnumerable.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ prelude
99
public import Init.Data.Option.Lemmas
1010
public import Init.Data.Order.Classes
1111

12+
set_option linter.missingDocs true
13+
1214
public section
1315

1416
namespace Std.PRange
@@ -240,12 +242,14 @@ This propositional typeclass ensures that `UpwardEnumerable.succ?` will never re
240242
In other words, it ensures that there will always be a successor.
241243
-/
242244
class InfinitelyUpwardEnumerable (α : Type u) [UpwardEnumerable α] where
245+
/-- Every element has a successor. -/
243246
isSome_succ? : ∀ a : α, (UpwardEnumerable.succ? a).isSome
244247

245248
/--
246249
This propositional typeclass ensures that `UpwardEnumerable.succ?` is injective.
247250
-/
248251
class LinearlyUpwardEnumerable (α : Type u) [UpwardEnumerable α] where
252+
/-- `UpwardEnumerable.succ?` is injective. -/
249253
eq_of_succ?_eq : ∀ a b : α, UpwardEnumerable.succ? a = UpwardEnumerable.succ? b → a = b
250254

251255
theorem UpwardEnumerable.isSome_succ? {α : Type u} [UpwardEnumerable α]
@@ -430,6 +434,9 @@ protected theorem UpwardEnumerable.le_iff {α : Type u} [LE α] [UpwardEnumerabl
430434
[LawfulUpwardEnumerableLE α] {a b : α} : a ≤ b ↔ UpwardEnumerable.LE a b :=
431435
LawfulUpwardEnumerableLE.le_iff a b
432436

437+
/--
438+
The `≤` relation that results from a lawfully upward enumerable type is transitive if it is lawful.
439+
-/
433440
def UpwardEnumerable.instLETransOfLawfulUpwardEnumerableLE {α : Type u} [LE α]
434441
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLE α] :
435442
Trans (α := α) (· ≤ ·) (· ≤ ·) (· ≤ ·) where
@@ -494,11 +501,17 @@ protected theorem UpwardEnumerable.lt_succ_iff {α : Type u} [UpwardEnumerable
494501
← succMany?_eq_some_iff_succMany] at hn
495502
exact ⟨n, hn⟩
496503

504+
/--
505+
The `<` relation that results from a lawfully upward enumerable type is transitive if it is lawful.
506+
-/
497507
def UpwardEnumerable.instLTTransOfLawfulUpwardEnumerableLT {α : Type u} [LT α]
498508
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLT α] :
499509
Trans (α := α) (· < ·) (· < ·) (· < ·) where
500510
trans := by simpa [UpwardEnumerable.lt_iff] using @UpwardEnumerable.lt_trans
501511

512+
/--
513+
The `≤` and `<` relations that results from a lawfully upward enumerable type are compatible.
514+
-/
502515
def UpwardEnumerable.instLawfulOrderLTOfLawfulUpwardEnumerableLT {α : Type u} [LT α] [LE α]
503516
[UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLT α]
504517
[LawfulUpwardEnumerableLE α] :
@@ -531,6 +544,9 @@ theorem UpwardEnumerable.isSome_least? {α : Type u} [UpwardEnumerable α] [Leas
531544
obtain ⟨_, h, _⟩ := least?_le (α := α) (a := Classical.ofNonempty)
532545
simp [h]
533546

547+
/--
548+
Returns the least element of an upward enumerable type.
549+
-/
534550
def UpwardEnumerable.least [UpwardEnumerable α] [Least? α] [LawfulUpwardEnumerableLeast? α]
535551
[hn : Nonempty α] : α :=
536552
least?.get isSome_least?

0 commit comments

Comments
 (0)