-
Notifications
You must be signed in to change notification settings - Fork 672
feat: redefine HashSet.union
and add lemmas
#7823
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
Conversation
theorem union_singleton {k : α} {v : β k} [EquivBEq α] [LawfulHashable α] (h : m.val.WF) : | ||
m.val.union {⟨k, v⟩} = m.insert k v := by |
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.
This lemma becomes strictly more general (as a simp
lemma) if you don't take k
and v
separately, but take a parameter p
from the sigma type and state the left-hand side as m.val.union {p}
.
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.
That makes sense - I've made the change you suggested. Now that I think of it, don't we want to formulate this lemma in terms of Raw_0
rather than Raw
, e.g. changing the goal to something of the form
m.union ⟨{p}, by sorry⟩ = m.insert p.fst p.snd
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.
Thinking about this more: since there is the lemma Std.DHashMap.singleton_eq_insert
, the LHS of this lemma will actually not be in simp
normal form in any user-facing situation, which suggests that we shouldn't have the lemma in this form. The correct statement is going to be a variant of your union_insert
below, namely m.union (empty.insert k v) = m.insert k v
(unlike the general case below, this is true on the nose, not just up to equivalence).
Raw₀
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.
Presumably there are also left
variants of the right
lemmas?
(m₁.union m₂).get k h' = m₁.get k (contains_of_contains_union_of_contains_eq_false h₁ h₂ h' contains_eq_false) := by | ||
sorry | ||
|
||
theorem union_insert [EquivBEq α] [LawfulHashable α] {p : (a : α) × β a} (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) : |
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.
This is only true up to equivalence of hash maps, as shown by the following example:
import Std
open Std
def m₁ : HashMap Nat Nat := ∅
def m₂ : HashMap Nat Nat := .ofList [(0, 0)]
-- Std.HashMap.ofList [(16, 1), (0, 0)]
#eval (m₁.union m₂).insert 16 1
-- Std.HashMap.ofList [(0, 0), (16, 1)]
#eval m₁.union (m₂.insert 16 1)
So the statement of this lemma should involve Equiv
.
It would also be nice to have |
Sounds good, I'll add some more this week! |
Raw₀
HashSet.union
and add new lemmas
HashSet.union
and add new lemmasHashSet.union
and add lemmas
Work on this will continue at #10611. |
This PR adds a few initial lemmas about unions on
Raw₀
to get feedback from @TwoFX.