Skip to content

Commit ba81065

Browse files
committed
address remarks
1 parent d655739 commit ba81065

File tree

3 files changed

+35
-40
lines changed

3 files changed

+35
-40
lines changed

src/Init/Data/Iterators/Lemmas/Consumers/Collect.lean

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ theorem Iter.toListRev_eq_toListRev_toIterM {α β} [Iterator α Id β] [Finite
3434
(rfl)
3535

3636
@[simp]
37-
theorem Iter.ensureTerminationToArray_eq_toArray {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
37+
theorem Iter.toArray_ensureTermination {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
3838
[LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
3939
it.ensureTermination.toArray = it.toArray :=
4040
(rfl)
4141

4242
@[simp]
43-
theorem Iter.ensureTerminationToList_eq_toList {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
43+
theorem Iter.toList_ensureTermination {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
4444
[LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
4545
it.ensureTermination.toList = it.toList :=
4646
(rfl)
4747

4848
@[simp]
49-
theorem Iter.ensureTerminationToListRev_eq_toListRev {α β} [Iterator α Id β] [Finite α Id]
49+
theorem Iter.toListRev_ensureTermination_eq_toListRev {α β} [Iterator α Id β] [Finite α Id]
5050
{it : Iter (α := α) β} : it.ensureTermination.toListRev = it.toListRev :=
5151
(rfl)
5252

@@ -68,23 +68,21 @@ theorem Iter.toList_toArray {α β} [Iterator α Id β] [Finite α Id] [Iterator
6868
it.toArray.toList = it.toList := by
6969
simp [toArray_eq_toArray_toIterM, toList_eq_toList_toIterM, ← IterM.toList_toArray]
7070

71-
@[simp]
72-
theorem Iter.toList_ensureTerminationToArray {α β} [Iterator α Id β] [Finite α Id]
71+
theorem Iter.toList_toArray_ensureTermination {α β} [Iterator α Id β] [Finite α Id]
7372
[IteratorCollect α Id Id] [LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
7473
it.ensureTermination.toArray.toList = it.toList := by
75-
rw [ensureTerminationToArray_eq_toArray, toList_toArray]
74+
simp
7675

7776
@[simp]
7877
theorem Iter.toArray_toList {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
7978
[LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
8079
it.toList.toArray = it.toArray := by
8180
simp [toArray_eq_toArray_toIterM, toList_eq_toList_toIterM, ← IterM.toArray_toList]
8281

83-
@[simp]
84-
theorem Iter.toArray_ensureTerminationToList {α β} [Iterator α Id β] [Finite α Id]
82+
theorem Iter.toArray_toList_ensureTermination {α β} [Iterator α Id β] [Finite α Id]
8583
[IteratorCollect α Id Id] [LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
8684
it.ensureTermination.toList.toArray = it.toArray := by
87-
rw [ensureTerminationToList_eq_toList, toArray_toList]
85+
simp
8886

8987
@[simp]
9088
theorem Iter.reverse_toListRev [Iterator α Id β] [Finite α Id]
@@ -93,21 +91,20 @@ theorem Iter.reverse_toListRev [Iterator α Id β] [Finite α Id]
9391
it.toListRev.reverse = it.toList := by
9492
simp [toListRev_eq_toListRev_toIterM, toList_eq_toList_toIterM, ← IterM.reverse_toListRev]
9593

96-
@[simp]
97-
theorem Iter.reverse_ensureTerminationToListRev [Iterator α Id β] [Finite α Id]
94+
theorem Iter.reverse_toListRev_ensureTermination [Iterator α Id β] [Finite α Id]
9895
[IteratorCollect α Id Id] [LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
9996
it.ensureTermination.toListRev.reverse = it.toList := by
100-
rw [ensureTerminationToListRev_eq_toListRev, reverse_toListRev]
97+
simp
10198

10299
theorem Iter.toListRev_eq {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
103100
[LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
104101
it.toListRev = it.toList.reverse := by
105102
simp [Iter.toListRev_eq_toListRev_toIterM, Iter.toList_eq_toList_toIterM, IterM.toListRev_eq]
106103

107-
theorem Iter.ensureTerminationToListRev_eq {α β} [Iterator α Id β] [Finite α Id]
104+
theorem Iter.toListRev_ensureTermination {α β} [Iterator α Id β] [Finite α Id]
108105
[IteratorCollect α Id Id] [LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
109106
it.ensureTermination.toListRev = it.toList.reverse := by
110-
rw [ensureTerminationToListRev_eq_toListRev, toListRev_eq]
107+
simp [toListRev_eq]
111108

112109
theorem Iter.toArray_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
113110
[LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
@@ -120,13 +117,13 @@ theorem Iter.toArray_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [I
120117
generalize it.toIterM.step.run = step
121118
cases step.inflate using PlausibleIterStep.casesOn <;> simp
122119

123-
theorem Iter.ensureTerminationToArray_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
120+
theorem Iter.toArray_ensureTermination_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
124121
[LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
125122
it.ensureTermination.toArray = match it.step.val with
126123
| .yield it' out => #[out] ++ it'.toArray
127124
| .skip it' => it'.toArray
128125
| .done => #[] := by
129-
rw [ensureTerminationToArray_eq_toArray, toArray_eq_match_step]
126+
rw [toArray_ensureTermination, toArray_eq_match_step]
130127

131128
theorem Iter.toList_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
132129
[LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
@@ -137,13 +134,13 @@ theorem Iter.toList_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [It
137134
rw [← Iter.toList_toArray, Iter.toArray_eq_match_step]
138135
split <;> simp [Iter.toList_toArray]
139136

140-
theorem Iter.ensureTerminationToList_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
137+
theorem Iter.toList_ensureTermination_eq_match_step {α β} [Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id]
141138
[LawfulIteratorCollect α Id Id] {it : Iter (α := α) β} :
142139
it.ensureTermination.toList = match it.step.val with
143140
| .yield it' out => out :: it'.toList
144141
| .skip it' => it'.toList
145142
| .done => [] := by
146-
rw [ensureTerminationToList_eq_toList, toList_eq_match_step]
143+
rw [toList_ensureTermination, toList_eq_match_step]
147144

148145
theorem Iter.toListRev_eq_match_step {α β} [Iterator α Id β] [Finite α Id] {it : Iter (α := α) β} :
149146
it.toListRev = match it.step.val with
@@ -154,12 +151,12 @@ theorem Iter.toListRev_eq_match_step {α β} [Iterator α Id β] [Finite α Id]
154151
generalize it.toIterM.step.run = step
155152
cases step.inflate using PlausibleIterStep.casesOn <;> simp
156153

157-
theorem Iter.ensureTerminationToListRev_eq_match_step {α β} [Iterator α Id β] [Finite α Id] {it : Iter (α := α) β} :
154+
theorem Iter.toListRev_ensureTermination_eq_match_step {α β} [Iterator α Id β] [Finite α Id] {it : Iter (α := α) β} :
158155
it.ensureTermination.toListRev = match it.step.val with
159156
| .yield it' out => it'.toListRev ++ [out]
160157
| .skip it' => it'.toListRev
161158
| .done => [] := by
162-
rw [ensureTerminationToListRev_eq_toListRev, toListRev_eq_match_step]
159+
rw [toListRev_ensureTermination_eq_toListRev, toListRev_eq_match_step]
163160

164161
theorem Iter.getElem?_toList_eq_atIdxSlow? {α β}
165162
[Iterator α Id β] [Finite α Id] [IteratorCollect α Id Id] [LawfulIteratorCollect α Id Id]

src/Init/Data/Iterators/Lemmas/Consumers/Monadic/Collect.lean

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ theorem IterM.DefaultConsumers.toArrayMapped_eq_match_step [Monad n] [LawfulMona
8888
simp [IterM.DefaultConsumers.toArrayMapped.go.aux₂]
8989

9090
@[simp]
91-
theorem IterM.ensureTerminationToArray_eq_toArray [Monad m] [Iterator α m β] [Finite α m]
91+
theorem IterM.toArray_ensureTermination [Monad m] [Iterator α m β] [Finite α m]
9292
[IteratorCollect α m m] {it : IterM (α := α) m β} :
9393
it.ensureTermination.toArray = it.toArray :=
9494
(rfl)
@@ -104,17 +104,17 @@ theorem IterM.toArray_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m β]
104104
rw [IterM.DefaultConsumers.toArrayMapped_eq_match_step]
105105
simp [bind_pure_comp, pure_bind]
106106

107-
theorem IterM.ensureTerminationToArray_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m β]
107+
theorem IterM.toArray_ensureTermination_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m β]
108108
[Finite α m] [IteratorCollect α m m] [LawfulIteratorCollect α m m] :
109109
it.ensureTermination.toArray = (do
110110
match (← it.step).inflate.val with
111111
| .yield it' out => return #[out] ++ (← it'.toArray)
112112
| .skip it' => it'.toArray
113113
| .done => return #[]) := by
114-
rw [ensureTerminationToArray_eq_toArray, toArray_eq_match_step]
114+
rw [toArray_ensureTermination, toArray_eq_match_step]
115115

116116
@[simp]
117-
theorem IterM.ensureTerminationToList_eq_toList [Monad m] [Iterator α m β] [Finite α m]
117+
theorem IterM.toList_ensureTermination [Monad m] [Iterator α m β] [Finite α m]
118118
[IteratorCollect α m m] {it : IterM (α := α) m β} :
119119
it.ensureTermination.toList = it.toList :=
120120
(rfl)
@@ -125,23 +125,21 @@ theorem IterM.toList_toArray [Monad m] [Iterator α m β] [Finite α m] [Iterato
125125
Array.toList <$> it.toArray = it.toList := by
126126
simp [IterM.toList]
127127

128-
@[simp]
129-
theorem IterM.toList_ensureTerminationToArray [Monad m] [Iterator α m β] [Finite α m]
128+
theorem IterM.toList_toArray_ensureTermination [Monad m] [Iterator α m β] [Finite α m]
130129
[IteratorCollect α m m] {it : IterM (α := α) m β} :
131130
Array.toList <$> it.ensureTermination.toArray = it.toList := by
132-
rw [ensureTerminationToArray_eq_toArray, toList_toArray]
131+
simp
133132

134133
@[simp]
135134
theorem IterM.toArray_toList [Monad m] [LawfulMonad m] [Iterator α m β] [Finite α m]
136135
[IteratorCollect α m m] {it : IterM (α := α) m β} :
137136
List.toArray <$> it.toList = it.toArray := by
138137
simp [IterM.toList, -toList_toArray]
139138

140-
@[simp]
141-
theorem IterM.toArray_ensureTerminationToList [Monad m] [LawfulMonad m] [Iterator α m β] [Finite α m]
139+
theorem IterM.toArray_toList_ensureTermination [Monad m] [LawfulMonad m] [Iterator α m β] [Finite α m]
142140
[IteratorCollect α m m] {it : IterM (α := α) m β} :
143141
List.toArray <$> it.ensureTermination.toList = it.toArray := by
144-
rw [ensureTerminationToList_eq_toList, toArray_toList]
142+
rw [toList_ensureTermination, toArray_toList]
145143

146144
theorem IterM.toList_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m β] [Finite α m]
147145
[IteratorCollect α m m] [LawfulIteratorCollect α m m] {it : IterM (α := α) m β} :
@@ -156,17 +154,17 @@ theorem IterM.toList_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m β]
156154
intro step
157155
split <;> simp
158156

159-
theorem IterM.ensureTerminationToList_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m β]
157+
theorem IterM.toList_ensureTermination_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m β]
160158
[Finite α m] [IteratorCollect α m m] [LawfulIteratorCollect α m m] {it : IterM (α := α) m β} :
161159
it.ensureTermination.toList = (do
162160
match (← it.step).inflate.val with
163161
| .yield it' out => return out :: (← it'.toList)
164162
| .skip it' => it'.toList
165163
| .done => return []) := by
166-
rw [ensureTerminationToList_eq_toList, toList_eq_match_step]
164+
rw [toList_ensureTermination, toList_eq_match_step]
167165

168166
@[simp]
169-
theorem IterM.ensureTerminationToListRev_eq_toListRev [Monad m] [Iterator α m β] [Finite α m]
167+
theorem IterM.toListRev_ensureTermination_eq_toListRev [Monad m] [Iterator α m β] [Finite α m]
170168
{it : IterM (α := α) m β} :
171169
it.ensureTermination.toListRev = it.toListRev :=
172170
(rfl)
@@ -230,14 +228,14 @@ theorem IterM.toListRev_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m
230228
intro step
231229
cases step.inflate using PlausibleIterStep.casesOn <;> simp [IterM.toListRev.go.aux₂]
232230

233-
theorem IterM.ensureTerminationToListRev_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m β]
231+
theorem IterM.toListRev_ensureTermination_eq_match_step [Monad m] [LawfulMonad m] [Iterator α m β]
234232
[Finite α m] {it : IterM (α := α) m β} :
235233
it.ensureTermination.toListRev = (do
236234
match (← it.step).inflate.val with
237235
| .yield it' out => return (← it'.toListRev) ++ [out]
238236
| .skip it' => it'.toListRev
239237
| .done => return []) := by
240-
rw [ensureTerminationToListRev_eq_toListRev, toListRev_eq_match_step]
238+
rw [toListRev_ensureTermination_eq_toListRev, toListRev_eq_match_step]
241239

242240
@[simp]
243241
theorem IterM.reverse_toListRev [Monad m] [LawfulMonad m] [Iterator α m β] [Finite α m]
@@ -253,19 +251,19 @@ theorem IterM.reverse_toListRev [Monad m] [LawfulMonad m] [Iterator α m β] [Fi
253251
cases step.inflate using PlausibleIterStep.casesOn <;> simp (discharger := assumption) [ihy, ihs]
254252

255253
@[simp]
256-
theorem IterM.reverse_ensureTerminationToListRev [Monad m] [LawfulMonad m] [Iterator α m β]
254+
theorem IterM.reverse_toListRev_ensureTermination [Monad m] [LawfulMonad m] [Iterator α m β]
257255
[Finite α m] [IteratorCollect α m m] [LawfulIteratorCollect α m m]
258256
{it : IterM (α := α) m β} :
259257
List.reverse <$> it.ensureTermination.toListRev = it.toList := by
260-
rw [ensureTerminationToListRev_eq_toListRev, reverse_toListRev]
258+
rw [toListRev_ensureTermination_eq_toListRev, reverse_toListRev]
261259

262260
theorem IterM.toListRev_eq [Monad m] [LawfulMonad m] [Iterator α m β] [Finite α m]
263261
[IteratorCollect α m m] [LawfulIteratorCollect α m m]
264262
{it : IterM (α := α) m β} :
265263
it.toListRev = List.reverse <$> it.toList := by
266264
simp [← IterM.reverse_toListRev]
267265

268-
theorem IterM.ensureTerminationToListRev_eq [Monad m] [LawfulMonad m] [Iterator α m β] [Finite α m]
266+
theorem IterM.toListRev_ensureTermination [Monad m] [LawfulMonad m] [Iterator α m β] [Finite α m]
269267
[IteratorCollect α m m] [LawfulIteratorCollect α m m]
270268
{it : IterM (α := α) m β} :
271269
it.ensureTermination.toListRev = List.reverse <$> it.toList := by

src/Init/Internal/ExtrinsicTermination.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public def extrinsicFix [∀ a, Nonempty (C a)] (F : ∀ a, (∀ a', C a') → C
7171
-- In effect, `extrinsicFix` is opaque if `TerminatesTotally F` is false.
7272
opaqueFix F a
7373

74-
public def extrinsicFix_eq [∀ a, Nonempty (C a)] {F : ∀ a, (∀ a', C a') → C a}
74+
public theorem extrinsicFix_eq [∀ a, Nonempty (C a)] {F : ∀ a, (∀ a', C a') → C a}
7575
(h : TerminatesTotally F) {a : α} :
7676
extrinsicFix F a = F a (extrinsicFix F) := by
7777
simp only [extrinsicFix, dif_pos h]
@@ -128,7 +128,7 @@ public def extrinsicFix₂ [∀ a b, Nonempty (C₂ a b)]
128128
F x.1 x.2 (fun a b => G ⟨a, b⟩)
129129
extrinsicFix (C := fun x : PSigma β => C₂ x.1 x.2) F' ⟨a, b⟩
130130

131-
public def extrinsicFix₂_eq [∀ a b, Nonempty (C₂ a b)]
131+
public theorem extrinsicFix₂_eq [∀ a b, Nonempty (C₂ a b)]
132132
{F : (a : α) → (b : β a) → ((a' : α) → (b' : β a') → C₂ a' b') → C₂ a b}
133133
(h : TerminatesTotally₂ F) {a : α} {b : β a} :
134134
extrinsicFix₂ F a b = F a b (extrinsicFix₂ F) := by

0 commit comments

Comments
 (0)