-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: HashMap.toList_insert_perm_of_not_mem #6304
base: master
Are you sure you want to change the base?
Conversation
Mathlib CI status (docs):
|
open _root_.List in | ||
theorem toList_insert_perm_of_not_contains [EquivBEq α] [LawfulHashable α] (h : m.1.WF) | ||
(k : α) (v : β k) (h' : m.contains k = false) : | ||
(m.insert k v).1.toList ~ ⟨k, v⟩ :: m.1.toList := by | ||
revert h' | ||
simp_to_model | ||
intro h' | ||
exact Perm.trans (toListModel_insert (Raw.WF.out h)) (by simp [insertEntry, h']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is how I had envisioned this working: you prove
private theorem perm_of_perm {l₁ l₂ l₃ : List α} (h : List.Perm l₁ l₂) :
List.Perm l₁ l₃ ↔ List.Perm l₂ l₃ :=
⟨h.symm.trans, h.trans⟩
and add ← `(perm_of_perm)
to congrNames
. Then this lemma is proved like this:
open _root_.List in | |
theorem toList_insert_perm_of_not_contains [EquivBEq α] [LawfulHashable α] (h : m.1.WF) | |
(k : α) (v : β k) (h' : m.contains k = false) : | |
(m.insert k v).1.toList ~ ⟨k, v⟩ :: m.1.toList := by | |
revert h' | |
simp_to_model | |
intro h' | |
exact Perm.trans (toListModel_insert (Raw.WF.out h)) (by simp [insertEntry, h']) | |
open _root_.List in | |
theorem toList_insert_perm_of_not_contains [EquivBEq α] [LawfulHashable α] (h : m.1.WF) | |
(k : α) (v : β k) : m.contains k = false → | |
(m.insert k v).1.toList ~ ⟨k, v⟩ :: m.1.toList := by | |
simp_to_model using Perm.of_eq ∘ insertEntry_of_containsKey_eq_false |
To spell it out explicitly: after simp_to_model
, it should always be possible to generalize toListModel m.1.buckets = l
so that m
is then no longer present in the goal.
open List in | ||
theorem toList_insert_perm_of_not_mem [EquivBEq α] [LawfulHashable α] | ||
(k : α) (v : β) (h' : ¬k ∈ m) : | ||
(m.insert k v).toList ~ (k, v) :: m.toList := by | ||
have t := DHashMap.toList_insert_perm_of_not_mem (β := fun _ => β) k v h' | ||
simp at t | ||
replace t := Perm.map (fun x : (_ : α) × β => (x.fst, x.snd)) t | ||
simpa [Function.comp_def] using t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way this is supposed to work is that you prove Const.toList_insert_perm_of_not_contains
in Internal/RawLemmas.lean
and DHashMap/(Raw)Lemmas.lean
and then just apply that here. toList_inner
and insert_inner
should not exist.
To give more details:
- I think you should drop
Const.toListModel
and change the statement ofConst.toList_eq_toListModel
toRaw.Const.toList m = (toListModel m.buckets).map (fun ⟨k, v⟩ => (k, v))
. - Then you should add
Raw.Const.toList_eq_toListModel
toqueryNames
inInternal/RawLemmas.lean
. Then you can add← `(perm_of_perm ∘ List.Perm.map _)
tocongrNames
(in addition to what was already added in my previous comment). This will allow you to put
namespace Const
variable {β : Type v} (m : Raw₀ α (fun _ => β))
open _root_.List in
theorem Const.toList_insert_perm_of_not_contains [EquivBEq α] [LawfulHashable α] (h : m.1.WF) {k : α} {v : β} :
m.contains k = false → Raw.Const.toList (m.insert k v).1 ~ (k, v) :: (Raw.Const.toList m.1) := by
simp_to_model
exact fun h => by simp [insertEntry_of_containsKey_eq_false h]
end Const
in the bottom of Internal/RawLemmas.lean
, from which the statements about (D)HashMap.toList
follow imediately.
I should add that this still isn't perfect; it would be even better to prove containsKey k l = false → List.map (fun x => (x.fst, x.snd)) (insertEntry k v l) = (k, v) :: List.map (fun x => (x.fst, x.snd)) l
in List/Associative.lean
(perhaps as part of the theory of a "toListOfPairs
" function) instead of inlining the proof.
WIP, this is stacked on top of #6232, and may not make sense at all if that requires substantial revisions.