Skip to content

Commit 2f3f9cf

Browse files
committed
insertMany + eraseMany lemmas
1 parent 1194755 commit 2f3f9cf

File tree

3 files changed

+122
-30
lines changed

3 files changed

+122
-30
lines changed

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

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6026,7 +6026,7 @@ end Max
60266026

60276027
namespace Equiv
60286028

6029-
variable {t₁ t₂ t₃ : Impl α β} {δ : Type w} {m : Type w → Type w}
6029+
variable {t₁ t₂ t₃ t₄ : Impl α β} {δ : Type w} {m : Type w → Type w}
60306030

60316031
@[refl, simp] theorem rfl : Equiv t t := ⟨.rfl⟩
60326032

@@ -6449,9 +6449,62 @@ theorem filterMap! (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂) {f : (a
64496449
t₁.filterMap! f ~m t₂.filterMap! f := by
64506450
simpa only [filterMap_eq_filterMap!] using h.filterMap h₁ h₂
64516451

6452+
theorem insertMany_list [TransOrd α] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂)
6453+
{l : List ((a : α) × β a)} :
6454+
(t₁.insertMany l h₁.balanced).1 ~m (t₂.insertMany l h₂.balanced).1 := by
6455+
simp only [insertMany_eq_foldl]
6456+
refine (List.foldl_rel (r := fun a b : Impl α β => a.WF ∧ b.WF ∧ a ~m b) ⟨h₁, h₂, h⟩ ?_).2.2
6457+
intro a ha c c' hc
6458+
refine ⟨hc.1.insert!, hc.2.1.insert!, hc.2.2.insert! hc.1 hc.2.1
6459+
6460+
theorem insertMany!_list [TransOrd α] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂)
6461+
{l : List ((a : α) × β a)} :
6462+
(t₁.insertMany! l).1 ~m (t₂.insertMany! l).1 := by
6463+
simpa only [insertMany_eq_insertMany!] using h.insertMany_list h₁ h₂
6464+
6465+
theorem eraseMany_list [TransOrd α] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂)
6466+
{l : List α} :
6467+
(t₁.eraseMany l h₁.balanced).1 ~m (t₂.eraseMany l h₂.balanced).1 := by
6468+
simp only [eraseMany, bind_pure_comp, map_pure, List.forIn_pure_yield_eq_foldl, bind_pure,
6469+
Id.run_pure]
6470+
refine (List.foldl_rel (r := fun (a : t₁.IteratedErasureFrom) (b : t₂.IteratedErasureFrom) =>
6471+
a.1.WF ∧ b.1.WF ∧ a.1 ~m b.1) ⟨h₁, h₂, h⟩ ?_).2.2
6472+
intro a ha c c' hc
6473+
refine ⟨hc.1.erase, hc.2.1.erase, hc.2.2.erase hc.1 hc.2.1
6474+
6475+
theorem eraseMany!_list [TransOrd α] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂)
6476+
{l : List α} :
6477+
(t₁.eraseMany! l).1 ~m (t₂.eraseMany! l).1 := by
6478+
simp only [eraseMany!, bind_pure_comp, map_pure, List.forIn_pure_yield_eq_foldl, bind_pure,
6479+
Id.run_pure]
6480+
refine (List.foldl_rel (r := fun (a : t₁.IteratedSlowErasureFrom) (b : t₂.IteratedSlowErasureFrom) =>
6481+
a.1.WF ∧ b.1.WF ∧ a.1 ~m b.1) ⟨h₁, h₂, h⟩ ?_).2.2
6482+
intro a ha c c' hc
6483+
refine ⟨hc.1.erase!, hc.2.1.erase!, hc.2.2.erase! hc.1 hc.2.1
6484+
6485+
theorem mergeWith [TransOrd α] [LawfulEqOrd α]
6486+
(h : t₁ ~m t₂) (h' : t₃ ~m t₄)
6487+
(h₁ : t₁.WF) (h₂ : t₂.WF)
6488+
(h₃ : t₃.WF) (h₄ : t₄.WF)
6489+
{f : (a : α) → β a → β a → β a} :
6490+
(t₁.mergeWith f t₃ h₁.balanced).impl ~m (t₂.mergeWith f t₄ h₂.balanced).impl := by
6491+
simp only [Impl.mergeWith, h'.foldl_eq h₃ h₄, foldl_eq_foldl]
6492+
refine (List.foldl_rel (r := fun a b : BalancedTree α β =>
6493+
a.impl.WF ∧ b.impl.WF ∧ a.impl ~m b.impl) ⟨h₁, h₂, h⟩ ?_).2.2
6494+
intro a ha c c' hc
6495+
exact ⟨hc.1.alter, hc.2.1.alter, hc.2.2.alter hc.1 hc.2.1
6496+
6497+
theorem mergeWith! [TransOrd α] [LawfulEqOrd α]
6498+
(h : t₁ ~m t₂) (h' : t₃ ~m t₄)
6499+
(h₁ : t₁.WF) (h₂ : t₂.WF)
6500+
(h₃ : t₃.WF) (h₄ : t₄.WF)
6501+
{f : (a : α) → β a → β a → β a} :
6502+
t₁.mergeWith! f t₃ ~m t₂.mergeWith! f t₄ := by
6503+
simpa only [mergeWith_eq_mergeWith!] using h.mergeWith h' h₁ h₂ h₃ h₄
6504+
64526505
section Const
64536506

6454-
variable {β : Type v} {t₁ t₂ : Impl α β} {δ : Type w} {m : Type w → Type w}
6507+
variable {β : Type v} {t₁ t₂ t₃ t₄ : Impl α β} {δ : Type w} {m : Type w → Type w}
64556508

64566509
theorem constGet?_eq [TransOrd α] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂) {k : α} :
64576510
Const.get? t₁ k = Const.get? t₂ k := by
@@ -6616,29 +6669,40 @@ theorem constModify [TransOrd α] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m
66166669
{k : α} {f : β → β} : Const.modify k f t₁ ~m Const.modify k f t₂ := by
66176670
simp_to_model [Const.modify, Equiv] using List.Const.modifyKey_of_perm _ h.1
66186671

6619-
end Const
6672+
theorem constInsertMany_list [TransOrd α] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂)
6673+
{l : List (α × β)} :
6674+
(Const.insertMany t₁ l h₁.balanced).1 ~m (Const.insertMany t₂ l h₂.balanced).1 := by
6675+
simp only [Const.insertMany_eq_foldl]
6676+
refine (List.foldl_rel (r := fun a b : Impl α β => a.WF ∧ b.WF ∧ a ~m b) ⟨h₁, h₂, h⟩ ?_).2.2
6677+
intro a ha c c' hc
6678+
refine ⟨hc.1.insert!, hc.2.1.insert!, hc.2.2.insert! hc.1 hc.2.1
66206679

6621-
variable {t₄ : Impl α β}
6680+
theorem constInsertMany!_list [TransOrd α] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂)
6681+
{l : List (α × β)} :
6682+
(Const.insertMany! t₁ l).1 ~m (Const.insertMany! t₂ l).1 := by
6683+
simpa only [Const.insertMany_eq_insertMany!] using h.constInsertMany_list h₁ h₂
66226684

