Skip to content

Conversation

Paul-Lez
Copy link

@Paul-Lez Paul-Lez commented Apr 4, 2025

This PR adds a few initial lemmas about unions on Raw₀ to get feedback from @TwoFX.

@TwoFX TwoFX self-assigned this Apr 7, 2025
Comment on lines 2319 to 2320
theorem union_singleton {k : α} {v : β k} [EquivBEq α] [LawfulHashable α] (h : m.val.WF) :
m.val.union {⟨k, v⟩} = m.insert k v := by
Copy link
Member

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}.

Copy link
Author

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

Copy link
Member

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).

@TwoFX TwoFX added the awaiting-author Waiting for PR author to address issues label Apr 8, 2025
@Paul-Lez Paul-Lez changed the title feat: Add sorried lemmas about unions of Raw_0 feat: Add sorried lemmas about unions of Raw₀ Apr 9, 2025
Copy link
Member

@TwoFX TwoFX left a 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) :
Copy link
Member

@TwoFX TwoFX Apr 10, 2025

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.

@TwoFX
Copy link
Member

TwoFX commented Apr 10, 2025

It would also be nice to have size lemmas similar to the ones for insertMany.

@Paul-Lez
Copy link
Author

It would also be nice to have size lemmas similar to the ones for insertMany.

Sounds good, I'll add some more this week!

@Paul-Lez Paul-Lez requested a review from TwoFX April 29, 2025 20:22
@github-actions github-actions bot added the stale label Jul 26, 2025
@TwoFX TwoFX changed the title feat: Add sorried lemmas about unions of Raw₀ feat: redefine HashSet.union and add new lemmas Jul 29, 2025
@TwoFX TwoFX changed the title feat: redefine HashSet.union and add new lemmas feat: redefine HashSet.union and add lemmas Jul 29, 2025
@github-actions github-actions bot removed the stale label Jul 30, 2025
@github-actions github-actions bot added the stale label Sep 25, 2025
@TwoFX
Copy link
Member

TwoFX commented Sep 30, 2025

Work on this will continue at #10611.

@TwoFX TwoFX closed this Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-author Waiting for PR author to address issues stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants