@@ -1032,6 +1032,20 @@ theorem distinct_keys_toList [EquivBEq α] [LawfulHashable α] (h : m.1.WF) :
10321032 m.1 .toList.Pairwise (fun a b => (a.1 == b.1 ) = false) := by
10331033 simp_to_model [toList] using List.pairwise_fst_eq_false
10341034
1035+ theorem nodup_toList [EquivBEq α] [LawfulHashable α] (h : m.1 .WF) :
1036+ m.1 .toList.Nodup := by
1037+ simp_to_model [toList] using List.nodup_of_distinctKeys
1038+
1039+ theorem mem_toList_insert_of_contains_eq_false [EquivBEq α] [LawfulHashable α] (h : m.1 .WF)
1040+ {k : α} {v : β k} {x : (a : α) × β a} (h' : m.contains k = false) :
1041+ x ∈ (m.insert k v).1 .toList ↔ x = ⟨k, v⟩ ∨ x ∈ m.1 .toList := by
1042+ rw [contains_eq_containsₘ] at h'
1043+ simp [Raw.toList, insert_eq_insertₘ, insertₘ, h', Bool.false_eq_true, ↓reduceIte,
1044+ Raw.foldRev_cons, List.append_nil]
1045+ rw [List.Perm.mem_iff (toListModel_expandIfNecessary (consₘ m k v))]
1046+ rw [List.Perm.mem_iff (toListModel_consₘ m (Raw.WF.out h) k v)]
1047+ simp
1048+
10351049namespace Const
10361050
10371051variable {β : Type v} (m : Raw₀ α (fun _ => β))
@@ -1081,6 +1095,28 @@ theorem distinct_keys_toList [EquivBEq α] [LawfulHashable α] (h : m.1.WF) :
10811095 (Raw.Const.toList m.1 ).Pairwise (fun a b => (a.1 == b.1 ) = false) := by
10821096 simp_to_model [Const.toList] using List.pairwise_fst_eq_false_map_toProd
10831097
1098+ theorem nodup_toList [EquivBEq α] [LawfulHashable α] (h : m.1 .WF) :
1099+ (Raw.Const.toList m.1 ).Nodup := by
1100+ simp_to_model [Const.toList] using List.nodup_map_of_distinctKeys
1101+
1102+ theorem mem_toList_insert_of_contains_eq_false [EquivBEq α] [LawfulHashable α] (h : m.1 .WF)
1103+ {k : α} {v : β} {x : α × β} (h' : m.contains k = false) :
1104+ x ∈ (Raw.Const.toList (m.insert k v).1 ) ↔ x = ⟨k, v⟩ ∨ x ∈ Raw.Const.toList m.1 := by
1105+ rw [contains_eq_containsₘ] at h'
1106+ simp only [Raw.Const.toList, insert_eq_insertₘ, insertₘ, h', Bool.false_eq_true, ↓reduceIte,
1107+ Raw.foldRev_cons_mk, List.append_nil]
1108+ rw [← List.mem_map_toProd_iff_mem, ← List.mem_map_toProd_iff_mem]
1109+ rw [List.Perm.mem_iff (toListModel_expandIfNecessary (consₘ m k v))]
1110+ rw [List.Perm.mem_iff (toListModel_consₘ m (Raw.WF.out h) k v)]
1111+ simp only [List.mem_cons, Sigma.mk.injEq, heq_eq_eq]
1112+ have : x.fst = k ∧ x.snd = v ↔ x = (k,v) := by
1113+ constructor
1114+ · intro h
1115+ simp [← h.1 , ← h.2 ]
1116+ · intro h
1117+ simp [h]
1118+ rw [this ]
1119+
10841120end Const
10851121
10861122omit [Hashable α] [BEq α] in
@@ -5184,16 +5220,6 @@ theorem snd_partition_not_eq_fst_partition [EquivBEq α] [LawfulHashable α]
51845220 rw [← fst_partition_not_eq_snd_partition]
51855221 simp
51865222
5187- private theorem mem_toList_insert_of_contains_eq_false [EquivBEq α] [LawfulHashable α] (h : m.1 .WF)
5188- {k : α} {v : β k} {x : (a : α) × β a} (h' : m.contains k = false) :
5189- x ∈ (m.insert k v).1 .toList ↔ x ∈ m.1 .toList ∨ x = ⟨k, v⟩ := by
5190- rw [contains_eq_containsₘ] at h'
5191- simp only [Raw.toList, insert_eq_insertₘ, insertₘ, h', Bool.false_eq_true, ↓reduceIte,
5192- Raw.foldRev_cons, List.append_nil]
5193- rw [List.Perm.mem_iff (toListModel_expandIfNecessary (consₘ m k v))]
5194- rw [List.Perm.mem_iff (toListModel_consₘ m (Raw.WF.out h) k v)]
5195- simp [Or.comm]
5196-
51975223private theorem mem_toList_fst_partition [EquivBEq α] [LawfulHashable α] (h : m.1 .WF)
51985224 {p : (a : α) → β a → Bool} (x : (a : α) × β a) :
51995225 x ∈ (m.partition p).1 .1 .toList ↔ x ∈ m.1 .toList ∧ p x.1 x.2 = true := by
@@ -5228,10 +5254,10 @@ private theorem mem_toList_fst_partition [EquivBEq α] [LawfulHashable α] (h :
52285254 | inr h =>
52295255 cases h with
52305256 | inl h =>
5231- apply Or.inr h
5232- | inr h =>
52335257 rw [h]
52345258 simp [hhd]
5259+ | inr h =>
5260+ apply Or.inr h
52355261 · intro h
52365262 cases h with
52375263 | inl h =>
@@ -5278,23 +5304,6 @@ private theorem mem_toList_fst_partition [EquivBEq α] [LawfulHashable α] (h :
52785304 · simp only [List.pairwise_cons] at h₄
52795305 apply h₄.2
52805306
5281- private theorem nodup_toList [EquivBEq α] [LawfulHashable α] (h : m.1 .WF) : m.1 .toList.Nodup := by
5282- simp only [List.Nodup, ne_eq]
5283- suffices ∀ (l : List ((a :α) × β a)) (h₁ : List.Pairwise (fun a b => (a.1 == b.1 ) = false) l),
5284- List.Pairwise (fun a b => a ≠ b) l from this m.1 .toList (distinct_keys_toList _ h)
5285- intro l
5286- induction l with
5287- | nil => simp
5288- | cons hd tl ih =>
5289- simp
5290- intro h₁ h₂
5291- refine And.intro ?_ (ih h₂)
5292- intro a ha
5293- false_or_by_contra
5294- rename_i h'
5295- specialize h₁ a ha
5296- simp [h'] at h₁
5297-
52985307theorem fst_partition_equiv_filter [EquivBEq α] [LawfulHashable α]
52995308 {p : (a : α) → β a → Bool} (h : m.1 .WF) :
53005309 (m.partition p).1 .1 .Equiv (m.filter p).1 := by
0 commit comments