@@ -3056,6 +3056,78 @@ 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 isEmpty_insertListIfNew [BEq α]
3060+ {l toInsert : List ((a : α) × β a)} :
3061+ (List.insertListIfNew l toInsert).isEmpty = (l.isEmpty && toInsert.isEmpty) := by
3062+ induction toInsert generalizing l with
3063+ | nil => simp [insertListIfNew]
3064+ | cons hd tl ih =>
3065+ rw [insertListIfNew, List.isEmpty_cons, ih, isEmpty_insertEntryIfNew]
3066+ simp
3067+
3068+ theorem isEmpty_insertSmallerList [BEq α]
3069+ {l toInsert : List ((a : α) × β a)} :
3070+ (List.insertSmallerList l toInsert).isEmpty = (l.isEmpty && toInsert.isEmpty) := by
3071+ rw [insertSmallerList]
3072+ split
3073+ case isTrue =>
3074+ simp only [isEmpty_insertListIfNew, Bool.and_comm]
3075+ case isFalse =>
3076+ simp only [isEmpty_insertList]
3077+
3078+ theorem length_insertListIfNew_le [BEq α]
3079+ {l toInsert : List ((a : α) × β a)} :
3080+ (List.insertListIfNew l toInsert).length ≤ l.length + toInsert.length := by
3081+ induction toInsert generalizing l with
3082+ | nil => simp only [List.insertListIfNew, List.length_nil, Nat.add_zero, Nat.le_refl]
3083+ | cons hd tl ih =>
3084+ simp only [insertListIfNew, List.length_cons]
3085+ apply Nat.le_trans ih
3086+ rw [Nat.add_comm tl.length 1 , ← Nat.add_assoc]
3087+ apply Nat.add_le_add _ (Nat.le_refl _)
3088+ apply length_insertEntryIfNew_le
3089+
3090+ theorem length_insertSmallerList_le [BEq α]
3091+ {l toInsert : List ((a : α) × β a)} :
3092+ (List.insertSmallerList l toInsert).length ≤ l.length + toInsert.length := by
3093+ unfold insertSmallerList
3094+ split
3095+ case isTrue =>
3096+ apply Nat.le_trans
3097+ . apply length_insertListIfNew_le
3098+ . simp only [Nat.add_comm, Nat.le_refl]
3099+ case isFalse => simp only [length_insertList_le]
3100+
3101+ theorem length_left_le_length_insertListIfNew [BEq α] [EquivBEq α]
3102+ {l toInsert : List ((a : α) × β a)} :
3103+ l.length ≤ (insertListIfNew l toInsert).length := by
3104+ induction toInsert generalizing l with
3105+ | nil => apply Nat.le_refl
3106+ | cons hd tl ih => exact Nat.le_trans length_le_length_insertEntryIfNew ih
3107+
3108+ theorem length_left_le_length_insertSmallerList [BEq α] [EquivBEq α]
3109+ {l toInsert : List ((a : α) × β a)} :
3110+ l.length ≤ (List.insertSmallerList l toInsert).length := by
3111+ unfold insertSmallerList
3112+ split
3113+ case isTrue h =>
3114+ apply Nat.le_trans
3115+ . exact h
3116+ . apply length_left_le_length_insertListIfNew
3117+ case isFalse => simp only [length_le_length_insertList]
3118+
3119+ theorem length_right_le_length_insertSmallerList [BEq α] [EquivBEq α]
3120+ {l toInsert : List ((a : α) × β a)} :
3121+ toInsert.length ≤ (List.insertSmallerList l toInsert).length := by
3122+ unfold insertSmallerList
3123+ split
3124+ case isTrue => apply length_left_le_length_insertListIfNew
3125+ case isFalse h =>
3126+ simp only [Nat.not_le] at h
3127+ apply Nat.le_trans
3128+ . apply le_of_lt h
3129+ . simp only [length_le_length_insertList]
3130+
30593131section
30603132
30613133variable {β : Type v}
@@ -3206,6 +3278,65 @@ theorem getValue?_insertListConst_of_contains_eq_false [BEq α] [PartialEquivBEq
32063278 rw [containsKey_eq_contains_map_fst]
32073279 simpa using not_contains
32083280
3281+ theorem getValue ?_insertList_of_contains_eq_false [BEq α] [PartialEquivBEq α]
3282+ {l toInsert : List ((_ : α) × β)} {k : α}
3283+ (not_contains : (toInsert.map Sigma.fst).contains k = false) :
3284+ getValue? k (insertList l toInsert) = getValue? k l := by
3285+ rw [getValue?_eq_getEntry?, getValue?_eq_getEntry?, getEntry?_insertList_of_contains_eq_false]
3286+ rw [containsKey_eq_contains_map_fst]
3287+ simpa using not_contains
3288+
3289+ theorem getEntry ?_insertListIfNew_of_contains_eq_false_right [BEq α] [PartialEquivBEq α]
3290+ {l toInsert : List ((_ : α) × β)} {k : α}
3291+ (not_contains : containsKey k l = false) :
3292+ getEntry? k (insertListIfNew l toInsert) = getEntry? k toInsert := by
3293+ induction toInsert generalizing l with
3294+ | nil => simpa [insertListIfNew]
3295+ | cons h t ih =>
3296+ unfold insertListIfNew
3297+ sorry
3298+ -- rw [ containsKey_cons_eq_false ] at not_contains
3299+ -- rw [ih not_contains.right, getEntry?_insertEntryIfNew]
3300+ -- simp [ not_contains ]
3301+
3302+ theorem getEntry ?_insertListIfNew_of_contains_eq_false [BEq α] [PartialEquivBEq α]
3303+ {l toInsert : List ((_ : α) × β)} {k : α}
3304+ (not_contains : containsKey k toInsert = false) :
3305+ getEntry? k (insertListIfNew l toInsert) = getEntry? k l := by
3306+ induction toInsert generalizing l with
3307+ | nil => simp [insertListIfNew]
3308+ | cons h t ih =>
3309+ unfold insertListIfNew
3310+ rw [containsKey_cons_eq_false] at not_contains
3311+ rw [ih not_contains.right, getEntry?_insertEntryIfNew]
3312+ simp [not_contains]
3313+
3314+ theorem getValue ?_insertListIfNew_of_contains_eq_false [BEq α] [PartialEquivBEq α]
3315+ {l toInsert : List ((_ : α) × β)} {k : α}
3316+ (not_contains : (toInsert.map Sigma.fst).contains k = false) :
3317+ getValue? k (insertListIfNew toInsert l) = getValue? k l := by
3318+ rw [getValue?_eq_getEntry?]
3319+ rw [getValue?_eq_getEntry?]
3320+ rw [getEntry?_insertListIfNew_of_contains_eq_false_right]
3321+ rw [containsKey_eq_contains_map_fst]
3322+ simpa using not_contains
3323+
3324+ theorem getValue ?_insertSmallerList_of_contains_eq_false [BEq α] [PartialEquivBEq α] [LawfulBEq α]
3325+ {l toInsert : List ((a : α) × β)} {k : α}
3326+ (not_contains : containsKey k toInsert = false) :
3327+ getValueCast? k (insertSmallerList l toInsert) = getValueCast? k l := by
3328+ unfold insertSmallerList
3329+ split
3330+ case isTrue =>
3331+ simp only [containsKey_eq_contains_map_fst] at not_contains
3332+ simp only [←getValue?_eq_getValueCast?]
3333+ simp only [getValue?_insertListIfNew_of_contains_eq_false not_contains]
3334+ case isFalse =>
3335+ simp only [containsKey_eq_contains_map_fst] at not_contains
3336+ simp only [←getValue?_eq_getValueCast?]
3337+ simp [getValue?_insertList_of_contains_eq_false not_contains]
3338+
3339+
32093340theorem getValue ?_insertListConst_of_mem [BEq α] [EquivBEq α]
32103341 {l : List ((_ : α) × β)} {toInsert : List (α × β)}
32113342 (distinct_l : DistinctKeys l)
0 commit comments