@@ -3056,6 +3056,32 @@ theorem containsKey_insertSmallerList [BEq α] [PartialEquivBEq α] {l₁ l₂ :
30563056 · rw [containsKey_insertListIfNew, ← containsKey_eq_contains_map_fst, Bool.or_comm]
30573057 · rw [containsKey_insertList, ← containsKey_eq_contains_map_fst]
30583058
3059+ theorem contains_insertSmallerList_iff [BEq α] [EquivBEq α] {l toInsert : List ((a : α) × β a)} {k : α} :
3060+ containsKey k (insertSmallerList l toInsert) = true ↔ containsKey k l = true ∨ containsKey k toInsert = true := by
3061+ simp only [containsKey_insertSmallerList, Bool.or_eq_true]
3062+
3063+ theorem contains_of_contains_insertSmallerList_of_contains_right_eq_false [BEq α] [EquivBEq α] {l toInsert : List ((a : α) × β a)} {k : α}
3064+ (h₁ : containsKey k (insertSmallerList l toInsert) = true)
3065+ (h₂ : containsKey k toInsert = false) : containsKey k l = true := by
3066+ have := contains_insertSmallerList_iff.1 h₁
3067+ simpa only [h₂, Bool.false_eq_true, or_false]
3068+
3069+ theorem contains_of_contains_insertSmallerList_of_contains_left_eq_false [BEq α] [EquivBEq α] {l toInsert : List ((a : α) × β a)} {k : α}
3070+ (h₁ : containsKey k (insertSmallerList l toInsert) = true)
3071+ (h₂ : containsKey k l = false) : containsKey k toInsert = true := by
3072+ have := contains_insertSmallerList_iff.1 h₁
3073+ simpa only [h₂, Bool.false_eq_true, false_or]
3074+
3075+ theorem contains_insertSmallerList_of_left [BEq α] [EquivBEq α] {l toInsert : List ((a : α) × β a)} {k : α}
3076+ (contains : containsKey k l = true) : containsKey k (insertSmallerList l toInsert) = true := by
3077+ apply contains_insertSmallerList_iff.2
3078+ exact Or.inl contains
3079+
3080+ theorem contains_insertSmallerList_of_right [BEq α] [EquivBEq α] {l toInsert : List ((a : α) × β a)} {k : α}
3081+ (contains : containsKey k toInsert = true) : containsKey k (insertSmallerList l toInsert) = true := by
3082+ apply contains_insertSmallerList_iff.2
3083+ exact Or.inr contains
3084+
30593085theorem isEmpty_insertListIfNew [BEq α]
30603086 {l toInsert : List ((a : α) × β a)} :
30613087 (List.insertListIfNew l toInsert).isEmpty = (l.isEmpty && toInsert.isEmpty) := by
@@ -3128,7 +3154,7 @@ theorem length_right_le_length_insertSmallerList [BEq α] [EquivBEq α]
31283154 . apply le_of_lt h
31293155 . simp only [length_le_length_insertList]
31303156
3131- theorem getEntry ?_insertListIfNew [BEq α] [PartialEquivBEq α] [LawfulBEq α] {l toInsert : List ((a : α) × β a)}
3157+ theorem getEntry ?_insertListIfNew [BEq α] [EquivBEq α] {l toInsert : List ((a : α) × β a)}
31323158 {k : α} :
31333159 getEntry? k (insertListIfNew l toInsert) =
31343160 (getEntry? k l).or (getEntry? k toInsert) := by
@@ -3145,41 +3171,25 @@ theorem getEntry?_insertListIfNew [BEq α] [PartialEquivBEq α] [LawfulBEq α] {
31453171 rw [getEntry?_eq_none.2 ]
31463172 . simp only [Option.none_or]
31473173 rw [←@getEntry?_congr _ _ _ _ (hd :: tl) hd.fst k hhd]
3148- simp [@getEntry?_cons_self _ _ _ _ tl hd.fst hd.snd]
3174+ simp only [@getEntry?_cons_self _ _ _ _ tl hd.fst hd.snd]
31493175 . simp only [←containsKey_congr hhd, hc]
31503176 . simp only [Bool.not_true, Bool.and_false, Bool.false_eq_true, ↓reduceIte]
31513177 rw [containsKey_congr hhd, containsKey_eq_isSome_getEntry?] at hc
31523178 obtain ⟨v, hv⟩ := Option.isSome_iff_exists.1 hc
31533179 simp [hv]
31543180
3155- theorem getEntry ?_insertListIfNew_of_same_elem [BEq α] [PartialEquivBEq α] [ LawfulBEq α] {l t : List ((a : α) × β a)} {k : α} {v : β k}:
3181+ theorem getEntry ?_insertListIfNew_of_same_elem [BEq α] [LawfulBEq α] {l t : List ((a : α) × β a)} {k : α} {v : β k}:
31563182 getEntry? k (insertListIfNew (⟨k, v⟩ :: l) t) = .some ⟨k, v⟩ := by
3157- simp [getEntry?_insertListIfNew]
3183+ simp only [getEntry?_insertListIfNew, getEntry?_cons_self, Option.some_or ]
31583184
3159- theorem getEntry ?_insertListIfNew_of_contains_eq_false_right [BEq α] [PartialEquivBEq α] [ LawfulBEq α]
3185+ theorem getEntry ?_insertListIfNew_of_contains_eq_false_right [BEq α] [LawfulBEq α]
31603186 {l toInsert : List ((a : α) × β a)} {k : α}
31613187 (not_contains : containsKey k l = false) :
31623188 getEntry? k (insertListIfNew l toInsert) = getEntry? k toInsert := by
3163- induction toInsert generalizing l with
3164- | nil => simpa [insertListIfNew]
3165- | cons h t ih =>
3166- unfold insertListIfNew
3167- by_cases (k = h.fst)
3168- case pos h_eq =>
3169- rw [h_eq]
3170- rw [h_eq] at not_contains
3171- simp only [@insertEntryIfNew_of_containsKey_eq_false α β _ l h.fst h.snd not_contains]
3172- simp only [getEntry?_insertListIfNew_of_same_elem]
3173- simp [getEntry?]
3174- case neg h_ne =>
3175- have := @getEntry?_cons_of_false α β _ t h.fst k h.snd (by simp; rw [Eq.comm]; exact h_ne)
3176- simp [this ]
3177- apply ih
3178- have := @containsKey_insertEntryIfNew α β _ _ l h.fst k h.snd
3179- simp [not_contains] at this
3180- simp [this ]
3181- rw [Eq.comm]
3182- exact h_ne
3189+ rw [getEntry?_insertListIfNew]
3190+ simp only [containsKey_eq_isSome_getEntry?] at not_contains
3191+ rw [(@Option.not_isSome_iff_eq_none ((a : α) × β a) (getEntry? k l)).1 (by simp [not_contains])]
3192+ simp only [Option.none_or]
31833193
31843194theorem getEntry ?_insertListIfNew_of_contains_eq_false [BEq α] [PartialEquivBEq α]
31853195 {l toInsert : List ((a : α) × β a)} {k : α}
@@ -3193,14 +3203,14 @@ theorem getEntry?_insertListIfNew_of_contains_eq_false [BEq α] [PartialEquivBEq
31933203 rw [ih not_contains.right, getEntry?_insertEntryIfNew]
31943204 simp [not_contains]
31953205
3196- theorem getValueCast ?_insertListIfNew_of_contains_eq_false [BEq α] [PartialEquivBEq α] [ LawfulBEq α]
3206+ theorem getValueCast ?_insertListIfNew_of_contains_eq_false [BEq α] [LawfulBEq α]
31973207 {l toInsert : List ((a : α) × β a)} {k : α}
31983208 (not_contains : containsKey k toInsert = false) :
31993209 getValueCast? k (insertListIfNew toInsert l) = getValueCast? k l := by
32003210 rw [getValueCast?_eq_getEntry?, getValueCast?_eq_getEntry?]
32013211 simp only [getEntry?_insertListIfNew_of_contains_eq_false_right not_contains]
32023212
3203- theorem getValue ?_insertSmallerList_of_contains_eq_false [BEq α] [PartialEquivBEq α] [ LawfulBEq α]
3213+ theorem getValue ?_insertSmallerList_of_contains_eq_false [BEq α] [LawfulBEq α]
32043214 {l toInsert : List ((a : α) × β a)} {k : α}
32053215 (not_contains : containsKey k toInsert = false) :
32063216 getValueCast? k (insertSmallerList l toInsert) = getValueCast? k l := by
0 commit comments