6623-
theorem mergeWith [TransOrd α] [LawfulEqOrd α]
6685+
theorem constMergeWith [TransOrd α]
66246686
(h : t₁ ~m t₂) (h' : t₃ ~m t₄)
66256687
(h₁ : t₁.WF) (h₂ : t₂.WF)
66266688
(h₃ : t₃.WF) (h₄ : t₄.WF)
6627-
{f : (a : α) → β a → β a → β a} :
6628-
(t₁.mergeWith f t₃ h₁.balanced).impl ~m (t₂.mergeWith f t₄ h₂.balanced).impl := by
6629-
simp only [Impl.mergeWith, h'.foldl_eq h₃ h₄, foldl_eq_foldl]
6689+
{f : α → β → β → β} :
6690+
(Const.mergeWith f t₁ t₃ h₁.balanced).impl ~m (Const.mergeWith f t₂ t₄ h₂.balanced).impl := by
6691+
simp only [Impl.Const.mergeWith, h'.foldl_eq h₃ h₄, foldl_eq_foldl]
66306692
refine (List.foldl_rel (r := fun a b : BalancedTree α β =>
66316693
a.impl.WF ∧ b.impl.WF ∧ a.impl ~m b.impl) ⟨h₁, h₂, h⟩ ?_).2.2
66326694
intro a ha c c' hc
6633-
exact ⟨hc.1.alter, hc.2.1.alter, hc.2.2.alter hc.1 hc.2.1
6695+
exact ⟨hc.1.constAlter, hc.2.1.constAlter, hc.2.2.constAlter hc.1 hc.2.1
66346696

6635-
theorem mergeWith! [TransOrd α] [LawfulEqOrd α]
6697+
theorem constMergeWith! [TransOrd α]
66366698
(h : t₁ ~m t₂) (h' : t₃ ~m t₄)
66376699
(h₁ : t₁.WF) (h₂ : t₂.WF)
66386700
(h₃ : t₃.WF) (h₄ : t₄.WF)
6639-
{f : (a : α) → β a → β a → β a} :
6640-
t₁.mergeWith! f t₃ ~m t₂.mergeWith! f t₄ := by
6641-
simpa only [mergeWith_eq_mergeWith!] using h.mergeWith h' h₁ h₂ h₃ h₄
6701+
{f : α → β → β → β} :
6702+
Const.mergeWith! f t₁ t₃ ~m Const.mergeWith! f t₂ t₄ := by
6703+
simpa only [Const.mergeWith_eq_mergeWith!] using h.constMergeWith h' h₁ h₂ h₃ h₄
6704+
6705+
end Const
66426706

66436707
-- extensionalities
66446708

src/Std/Data/DTreeMap/Lemmas.lean

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,7 +4136,7 @@ end Max
41364136

41374137
namespace Equiv
41384138

4139-
variable {t₁ t₂ t₃ : DTreeMap α β cmp} {δ : Type w} {m : Type w → Type w}
4139+
variable {t₁ t₂ t₃ t₄ : DTreeMap α β cmp} {δ : Type w} {m : Type w → Type w}
41404140

41414141
@[refl, simp] theorem rfl : Equiv t t := ⟨.rfl⟩
41424142

@@ -4452,6 +4452,19 @@ theorem modify [TransCmp cmp] [LawfulEqCmp cmp] (h : t₁ ~m t₂)
44524452
theorem filter (h : t₁ ~m t₂) (f : (a : α) → β a → Bool) : t₁.filter f ~m t₂.filter f :=
44534453
⟨h.1.filter t₁.2 t₂.2
44544454

4455+
theorem insertMany_list [TransCmp cmp] (h : t₁ ~m t₂) (l : List ((a : α) × β a)) :
4456+
t₁.insertMany l ~m t₂.insertMany l :=
4457+
⟨h.1.insertMany_list t₁.2 t₂.2
4458+
4459+
theorem eraseMany_list [TransCmp cmp] (h : t₁ ~m t₂) (l : List α) :
4460+
t₁.eraseMany l ~m t₂.eraseMany l :=
4461+
⟨h.1.eraseMany_list t₁.2 t₂.2
4462+
4463+
theorem mergeWith [TransCmp cmp] [LawfulEqCmp cmp]
4464+
(h : t₁ ~m t₂) (f : (a : α) → β a → β a → β a) (h' : t₃ ~m t₄) :
4465+
t₁.mergeWith f t₃ ~m t₂.mergeWith f t₄ :=
4466+
⟨h.1.mergeWith h'.1 t₁.2 t₂.2 t₃.2 t₄.2
4467+
44554468
section Const
44564469

44574470
variable {β : Type v} {t₁ t₂ : DTreeMap α β cmp} {δ : Type w} {m : Type w → Type w}
@@ -4587,14 +4600,11 @@ theorem constModify [TransCmp cmp] (h : t₁ ~m t₂) (k : α) (f : β → β) :
45874600
Const.modify t₁ k f ~m Const.modify t₂ k f :=
45884601
⟨h.1.constModify t₁.2 t₂.2
45894602

4590-
end Const
4591-
4592-
variable {t₄ : DTreeMap α β cmp}
4603+
theorem constInsertMany_list [TransCmp cmp] [LawfulEqCmp cmp] (h : t₁ ~m t₂) (l : List (α × β)) :
4604+
Const.insertMany t₁ l ~m Const.insertMany t₂ l :=
4605+
⟨h.1.constInsertMany_list t₁.2 t₂.2
45934606

4594-
theorem mergeWith [TransCmp cmp] [LawfulEqCmp cmp]
4595-
(h : t₁ ~m t₂) (f : (a : α) → β a → β a → β a) (h' : t₃ ~m t₄) :
4596-
t₁.mergeWith f t₃ ~m t₂.mergeWith f t₄ :=
4597-
⟨h.1.mergeWith t₁.2 t₂.2 t₃.2 t₄.2 h'.1
4607+
end Const
45984608

45994609
-- extensionalities
46004610

src/Std/Data/DTreeMap/Raw/Lemmas.lean

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,7 +3854,7 @@ end Max
38543854

38553855
namespace Equiv
38563856

3857-
variable {t₁ t₂ t₃ : Raw α β cmp} {δ : Type w} {m : Type w → Type w}
3857+
variable {t₁ t₂ t₃ t₄ : Raw α β cmp} {δ : Type w} {m : Type w → Type w}
38583858

38593859
@[refl, simp] theorem rfl : Equiv t t := ⟨.rfl⟩
38603860

@@ -4155,9 +4155,25 @@ theorem filter (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂) (f : (a : α
41554155
t₁.filter f ~m t₂.filter f :=
41564156
⟨h.1.filter! h₁.1 h₂.1
41574157

4158+
theorem insertMany_list [TransCmp cmp] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂)
4159+
(l : List ((a : α) × β a)) : t₁.insertMany l ~m t₂.insertMany l :=
4160+
⟨h.1.insertMany!_list h₁.1 h₂.1
4161+
4162+
theorem eraseMany_list [TransCmp cmp] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂) (l : List α) :
4163+
t₁.eraseMany l ~m t₂.eraseMany l :=
4164+
⟨h.1.eraseMany!_list h₁.1 h₂.1
4165+
4166+
theorem mergeWith [TransCmp cmp] [LawfulEqCmp cmp]
4167+
(h₁ : t₁.WF) (h₂ : t₂.WF)
4168+
(h₃ : t₃.WF) (h₄ : t₄.WF)
4169+
(h : t₁ ~m t₂) (h' : t₃ ~m t₄)
4170+
(f : (a : α) → β a → β a → β a) :
4171+
t₁.mergeWith f t₃ ~m t₂.mergeWith f t₄ :=
4172+
⟨h.1.mergeWith! h'.1 h₁.1 h₂.1 h₃.1 h₄.1
4173+
41584174
section Const
41594175

4160-
variable (β : Type v) {t₁ t₂ : Raw α β cmp} (δ : Type w) (m : Type w → Type w)
4176+
variable (β : Type v) {t₁ t₂ t₃ t₄ : Raw α β cmp} (δ : Type w) (m : Type w → Type w)
41614177

41624178
theorem constGet?_eq [TransCmp cmp] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂) (k : α) :
41634179
Const.get? t₁ k = Const.get? t₂ k :=
@@ -4283,17 +4299,19 @@ theorem constModify [TransCmp cmp] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~
42834299
(k : α) (f : β → β) : Const.modify t₁ k f ~m Const.modify t₂ k f :=
42844300
⟨h.1.constModify h₁.1 h₂.1
42854301

4286-
end Const
4287-
4288-
variable {t₄ : Raw α β cmp}
4302+
theorem constInsertMany_list [TransCmp cmp] (h₁ : t₁.WF) (h₂ : t₂.WF) (h : t₁ ~m t₂)
4303+
(l : List (α × β)) : Const.insertMany t₁ l ~m Const.insertMany t₂ l :=
4304+
⟨h.1.constInsertMany!_list h₁.1 h₂.1
42894305

4290-
theorem mergeWith [TransCmp cmp] [LawfulEqCmp cmp]
4306+
theorem constMergeWith [TransCmp cmp]
42914307
(h₁ : t₁.WF) (h₂ : t₂.WF)
42924308
(h₃ : t₃.WF) (h₄ : t₄.WF)
42934309
(h : t₁ ~m t₂) (h' : t₃ ~m t₄)
4294-
(f : (a : α) → β a → β a → β a) :
4295-
t₁.mergeWith f t₃ ~m t₂.mergeWith f t₄ :=
4296-
⟨h.1.mergeWith! h'.1 h₁.1 h₂.1 h₃.1 h₄.1
4310+
(f : α → β → β → β) :
4311+
Const.mergeWith f t₁ t₃ ~m Const.mergeWith f t₂ t₄ :=
4312+
⟨h.1.constMergeWith! h'.1 h₁.1 h₂.1 h₃.1 h₄.1
4313+
4314+
end Const
42974315

42984316
-- extensionalities
42994317

0 commit comments

Comments
 (0)