Skip to content

Commit 649d0b4

Browse files
authored
refactor: remove duplicated internal lemmas (#11260)
This PR removes some duplicated internal lemmas of the hash map and tree map infrastructure.
1 parent e5e7a89 commit 649d0b4

File tree

4 files changed

+9
-83
lines changed

4 files changed

+9
-83
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,12 +2080,6 @@ theorem getKey_insertManyIfNewUnit_list_of_contains_eq_false_of_mem [EquivBEq α
20802080
simp_to_model [Const.insertManyIfNewUnit, getKey, contains]
20812081
using List.getKey_insertListIfNewUnit_of_contains_eq_false_of_mem
20822082

2083-
theorem getKey_insertManyIfNewUnit_list_mem_of_contains [EquivBEq α] [LawfulHashable α]
2084-
(h : m.1.WF) {l : List α} {k : α} (contains : m.contains k) {h'} :
2085-
getKey (insertManyIfNewUnit m l).1 k h' = getKey m k contains := by
2086-
simp_to_model [Const.insertManyIfNewUnit, getKey]
2087-
using List.getKey_insertListIfNewUnit_of_contains
2088-
20892083
theorem getKey!_insertManyIfNewUnit_list_of_contains_eq_false_of_contains_eq_false
20902084
[EquivBEq α] [LawfulHashable α] [Inhabited α] (h : m.1.WF) {l : List α} {k : α} :
20912085
m.contains k = false → l.contains k = false →

src/Std/Data/DTreeMap/Internal/Lemmas.lean

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,18 +2666,6 @@ theorem getKey_insertManyIfNewUnit!_list_of_not_mem_of_mem [TransOrd α]
26662666
getKey (insertManyIfNewUnit! t l).1 k' h' = k := by
26672667
simpa only [insertManyIfNewUnit_eq_insertManyIfNewUnit!] using getKey_insertManyIfNewUnit_list_of_not_mem_of_mem h
26682668

2669-
theorem getKey_insertManyIfNewUnit_list_mem_of_mem [TransOrd α]
2670-
(h : t.WF) {l : List α} {k : α} (contains : k ∈ t) {h'} :
2671-
getKey (insertManyIfNewUnit t l h.balanced).1 k h' = getKey t k contains := by
2672-
simp_to_model [Const.insertManyIfNewUnit, getKey] using List.getKey_insertListIfNewUnit_of_contains
2673-
2674-
theorem getKey_insertManyIfNewUnit!_list_mem_of_mem [TransOrd α]
2675-
(h : t.WF) {l : List α} {k : α} (contains : k ∈ t) {h'} :
2676-
getKey (insertManyIfNewUnit! t l).1 k h' = getKey t k contains := by
2677-
simpa only [insertManyIfNewUnit_eq_insertManyIfNewUnit!] using
2678-
getKey_insertManyIfNewUnit_list_mem_of_mem h contains
2679-
(h' := by simpa [insertManyIfNewUnit_eq_insertManyIfNewUnit!])
2680-
26812669
theorem getKey!_insertManyIfNewUnit_list_of_not_mem_of_contains_eq_false [BEq α] [LawfulBEqOrd α]
26822670
[TransOrd α] [Inhabited α] (h : t.WF) {l : List α} {k : α} :
26832671
¬ k ∈ t → l.contains k = false

src/Std/Data/DTreeMap/Internal/WF/Lemmas.lean

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,12 +1073,6 @@ theorem WF.containsThenInsertIfNew! {_ : Ord α} [TransOrd α] {k : α} {v : β
10731073
(h : l.WF) : (l.containsThenInsertIfNew! k v).2.WF := by
10741074
simpa [containsThenInsertIfNew!_snd_eq_insertIfNew!] using WF.insertIfNew! (h := h)
10751075

1076-
theorem toListModel_containsThenInsertIfNew! [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α] {k : α}
1077-
{v : β k} {t : Impl α β} (htb : t.Balanced) (hto : t.Ordered) :
1078-
(t.containsThenInsertIfNew k v htb).2.impl.toListModel.Perm (insertEntryIfNew k v t.toListModel) := by
1079-
rw [containsThenInsertIfNew_snd_eq_insertIfNew]
1080-
exact toListModel_insertIfNew htb hto
1081-
10821076
/-!
10831077
### filterMap
10841078
-/

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

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -712,23 +712,18 @@ theorem getValueCast_cons [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)}
712712
rw [getValueCast, Option.get_congr getValueCast?_cons]
713713
split <;> simp [getValueCast]
714714

715-
theorem getValueCast_mem [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {a : α}
716-
(h : containsKey a l) :
715+
theorem getValueCast_mem [BEq α] [LawfulBEq α]
716+
{l : List ((a : α) × β a)} {a : α} (h : containsKey a l = true) :
717717
⟨a, getValueCast a l h⟩ ∈ l := by
718718
induction l with
719719
| nil => simp at h
720720
| cons hd tl ih =>
721-
simp only [List.mem_cons]
722-
by_cases hd_a: hd.1 == a
723-
· simp only [beq_iff_eq] at hd_a
724-
rw [Sigma.ext_iff]
725-
simp only [hd_a, getValueCast, getValueCast?, beq_self_eq_true, ↓reduceDIte, Option.get_some,
726-
cast_heq, and_self, true_or]
727-
· rw [getValueCast_cons]
728-
simp only [hd_a, Bool.false_eq_true, ↓reduceDIte]
729-
rw [containsKey_cons] at h
721+
by_cases hd_a : hd.1 == a
722+
· simp [getValueCast, getValueCast?, Sigma.ext_iff, LawfulBEq.eq_of_beq hd_a]
723+
· rw [containsKey_cons] at h
730724
simp only [hd_a, Bool.false_or] at h
731-
simp [ih h]
725+
simp only [getValueCast, getValueCast?, hd_a, Bool.false_eq_true, ↓reduceDIte, List.mem_cons]
726+
exact Or.inr (ih h)
732727

733728
theorem getValueCast_of_mem [BEq α] [LawfulBEq α] {l : List ((a : α) × β a)} {x : (a : α) × β a}
734729
(h : x ∈ l) (distinct : DistinctKeys l) :
@@ -1575,10 +1570,6 @@ theorem getValue?_insertEntry_of_beq [BEq α] [PartialEquivBEq α] {l : List ((_
15751570
· rw [insertEntry_of_containsKey_eq_false h', getValue?_cons_of_true h]
15761571
· rw [insertEntry_of_containsKey h', getValue?_replaceEntry_of_true h' h]
15771572

1578-
theorem getValue?_insertEntry_of_self [BEq α] [EquivBEq α] {l : List ((_ : α) × β)} {k : α}
1579-
{v : β} : getValue? k (insertEntry k v l) = some v :=
1580-
getValue?_insertEntry_of_beq BEq.rfl
1581-
15821573
theorem getValue?_insertEntry_of_false [BEq α] [PartialEquivBEq α] {l : List ((_ : α) × β)}
15831574
{k a : α} {v : β} (h : (k == a) = false) : getValue? a (insertEntry k v l) = getValue? a l := by
15841575
cases h' : containsKey k l
@@ -6180,27 +6171,14 @@ theorem length_filterMap_eq_length_iff [BEq α] [LawfulBEq α] {f : (a : α) →
61806171
rw [getValueCast_of_mem hx distinct] at h
61816172
exact h
61826173

6183-
theorem key_getValueCast_mem [BEq α] [LawfulBEq α]
6184-
{l : List ((a : α) × β a)} {a : α} (h : containsKey a l = true) :
6185-
⟨a, getValueCast a l h⟩ ∈ l := by
6186-
induction l with
6187-
| nil => simp at h
6188-
| cons hd tl ih =>
6189-
by_cases hd_a : hd.1 == a
6190-
· simp [getValueCast, getValueCast?, Sigma.ext_iff, LawfulBEq.eq_of_beq hd_a]
6191-
· rw [containsKey_cons] at h
6192-
simp only [hd_a, Bool.false_or] at h
6193-
simp only [getValueCast, getValueCast?, hd_a, Bool.false_eq_true, ↓reduceDIte, List.mem_cons]
6194-
exact Or.inr (ih h)
6195-
61966174
theorem forall_mem_iff_forall_contains_getValueCast [BEq α] [LawfulBEq α]
61976175
{l : List ((a : α) × β a)} {p : (a : α) → β a → Prop} (distinct : DistinctKeys l) :
61986176
(∀ (x : (a : α) × β a), x ∈ l → p x.1 x.2) ↔
61996177
∀ (a: α) (h : containsKey a l), p a (getValueCast a l h) := by
62006178
constructor
62016179
· intro h a ha
62026180
specialize h ⟨a, getValueCast a l ha⟩
6203-
apply h (key_getValueCast_mem ha)
6181+
apply h (getValueCast_mem ha)
62046182
· intro h x hx
62056183
rw [← getValueCast_of_mem hx distinct]
62066184
apply h
@@ -7874,12 +7852,6 @@ theorem getKeyD_minKey! [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α] [Inhab
78747852
getKeyD (minKey! l) l fallback = minKey! l := by
78757853
simpa [minKey_eq_minKey!] using getKeyD_minKey hd (he := he)
78767854

7877-
theorem minKey!_eraseKey_eq_iff_beq_minKey_eq_false [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
7878-
[Inhabited α] {l : List ((a : α) × β a)} (hd : DistinctKeys l) {k}
7879-
(he : (eraseKey k l).isEmpty = false) :
7880-
(eraseKey k l |> minKey!) = minKey! l ↔ (k == (minKey! l)) = false := by
7881-
simpa [minKey_eq_minKey!] using minKey_eraseKey_eq_iff_beq_minKey_eq_false hd (he := he)
7882-
78837855
theorem minKey!_eraseKey_eq_iff_beq_minKey!_eq_false [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
78847856
[Inhabited α] {l : List ((a : α) × β a)} (hd : DistinctKeys l) {k}
78857857
(he : (eraseKey k l).isEmpty = false) :
@@ -8078,19 +8050,12 @@ theorem getKeyD_minKeyD [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
80788050
getKeyD (minKeyD l fallback) l fallback' = minKeyD l fallback := by
80798051
simpa [minKey_eq_minKeyD (fallback := fallback)] using getKeyD_minKey hd (he := he)
80808052

8081-
theorem minKeyD_eraseKey_eq_iff_beq_minKey_eq_false [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
8082-
{l : List ((a : α) × β a)} (hd : DistinctKeys l) {k fallback}
8083-
(he : (eraseKey k l).isEmpty = false) :
8084-
(eraseKey k l |> minKeyD <| fallback) = minKeyD l fallback ↔
8085-
(k == (minKeyD l fallback)) = false := by
8086-
simpa [minKey_eq_minKeyD (fallback := fallback)] using
8087-
minKey_eraseKey_eq_iff_beq_minKey_eq_false hd (he := he)
8088-
80898053
theorem minKeyD_eraseKey_eq_iff_beq_minKeyD_eq_false [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
80908054
{l : List ((a : α) × β a)} (hd : DistinctKeys l) {k fallback}
80918055
(he : (eraseKey k l).isEmpty = false) :
80928056
(eraseKey k l |> minKeyD <| fallback) = minKeyD l fallback ↔
80938057
(k == (minKeyD l fallback)) = false := by
8058+
80948059
simpa [minKey_eq_minKeyD (fallback := fallback)] using
80958060
minKey_eraseKey_eq_iff_beq_minKey_eq_false hd (he := he)
80968061

@@ -8757,13 +8722,6 @@ theorem getKeyD_maxKey! [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α] [Inhab
87578722
letI : Ord α := .opposite inferInstance
87588723
getKeyD_minKey! hd he
87598724

8760-
theorem maxKey!_eraseKey_eq_iff_beq_maxKey_eq_false [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
8761-
[Inhabited α] {l : List ((a : α) × β a)} (hd : DistinctKeys l) {k}
8762-
(he : (eraseKey k l).isEmpty = false) :
8763-
(eraseKey k l |> maxKey!) = maxKey! l ↔ (k == (maxKey! l)) = false :=
8764-
letI : Ord α := .opposite inferInstance
8765-
minKey!_eraseKey_eq_iff_beq_minKey_eq_false hd he
8766-
87678725
theorem maxKey!_eraseKey_eq_iff_beq_maxKey!_eq_false [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
87688726
[Inhabited α] {l : List ((a : α) × β a)} (hd : DistinctKeys l) {k}
87698727
(he : (eraseKey k l).isEmpty = false) :
@@ -8976,14 +8934,6 @@ theorem getKeyD_maxKeyD [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
89768934
letI : Ord α := .opposite inferInstance
89778935
getKeyD_minKeyD hd he
89788936

8979-
theorem maxKeyD_eraseKey_eq_iff_beq_maxKey_eq_false [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
8980-
{l : List ((a : α) × β a)} (hd : DistinctKeys l) {k fallback}
8981-
(he : (eraseKey k l).isEmpty = false) :
8982-
(eraseKey k l |> maxKeyD <| fallback) = maxKeyD l fallback ↔
8983-
(k == (maxKeyD l fallback)) = false :=
8984-
letI : Ord α := .opposite inferInstance
8985-
minKeyD_eraseKey_eq_iff_beq_minKey_eq_false hd he
8986-
89878937
theorem maxKeyD_eraseKey_eq_iff_beq_maxKeyD_eq_false [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α]
89888938
{l : List ((a : α) × β a)} (hd : DistinctKeys l) {k fallback}
89898939
(he : (eraseKey k l).isEmpty = false) :

0 commit comments

Comments
 (0)