@@ -6026,7 +6026,7 @@ end Max
60266026
60276027namespace 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+
64526505section 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
64566509theorem 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
0 commit comments