Skip to content

Commit 49c8989

Browse files
committed
chore: refactor
1 parent 6131ba2 commit 49c8989

File tree

2 files changed

+50
-62
lines changed

2 files changed

+50
-62
lines changed

src/Std/Data/DHashMap/Internal/RawLemmas.lean

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,22 +2699,12 @@ theorem union_insert_emptyWithCapacity {k : α} {v : β k} [EquivBEq α] [Lawful
26992699
theorem contains_union_of_left [EquivBEq α] [LawfulHashable α] (h₁ : m₁.val.WF)
27002700
(h₂ : m₂.val.WF) {k : α} :
27012701
m₁.contains k → (m₁.union m₂).contains k := by
2702-
simp_to_model [contains, union]
2703-
simp only [List.containsKey_insertSmallerList]
2704-
intro h
2705-
simp only [Bool.or_eq_true]
2706-
apply Or.inl
2707-
exact h
2702+
simp_to_model [contains, union] using List.contains_insertSmallerList_of_left
27082703

27092704
theorem contains_union_of_right [EquivBEq α] [LawfulHashable α] (h₁ : m₁.val.WF)
27102705
(h₂ : m₂.val.WF) {k : α} :
27112706
m₂.contains k → (m₁.union m₂).contains k := by
2712-
simp_to_model [contains, union]
2713-
simp only [List.containsKey_insertSmallerList]
2714-
intro h
2715-
simp only [Bool.or_eq_true]
2716-
apply Or.inr
2717-
exact h
2707+
simp_to_model [contains, union] using List.contains_insertSmallerList_of_right
27182708

27192709
@[simp]
27202710
theorem contains_union [EquivBEq α] [LawfulHashable α] (h₁ : m₁.val.WF)
@@ -2726,51 +2716,33 @@ theorem contains_union [EquivBEq α] [LawfulHashable α] (h₁ : m₁.val.WF)
27262716
theorem contains_union_iff [EquivBEq α] [LawfulHashable α] (h₁ : m₁.val.WF)
27272717
(h₂ : m₂.val.WF) {k : α} :
27282718
(m₁.union m₂).contains k ↔ m₁.contains k ∨ m₂.contains k := by
2729-
apply Iff.trans
2730-
rotate_left
2731-
. apply iff_of_eq
2732-
apply Bool.or_eq_true
2733-
. rw [Bool.coe_iff_coe]
2734-
apply contains_union h₁ h₂
2719+
simp_to_model [union, contains] using List.contains_insertSmallerList_iff
27352720

27362721
theorem contains_of_contains_union_of_contains_right_eq_false [EquivBEq α]
27372722
[LawfulHashable α] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) {k : α} :
27382723
(m₁.union m₂).contains k → m₂.contains k = false → m₁.contains k := by
2739-
intro h₃ h₄
2740-
apply Or.elim <| (@contains_union_iff α β _ _ _ _ _ _ h₁ h₂ k).1 h₃
2741-
. simp only [imp_self]
2742-
. intro n
2743-
rw [n] at h₄
2744-
contradiction
2724+
simp_to_model [union, contains] using List.contains_of_contains_insertSmallerList_of_contains_right_eq_false
27452725

27462726
theorem contains_of_contains_union_of_contains_left_eq_false [EquivBEq α]
27472727
[LawfulHashable α] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) {k : α} :
27482728
(m₁.union m₂).contains k → m₁.contains k = false → m₂.contains k := by
2749-
intro h₃ h₄
2750-
apply Or.elim <| (@contains_union_iff α β _ _ _ _ _ _ h₁ h₂ k).1 h₃
2751-
. intro n
2752-
rw [n] at h₄
2753-
contradiction
2754-
. simp only [imp_self]
2729+
simp_to_model [union, contains] using List.contains_of_contains_insertSmallerList_of_contains_left_eq_false
27552730

27562731
theorem get?_union_of_contains_right_eq_false [LawfulBEq α] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF)
27572732
{k : α} (contains_eq_false : m₂.contains k = false) :
27582733
(m₁.union m₂).get? k = m₁.get? k := by
27592734
revert contains_eq_false
27602735
simp_to_model [union, get?, contains]
27612736
intro contains_eq_false
2762-
apply List.getValue?_insertSmallerList_of_contains_eq_false
2763-
exact contains_eq_false
2764-
2737+
apply List.getValue?_insertSmallerList_of_contains_eq_false contains_eq_false
27652738

27662739
theorem get_union_of_contains_right_eq_false [LawfulBEq α] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF)
27672740
{k : α} (contains_eq_false : m₂.contains k = false) {h'} :
27682741
(m₁.union m₂).get k h' = m₁.get k (contains_of_contains_union_of_contains_right_eq_false h₁ h₂ h' contains_eq_false) := by
27692742
revert contains_eq_false
27702743
simp_to_model [union, get, contains]
27712744
intro contains_eq_false
2772-
apply List.getValue_insertSmallerList_of_contains_eq_false
2773-
exact contains_eq_false
2745+
apply List.getValue_insertSmallerList_of_contains_eq_false contains_eq_false
27742746

27752747
theorem union_insert_right_equiv_union_insert [EquivBEq α] [LawfulHashable α] {p : (a : α) × β a}
27762748
(h₁ : m₁.val.WF) (h₂ : m₂.val.WF) :
@@ -2793,7 +2765,13 @@ theorem getKey!_union_of_contains_right_eq_false [Inhabited α]
27932765
[EquivBEq α] [LawfulHashable α] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) {k : α}
27942766
(h' : m₂.contains k = false) :
27952767
(m₁.union m₂).getKey! k = m₁.getKey! k := by
2768+
simp_to_model
2769+
simp only [List.getKey!_eq_getKey?]
2770+
apply Option.get!.congr_simp
2771+
simp only [List.getKey?_eq_getEntry?]
2772+
congr 1
27962773
sorry
2774+
--rw [List.getEntry?_eq_getValueCast?]
27972775

27982776
theorem getKey!_union_of_mem_right [EquivBEq α] [LawfulHashable α] [Inhabited α] (h₁ : m₁.1.WF)
27992777
(h₂ : m₂.1.WF) {k : α} (mem : m₂.contains k) :

src/Std/Data/Internal/List/Associative.lean

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
30593085
theorem 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

31843194
theorem 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

Comments
 (0)