Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Std/Data/DHashMap/Internal/RawLemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,24 @@ theorem contains_of_contains_union_of_contains_eq_false_left [EquivBEq α]
simp_to_model [union, contains] using List.contains_of_contains_insertList_of_contains_eq_false_left

/- Equiv -/
theorem union_equiv_congr_left {m₃ : Raw₀ α β} [EquivBEq α] [LawfulHashable α]
(h₁ : m₁.val.WF) (h₂ : m₂.val.WF) (h₃ : m₃.val.WF) (equiv : m₁.1.Equiv m₂.1) :
(m₁.union m₃).1.Equiv (m₂.union m₃).1 := by
revert equiv
simp_to_model [union]
intro equiv
apply @List.insertList_perm_of_perm_first _ _ _ _ (toListModel m₁.val.buckets) (toListModel m₂.val.buckets) (toListModel m₃.val.buckets) equiv
wf_trivial

theorem union_equiv_congr_right {m₃ : Raw₀ α β} [EquivBEq α] [LawfulHashable α]
(h₁ : m₁.val.WF) (h₂ : m₂.val.WF) (h₃ : m₃.val.WF) (equiv : m₂.1.Equiv m₃.1) :
(m₁.union m₂).1.Equiv (m₁.union m₃).1 := by
revert equiv
simp_to_model [union]
intro equiv
apply @List.insertList_perm_of_perm_second _ _ _ _ (toListModel m₂.val.buckets) (toListModel m₃.val.buckets) (toListModel m₁.val.buckets) equiv
all_goals wf_trivial

theorem union_insert_right_equiv_insert_union [EquivBEq α] [LawfulHashable α] {p : (a : α) × β a}
(h₁ : m₁.val.WF) (h₂ : m₂.val.WF) :
(m₁.union (m₂.insert p.fst p.snd)).1.Equiv ((m₁.union m₂).insert p.fst p.snd).1 := by
Expand Down
10 changes: 10 additions & 0 deletions src/Std/Data/DHashMap/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,16 @@ theorem mem_of_mem_union_of_not_mem_left [EquivBEq α]
exact @Raw₀.contains_of_contains_union_of_contains_eq_false_left _ _ _ _ ⟨m₁.1, _⟩ ⟨m₂.1, _⟩ _ _ m₁.2 m₂.2 k h₁ h₂

/- Equiv -/
theorem union_equiv_congr_left {m₃ : DHashMap α β} [EquivBEq α] [LawfulHashable α]
(equiv : m₁ ~m m₂) :
(m₁ ∪ m₃) ~m (m₂ ∪ m₃) :=
⟨@Raw₀.union_equiv_congr_left α β _ _ ⟨m₁.1, m₁.2.size_buckets_pos⟩ ⟨m₂.1, m₂.2.size_buckets_pos⟩ ⟨m₃.1, m₃.2.size_buckets_pos⟩ _ _ m₁.2 m₂.2 m₃.2 equiv.1⟩

theorem union_equiv_congr_right {m₃ : DHashMap α β} [EquivBEq α] [LawfulHashable α]
(equiv : m₂ ~m m₃) :
(m₁ ∪ m₂) ~m (m₁ ∪ m₃) :=
⟨@Raw₀.union_equiv_congr_right α β _ _ ⟨m₁.1, m₁.2.size_buckets_pos⟩ ⟨m₂.1, m₂.2.size_buckets_pos⟩ ⟨m₃.1, m₃.2.size_buckets_pos⟩ _ _ m₁.2 m₂.2 m₃.2 equiv.1⟩

theorem union_insert_right_equiv_insert_union [EquivBEq α] [LawfulHashable α] {p : (a : α) × β a} :
(m₁ ∪ (m₂.insert p.fst p.snd)) ~m ((m₁ ∪ m₂).insert p.fst p.snd) :=
⟨@Raw₀.union_insert_right_equiv_insert_union _ _ _ _ ⟨m₁.1, m₁.2.size_buckets_pos⟩ ⟨m₂.1, m₂.2.size_buckets_pos⟩ _ _ p m₁.2 m₂.2⟩
Expand Down
20 changes: 20 additions & 0 deletions src/Std/Data/DHashMap/RawLemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,26 @@ theorem mem_of_mem_union_of_not_mem_left [EquivBEq α]
simp_to_raw using Raw₀.contains_of_contains_union_of_contains_eq_false_left

/- Equiv -/
theorem union_equiv_congr_left {m₃ : Raw α β} [EquivBEq α] [LawfulHashable α] (h₁ : m₁.WF) (h₂ : m₂.WF) (h₃ : m₃.WF)
(equiv : m₁ ~m m₂) :
(m₁ ∪ m₃) ~m (m₂ ∪ m₃) := by
revert equiv
simp only [Union.union]
simp_to_raw
intro hyp
apply Raw₀.union_equiv_congr_left
all_goals wf_trivial

