@@ -1661,6 +1661,75 @@ theorem WF.eraseMany! {_ : Ord α} [TransOrd α] {ρ} [ForIn Id ρ α] {l : ρ}
16611661 {t : Impl α β} (h : t.WF) : (t.eraseMany! l).1 .WF :=
16621662 (t.eraseMany! l).2 h (fun _ _ h' => h'.erase!)
16631663
1664+ /-!
1665+ ### `eraseManyEntries`
1666+ -/
1667+
1668+ theorem eraseManyEntries !_eq_foldl {_ : Ord α} {l : List ((a : α) × β a)} {t : Impl α β} :
1669+ (t.eraseManyEntries! l).val = l.foldl (init := t) fun acc ⟨k, _⟩ => acc.erase! k := by
1670+ simp [eraseManyEntries!, ← List.foldl_hom Subtype.val, List.forIn_pure_yield_eq_foldl]
1671+
1672+ theorem eraseManyEntries_eq_foldl {_ : Ord α} {l : List ((a : α) × β a)} {t : Impl α β} (h : t.Balanced) :
1673+ (t.eraseManyEntries l h).val = l.foldl (init := t) fun acc ⟨k, _⟩ => acc.erase! k := by
1674+ simp [eraseManyEntries, erase_eq_erase!, ← List.foldl_hom Subtype.val, List.forIn_pure_yield_eq_foldl]
1675+
1676+ theorem eraseManyEntries_impl_eq_foldl {_ : Ord α} {t₁ : Impl α β} (h₁ : t₁.Balanced) {t₂ : Impl α β} :
1677+ (t₁.eraseManyEntries t₂ h₁).val = t₂.foldl (init := t₁) fun acc k _ => acc.erase! k := by
1678+ simp [foldl_eq_foldl]
1679+ rw [← eraseManyEntries_eq_foldl]
1680+ rotate_left
1681+ · exact h₁
1682+ · simp only [eraseManyEntries, pure, ForIn.forIn, Id.run_bind]
1683+ rw [forIn_eq_forIn_toListModel]
1684+ congr
1685+
1686+ theorem eraseManyEntries !_impl_eq_foldl {_ : Ord α} {t₁ : Impl α β} {t₂ : Impl α β} :
1687+ (t₁.eraseManyEntries! t₂).val = t₂.foldl (init := t₁) fun acc k _ => acc.erase! k := by
1688+ simp [foldl_eq_foldl]
1689+ rw [← eraseManyEntries!_eq_foldl]
1690+ simp only [eraseManyEntries!, pure, ForIn.forIn, Id.run_bind]
1691+ rw [forIn_eq_forIn_toListModel]
1692+ congr
1693+
1694+ theorem eraseManyEntries_impl_eq_eraseManyEntries ! {_ : Ord α}
1695+ {t₁ t₂ : Impl α β} (h : t₁.Balanced) :
1696+ (t₁.eraseManyEntries t₂ h).val = (t₁.eraseManyEntries! t₂).val := by
1697+ simp only [eraseManyEntries_impl_eq_foldl, eraseManyEntries!_impl_eq_foldl]
1698+
1699+ theorem eraseManyEntries_impl_perm_eraseList {_ : Ord α} [BEq α] [LawfulBEqOrd α] [TransOrd α]
1700+ {t₁ : Impl α β} (h₁ : t₁.WF) {t₂ : Impl α β} :
1701+ List.Perm (t₁.eraseManyEntries t₂ h₁.balanced).val.toListModel (t₁.toListModel.eraseList (t₂.toListModel.map (·.1 ))) := by
1702+ rw [eraseManyEntries_impl_eq_foldl]
1703+ rw [foldl_eq_foldl]
1704+ induction t₂.toListModel generalizing t₁ with
1705+ | nil => rfl
1706+ | cons e es ih =>
1707+ simp only [List.foldl_cons]
1708+ apply List.Perm.trans (@ih (t₁.erase! e.1 ) (h₁.erase!))
1709+ apply eraseList_perm_of_perm_first
1710+ · apply toListModel_erase!
1711+ · exact h₁.balanced
1712+ · exact h₁.ordered
1713+ · apply h₁.erase!.ordered.distinctKeys
1714+
1715+ theorem toListModel_eraseManyEntries_impl {_ : Ord α} [BEq α] [LawfulBEqOrd α] [TransOrd α]
1716+ {t₁ : Impl α β} (h₁ : t₁.WF) {t₂ : Impl α β} :
1717+ List.Perm (t₁.eraseManyEntries t₂ h₁.balanced).val.toListModel (t₁.toListModel.filter (fun p => !List.contains (t₂.toListModel.map Sigma.fst) p.fst )) := by
1718+ apply List.Perm.trans
1719+ · apply eraseManyEntries_impl_perm_eraseList h₁
1720+ · apply eraseList_perm_filter_not_contains
1721+ · apply h₁.ordered.distinctKeys
1722+
1723+ theorem toListModel_eraseManyEntries !_impl {_ : Ord α} [BEq α] [LawfulBEqOrd α] [TransOrd α]
1724+ {t₁ : Impl α β} (h₁ : t₁.WF) {t₂ : Impl α β} :
1725+ List.Perm (t₁.eraseManyEntries! t₂).val.toListModel (t₁.toListModel.filter (fun p => !List.contains (t₂.toListModel.map Sigma.fst) p.fst)) := by
1726+ rw [← eraseManyEntries_impl_eq_eraseManyEntries! h₁.balanced]
1727+ apply toListModel_eraseManyEntries_impl h₁
1728+
1729+ theorem WF.eraseManyEntries ! {_ : Ord α} [TransOrd α] {ρ} [ForIn Id ρ ((a : α) × β a)] {l : ρ}
1730+ {t : Impl α β} (h : t.WF) : (t.eraseManyEntries! l).1 .WF :=
1731+ (t.eraseManyEntries! l).2 h (fun _ _ h' => h'.erase!)
1732+
16641733/-!
16651734### `insertMany`
16661735-/
@@ -2048,6 +2117,40 @@ theorem toListModel_interSmallerFn {_ : Ord α} [TransOrd α] [BEq α] [LawfulBE
20482117 simp only [heq, hml]
20492118 exact h₁.ordered
20502119
2120+ /-!
2121+ ### diff
2122+ -/
2123+
2124+ theorem toListModel_diff {_ : Ord α} [BEq α] [LawfulBEqOrd α] [TransOrd α]
2125+ {t₁ t₂ : Impl α β} (h₁ : t₁.WF) (h₂ : t₂.WF) :
2126+ List.Perm (t₁.diff t₂ h₁.balanced).toListModel (t₁.toListModel.filter (fun p => !List.contains (t₂.toListModel.map Sigma.fst) p.fst)) := by
2127+ rw [diff]
2128+ split
2129+ · simp only [toListModel_filter]
2130+ conv =>
2131+ lhs
2132+ lhs
2133+ ext e
2134+ congr
2135+ rw [contains_eq_containsKey h₂.ordered]
2136+ rw [containsKey_eq_contains_map_fst]
2137+ · apply toListModel_eraseManyEntries_impl h₁
2138+
2139+ theorem diff_eq_diff ! [Ord α]
2140+ {t₁ t₂ : Impl α β} (h₁ : t₁.WF) :
2141+ (t₁.diff t₂ h₁.balanced) = t₁.diff! t₂ := by
2142+ simp only [diff, diff!]
2143+ split
2144+ · rw [filter_eq_filter!]
2145+ . rw [eraseManyEntries_impl_eq_eraseManyEntries! h₁.balanced]
2146+
2147+ theorem WF.diff ! {_ : Ord α} [TransOrd α]
2148+ {t₁ : Impl α β} (h₁ : t₁.WF) {t₂ : Impl α β} : (t₁.diff! t₂).WF := by
2149+ simp only [Impl.diff!]
2150+ split
2151+ . exact WF.filter! h₁
2152+ . exact WF.eraseManyEntries! h₁
2153+
20512154/-!
20522155### interSmaller
20532156-/
0 commit comments