@@ -983,7 +983,7 @@ theorem wfImp_filter [BEq α] [Hashable α] [EquivBEq α] [LawfulHashable α] {m
983983
984984/-! # `insertListₘ` -/
985985
986- theorem toListModel_insertListₘ [BEq α] [Hashable α] [EquivBEq α][LawfulHashable α]
986+ theorem toListModel_insertListₘ [BEq α] [Hashable α] [EquivBEq α] [LawfulHashable α]
987987 {m : Raw₀ α β} {l : List ((a : α) × β a)} (h : Raw.WFImp m.1 ) :
988988 Perm (toListModel (insertListₘ m l).1 .buckets)
989989 (List.insertList (toListModel m.1 .buckets) l) := by
@@ -995,6 +995,37 @@ theorem toListModel_insertListₘ [BEq α] [Hashable α] [EquivBEq α][LawfulHas
995995 apply Perm.trans (ih (wfImp_insert h))
996996 apply List.insertList_perm_of_perm_first (toListModel_insert h) (wfImp_insert h).distinct
997997
998+ /-! # `unionₘ` -/
999+
1000+ theorem insertMany_eq_insertListₘ_toListModel [BEq α] [Hashable α] (m m₂ : Raw₀ α β) :
1001+ insertMany m m₂.1 = insertListₘ m (toListModel m₂.1 .buckets) := by
1002+ simp only [insertMany, bind_pure_comp, map_pure, bind_pure]
1003+ simp only [ForIn.forIn]
1004+ simp only [Raw.forIn_eq_forIn_toListModel, forIn_pure_yield_eq_foldl, Id.run_pure]
1005+ generalize toListModel m₂.val.buckets = l
1006+ suffices ∀ (t : { m' // ∀ (P : Raw₀ α β → Prop ),
1007+ (∀ {m'' : Raw₀ α β} {a : α} {b : β a}, P m'' → P (m''.insert a b)) → P m → P m' }),
1008+ (List.foldl (fun m' p => ⟨m'.val.insert p.1 p.2 , fun P h₁ h₂ => h₁ (m'.2 _ h₁ h₂)⟩) t l).val =
1009+ t.val.insertListₘ l from this _
1010+ intro t
1011+ induction l generalizing m with
1012+ | nil => simp [insertListₘ]
1013+ | cons hd tl ih =>
1014+ simp only [List.foldl_cons, insertListₘ]
1015+ apply ih
1016+
1017+ theorem union_eq_unionₘ [BEq α] [Hashable α] (m₁ m₂ : Raw₀ α β) :
1018+ union m₁ m₂ = unionₘ m₁ m₂ := by
1019+ rw [union, unionₘ]
1020+ split <;> rw [insertMany_eq_insertListₘ_toListModel]
1021+
1022+ theorem toListModel_unionₘ [BEq α] [Hashable α] [EquivBEq α] [LawfulHashable α]
1023+ {m₁ m₂ : Raw₀ α β} (h₁ : Raw.WFImp m₁.1 ) (h₂ : Raw.WFImp m₂.1 ) :
1024+ Perm (toListModel (unionₘ m₁ m₂).1 .buckets)
1025+ (List.insertSmallerList (toListModel m₁.1 .buckets) (toListModel m₂.1 .buckets)) := by
1026+ rw [unionₘ, insertSmallerList, h₁.size_eq, h₂.size_eq]
1027+ split <;> exact toListModel_insertListₘ ‹_›
1028+
9981029end Raw₀
9991030
10001031namespace Raw
@@ -1134,6 +1165,22 @@ theorem toListModel_insertMany_list [BEq α] [Hashable α] [EquivBEq α] [Lawful
11341165 apply toListModel_insertListₘ
11351166 exact h
11361167
1168+ /-! # `union` -/
1169+
1170+ theorem wf_union₀ [BEq α] [Hashable α] [EquivBEq α] [LawfulHashable α]
1171+ {m₁ m₂ : Raw α β} {h₁ : 0 < m₁.buckets.size} {h₂ : 0 < m₂.buckets.size} (h'₁ : m₁.WF)
1172+ (h'₂ : m₂.WF) :
1173+ (Raw₀.union ⟨m₁, h₁⟩ ⟨m₂, h₂⟩).1 .WF := by
1174+ rw [union]
1175+ split <;> exact wf_insertMany₀ ‹_›
1176+
1177+ theorem toListModel_union [BEq α] [Hashable α] [EquivBEq α] [LawfulHashable α] {m₁ m₂ : Raw₀ α β}
1178+ (h₁ : Raw.WFImp m₁.1 ) (h₂ : Raw.WFImp m₂.1 ) :
1179+ Perm (toListModel (m₁.union m₂).1 .buckets)
1180+ (List.insertSmallerList (toListModel m₁.1 .buckets) (toListModel m₂.1 .buckets)) := by
1181+ rw [union_eq_unionₘ]
1182+ exact toListModel_unionₘ h₁ h₂
1183+
11371184/-! # `Const.insertListₘ` -/
11381185
11391186theorem Const.toListModel_insertListₘ {β : Type v} [BEq α] [Hashable α] [EquivBEq α]
0 commit comments