theorem union_equiv_congr_right {m₃ : Raw α β} [EquivBEq α] [LawfulHashable α] (h₁ : m₁.WF) (h₂ : m₂.WF) (h₃ : m₃.WF)
(equiv : m₂ ~m m₃) :
(m₁ ∪ m₂) ~m (m₁ ∪ m₃) := by
revert equiv
simp only [Union.union]
simp_to_raw
intro hyp
apply Raw₀.union_equiv_congr_right
all_goals wf_trivial

theorem union_insert_right_equiv_insert_union [EquivBEq α] [LawfulHashable α] {p : (a : α) × β a}
(h₁ : m₁.WF) (h₂ : m₂.WF) :
(m₁ ∪ (m₂.insert p.fst p.snd)).Equiv ((m₁ ∪ m₂).insert p.fst p.snd) := by
Expand Down
32 changes: 32 additions & 0 deletions src/Std/Data/DTreeMap/Internal/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3396,6 +3396,38 @@ theorem union!_insert_right_equiv_insert_union! [TransOrd α] {p : (a : α) ×
. wf_trivial
. exact h₂.balanced

theorem union_equiv_congr_left {m₃ : Impl α β} [TransOrd α]
(h₁ : m₁.WF) (h₂ : m₂.WF) (h₃ : m₃.WF) (equiv : m₁.Equiv m₂) :
(m₁.union m₃ h₁.balanced h₃.balanced).Equiv (m₂.union m₃ h₂.balanced h₃.balanced) := by
revert equiv
simp_to_model [union]
intro equiv
apply List.insertList_perm_of_perm_first equiv
wf_trivial

theorem union!_equiv_congr_left {m₃ : Impl α β} [TransOrd α]
(h₁ : m₁.WF) (h₂ : m₂.WF) (h₃ : m₃.WF) (equiv : m₁.Equiv m₂) :
(m₁.union! m₃).Equiv (m₂.union! m₃) := by
rw [← union_eq_union!, ← union_eq_union!]
apply union_equiv_congr_left
all_goals wf_trivial

theorem union_equiv_congr_right {m₃ : Impl α β} [TransOrd α]
(h₁ : m₁.WF) (h₂ : m₂.WF) (h₃ : m₃.WF) (equiv : m₂.Equiv m₃) :
(m₁.union m₂ h₁.balanced h₂.balanced).Equiv (m₁.union m₃ h₁.balanced h₃.balanced) := by
revert equiv
simp_to_model [union]
intro equiv
apply List.insertList_perm_of_perm_second equiv
all_goals wf_trivial

theorem union!_equiv_congr_right {m₃ : Impl α β} [TransOrd α]
(h₁ : m₁.WF) (h₂ : m₂.WF) (h₃ : m₃.WF) (equiv : m₂.Equiv m₃) :
(m₁.union! m₂).Equiv (m₁.union! m₃) := by
rw [← union_eq_union!, ← union_eq_union!]
apply union_equiv_congr_right
all_goals wf_trivial

/- get? -/
theorem get?_union [TransOrd α] [LawfulEqOrd α] (h₁ : m₁.WF) (h₂ : m₂.WF)
{k : α} :
Expand Down
16 changes: 16 additions & 0 deletions src/Std/Data/DTreeMap/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2260,6 +2260,22 @@ theorem mem_of_mem_union_of_not_mem_left [TransCmp cmp]


/- Equiv -/
theorem union_equiv_congr_left {t₃ : DTreeMap α β cmp} [TransCmp cmp]
(equiv : t₁.Equiv t₂) :
(t₁ ∪ t₃).Equiv (t₂ ∪ t₃) := by
simp only [Union.union]
constructor
have ⟨equiv⟩ := equiv
apply Impl.union_equiv_congr_left t₁.wf t₂.wf t₃.wf equiv

theorem union_equiv_congr_right {t₃ : DTreeMap α β cmp} [TransCmp cmp]
(equiv : t₂.Equiv t₃) :
(t₁ ∪ t₂).Equiv (t₁ ∪ t₃) := by
simp only [Union.union]
constructor
have ⟨equiv⟩ := equiv
apply Impl.union_equiv_congr_right t₁.wf t₂.wf t₃.wf equiv

theorem union_insert_right_equiv_insert_union [TransCmp cmp] {p : (a : α) × β a} :
(t₁ ∪ (t₂.insert p.fst p.snd)).Equiv ((t₁ ∪ t₂).insert p.fst p.snd) :=
⟨Impl.union_insert_right_equiv_insert_union t₁.wf t₂.wf⟩
Expand Down
16 changes: 16 additions & 0 deletions src/Std/Data/DTreeMap/Raw/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,22 @@ theorem mem_of_mem_union_of_not_mem_left [TransCmp cmp]
exact Impl.contains_of_contains_union!_of_contains_eq_false_left h₁ h₂

/- Equiv -/
theorem union_equiv_congr_left {t₃ : Raw α β cmp} [TransCmp cmp]
(h₁ : t₁.WF) (h₂ : t₂.WF) (h₃ : t₃.WF) (equiv : t₁.Equiv t₂) :
(t₁ ∪ t₃).Equiv (t₂ ∪ t₃) := by
simp only [Union.union]
constructor
have ⟨equiv⟩ := equiv
apply Impl.union!_equiv_congr_left h₁ h₂ h₃ equiv

theorem union_equiv_congr_right {t₃ : Raw α β cmp} [TransCmp cmp]
(h₁ : t₁.WF) (h₂ : t₂.WF) (h₃ : t₃.WF) (equiv : t₂.Equiv t₃) :
(t₁ ∪ t₂).Equiv (t₁ ∪ t₃) := by
simp only [Union.union]
constructor
have ⟨equiv⟩ := equiv
apply Impl.union!_equiv_congr_right h₁ h₂ h₃ equiv

theorem union_insert_right_equiv_insert_union [TransCmp cmp] {p : (a : α) × β a}
(h₁ : t₁.WF) (h₂ : t₂.WF) :
(t₁ ∪ (t₂.insert p.fst p.snd)).Equiv ((t₁ ∪ t₂).insert p.fst p.snd) := by
Expand Down
20 changes: 18 additions & 2 deletions src/Std/Data/ExtDHashMap/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ abbrev mk (m : DHashMap α β) : ExtDHashMap α β :=
def lift {γ : Sort w} (f : DHashMap α β → γ) (h : ∀ a b, a ~m b → f a = f b) (m : ExtDHashMap α β) : γ :=
m.1.lift f h

/-- Internal implementation detail of the hash map. -/
def lift₂ {γ : Sort w} (f : DHashMap α β → DHashMap α β → γ) (h : ∀ a b c d, a ~m c → b ~m d → f a b = f c d) (m₁ m₂ : ExtDHashMap α β) : γ :=
Quotient.lift₂ f h m₁.inner m₂.inner

/-- Internal implementation detail of the hash map. -/
def pliftOn {γ : Sort w} (m : ExtDHashMap α β) (f : (a : DHashMap α β) → m = mk a → γ)
(h : ∀ a b h₁ h₂, a ~m b → f a h₁ = f b h₂) : γ :=
m.1.pliftOn (fun a ha => f a (by cases m; cases ha; rfl)) (fun _ _ _ _ h' => h _ _ _ _ h')

@[induction_eliminator, cases_eliminator, elab_as_elim]
theorem inductionOn {motive : ExtDHashMap α β → Prop} (m : ExtDHashMap α β)
theorem inductionOn {motive : ExtDHashMap α β → Prop} (m : ExtDHashMap α β)
(mk : (a : DHashMap α β) → motive (mk a)) : motive m :=
(m.1.inductionOn fun _ => mk _ : motive ⟨m.1⟩)

Expand Down Expand Up @@ -347,7 +351,19 @@ def Const.insertManyIfNewUnit [EquivBEq α] [LawfulHashable α] {ρ : Type w}
m := ⟨m.1.insertIfNew a (), fun _ init step => step (m.2 _ init step)⟩
return m.1

-- TODO (after verification): partition, union
theorem union_congr [EquivBEq α] [LawfulHashable α] (a b c d : DHashMap α β) (h₁ : a ~m c) (h₂ : b ~m d) : a ∪ b ~m c ∪ d :=
DHashMap.Equiv.trans (DHashMap.union_equiv_congr_left h₁) (DHashMap.union_equiv_congr_right h₂)

@[inline, inherit_doc DHashMap.union]
def union [EquivBEq α] [LawfulHashable α] (m₁ m₂ : ExtDHashMap α β) : ExtDHashMap α β := lift₂ (fun x y : DHashMap α β => mk (x.union y))
(fun a b c d equiv₁ equiv₂ => by
simp only [DHashMap.union_eq, mk'.injEq]
apply Quotient.sound
apply union_congr
. exact equiv₁
. exact equiv₂) m₁ m₂

instance [EquivBEq α] [LawfulHashable α] : Union (ExtDHashMap α β) := ⟨union⟩

@[inline, inherit_doc DHashMap.Const.unitOfArray]
def Const.unitOfArray [BEq α] [Hashable α] (l : Array α) :
Expand Down
Loading
Loading