Skip to content

Commit e6821e0

Browse files
committed
Add productiveness relation
1 parent 3c3bed7 commit e6821e0

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/Std/Data/DTreeMap/Internal/Slice.lean

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public import Std.Data.DTreeMap.Internal.Lemmas
1717
namespace Std.DTreeMap.Internal
1818
open Std.Iterators
1919

20-
section MapIterator
20+
section Zipper
2121
public inductive Zipper (α : Type u) (β : α → Type v) where
2222
| done
2323
| cons (k : α) (v : β k) (tree : Impl α β) (next : Zipper α β)
@@ -213,10 +213,6 @@ theorem Zipper.prependMap_size (t : Impl α β) (it : Zipper α β) : (Zipper.pr
213213
case case2 size k v l r it ih =>
214214
simp only [ih, Zipper.size, Impl.treeSize, ← Nat.add_assoc, Nat.add_comm]
215215

216-
end MapIterator
217-
218-
section ZipperIterator
219-
variable {α : Type u} {β : α → Type v}
220216

221217
public def Zipper.step : Zipper α β → IterStep (IterM (α := Zipper α β) Id ((a : α) × β a)) ((a : α) × β a)
222218
| .done => .done
@@ -270,7 +266,6 @@ public def Zipper.iter (t : Zipper α β) : Iter (α := Zipper α β) ((a : α)
270266
public def Zipper.iter_of_tree (t : Impl α β) : Iter (α := Zipper α β) ((a : α) × β a) :=
271267
Zipper.iter <| Zipper.done.prependMap t
272268

273-
274269
public theorem Zipper.iter_of_tree_toList_eq_zipper_prependMap_toList (t : Impl α β) :
275270
(Zipper.iter_of_tree t).internalState.toList = t.toList := by
276271
unfold iter_of_tree
@@ -302,7 +297,6 @@ public theorem step_Zipper_eq_match {it : IterM (α := Zipper α β) Id ((a : α
302297
case cons k v tree next =>
303298
simp only [Zipper.iter]
304299

305-
306300
public theorem val_step_Zipper_eq_match {α β}
307301
{it : Iter (α := Zipper α β) (Sigma β)} :
308302
it.step.val =
@@ -370,8 +364,6 @@ decreasing_by
370364
simp only [Zipper.prependMap_size, Impl.treeSize, Nat.add_lt_add_iff_right, Nat.lt_add_left_iff_pos,
371365
Nat.lt_add_one]
372366

373-
end ZipperIterator
374-
375367
public theorem val_step_map_Zipper_eq_match {α β γ} {f : (a : α) × β a → γ}
376368
{it : Iter (α := Zipper α β) (Sigma β)} :
377369
(it.map f).step.val =
@@ -435,8 +427,9 @@ public theorem iter_of_tree_internal_state_eq :
435427
(Internal.Zipper.iter_of_tree m).internalState = Zipper.prependMap m .done := by
436428
simp [Zipper.iter_of_tree, Zipper.iter]
437429

438-
section Rxc
430+
end Zipper
439431

432+
section Rxc
440433
public structure RxcIterator (α : Type u) (β : α → Type v) (cmp : α → α → Ordering) where
441434
iter : Zipper α β
442435
upper : α
@@ -606,6 +599,27 @@ public theorem toList_eq_takeWhile {α β} [Ord α] [TransOrd α] {z : Zipper α
606599
simp only [Zipper.Ordered] at z_ord
607600
apply toList_eq_takeWhile_list
608601
exact z_ord
602+
603+
def instProductivenessRelation : ProductivenessRelation (RxcIterator α β cmp) Id where
604+
rel t' t := t'.internalState.iter.size < t.internalState.iter.size
605+
wf := by
606+
apply InvImage.wf
607+
exact Nat.lt_wfRel.wf
608+
subrelation {it it'} h := by
609+
simp [IterM.IsPlausibleSkipSuccessorOf, IterM.IsPlausibleStep, Iterator.IsPlausibleStep] at h
610+
have := @step_rxcIterator_eq_match α β cmp ⟨it.1
611+
simp [IterM.step, Iterator.step] at this
612+
injections val_eq
613+
rw [h] at val_eq
614+
split at val_eq
615+
case h_1 => contradiction
616+
case h_2 =>
617+
split at val_eq <;> contradiction
618+
619+
@[no_expose]
620+
public instance instProductive : Productive (RxcIterator α β cmp) Id :=
621+
.of_productivenessRelation instProductivenessRelation
622+
609623
end Rxc
610624

611625
section Rcx

0 commit comments

Comments
 (0)