Skip to content
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d28319d
push work so far
wkrozowski Nov 19, 2025
fc9c400
Sublemma works
wkrozowski Nov 19, 2025
26bffd8
Sublemma now works
wkrozowski Nov 19, 2025
d586c3f
Main lemma goes through
wkrozowski Nov 19, 2025
ae7a4ac
Add first user-facing lemmas
wkrozowski Nov 19, 2025
54f89f9
Add working model lemma
wkrozowski Nov 20, 2025
9b0035c
Work on the train
wkrozowski Nov 20, 2025
a560481
Lemmas go through
wkrozowski Nov 20, 2025
44f9398
Progress with the const BEq
wkrozowski Nov 26, 2025
f4bce74
push
wkrozowski Nov 26, 2025
4d63159
Add const lemma
wkrozowski Nov 26, 2025
09452de
Add perm lemmas
wkrozowski Nov 26, 2025
fa88c40
Congruence lemmas continued
wkrozowski Nov 26, 2025
fcad743
fix scoping issue
wkrozowski Nov 26, 2025
bd7dca5
Remove unit variant and add the raw variant
wkrozowski Nov 26, 2025
f37ad5f
Add lemmas to DHashMap
wkrozowski Nov 26, 2025
9ce4b8c
Add Raw DHashMapLemmas
wkrozowski Nov 26, 2025
3afdb45
Done with lemmas
wkrozowski Nov 26, 2025
d985064
ExtHashMap done
wkrozowski Nov 26, 2025
7ed80a9
Add BEq to ExtHashSet
wkrozowski Nov 27, 2025
99b62eb
Merge branch 'master' into wojciech/hashmap_beq2
wkrozowski Nov 27, 2025
4a93e11
Fix merge issue
wkrozowski Nov 27, 2025
59a0ec6
Remove unnecessary hashable instance
wkrozowski Nov 27, 2025
53e4653
Remove unnecessary hashable
wkrozowski Nov 27, 2025
cea11fe
Continue removing useless Hashable instance
wkrozowski Nov 27, 2025
a87d1e0
Remove whitespace
wkrozowski Nov 27, 2025
59738d1
Fix formatting
wkrozowski Nov 27, 2025
396efbd
Merge branch 'master' into wojciech/hashmap_beq2
wkrozowski Nov 27, 2025
8a84316
Remove unused code
wkrozowski Nov 27, 2025
b928c86
Refactor ExtDHashMap code
wkrozowski Nov 28, 2025
483f612
One more refactor
wkrozowski Nov 28, 2025
4d23872
Merge branch 'master' into wojciech/hashmap_beq2
wkrozowski Dec 1, 2025
d1f18b9
First part of addressing Markus' comments
wkrozowski Dec 2, 2025
dbc9784
Proof golfing
wkrozowski Dec 2, 2025
40ef92e
Fix notation
wkrozowski Dec 2, 2025
b3b2f97
Apply Markus' suggestions
wkrozowski Dec 2, 2025
84b1bd7
Try refactoring `ExtDHashMap`
wkrozowski Dec 2, 2025
1a93a9f
cleanup extensional variants
wkrozowski Dec 2, 2025
4e012a6
further renaming
wkrozowski Dec 2, 2025
3bd07be
Refactor
wkrozowski Dec 4, 2025
7ef173e
Further refactor
wkrozowski Dec 4, 2025
3b281d5
Remove `beqUnit`
wkrozowski Dec 4, 2025
c47995a
Weaken the instances for the Const variant
wkrozowski Dec 5, 2025
8adfa66
Cleanup
wkrozowski Dec 5, 2025
81ca6a5
Further cleanup
wkrozowski Dec 5, 2025
b1ed589
Further cleanup
wkrozowski Dec 5, 2025
06c5d1d
One more round of cleanup
wkrozowski Dec 5, 2025
ea94efb
Fix whitespace
wkrozowski Dec 5, 2025
3079fa6
Further cleanup
wkrozowski Dec 5, 2025
f353aea
Proof golf
wkrozowski Dec 5, 2025
3074be8
Add `any_eq`
wkrozowski Dec 8, 2025
02434df
Minor cleanup
wkrozowski Dec 8, 2025
a269546
chore: proof golf
wkrozowski Dec 8, 2025
b2c392f
chore: docstrings
wkrozowski Dec 8, 2025
d0e16d9
chore: cleanup
wkrozowski Dec 8, 2025
179addf
chore: fix indentation
wkrozowski Dec 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Std/Data/DHashMap/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,16 @@ instance [BEq α] [Hashable α] : Union (DHashMap α β) := ⟨union⟩
instance [BEq α] [Hashable α] : Inter (DHashMap α β) := ⟨inter⟩
instance [BEq α] [Hashable α] : SDiff (DHashMap α β) := ⟨diff⟩

/-- Internal implementation detail of the hash map. -/
def beq [LawfulBEq α] [∀ k, BEq (β k)] (a b : DHashMap α β) : Bool :=
Raw₀.beq ⟨a.1, a.2.size_buckets_pos⟩ ⟨b.1, b.2.size_buckets_pos⟩

instance [LawfulBEq α] [∀ k, BEq (β k)] : BEq (DHashMap α β) := ⟨beq⟩

/-- Internal implementation detail of the hash map. -/
def Const.beq {β : Type v} [BEq α] [BEq β] (m₁ m₂ : DHashMap α (fun _ => β)) : Bool :=
Raw₀.Const.beq ⟨m₁.1, m₁.2.size_buckets_pos⟩ ⟨m₂.1, m₂.2.size_buckets_pos⟩

section Unverified

/-! We currently do not provide lemmas for the functions below. -/
Expand Down
9 changes: 8 additions & 1 deletion src/Std/Data/DHashMap/Internal/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,14 @@ def interSmaller [BEq α] [Hashable α] (m₁ : Raw₀ α β) (m₂ : Raw α β)
def inter [BEq α] [Hashable α] (m₁ m₂ : Raw₀ α β) : Raw₀ α β :=
if m₁.1.size ≤ m₂.1.size then m₁.filter fun k _ => m₂.contains k else interSmaller m₁ m₂

/-- Internal implementation detail of the hash map -/
def beq [BEq α] [LawfulBEq α] [Hashable α] [∀ k, BEq (β k)] (m₁ m₂ : Raw₀ α β) : Bool :=
if m₁.1.size ≠ m₂.1.size then false else m₁.1.all (fun k v => m₂.get? k == some v)

/-- Internal implementation detail of the hash map -/
@[inline] def diff [BEq α] [Hashable α] (m₁ m₂ : Raw₀ α β) : Raw₀ α β :=
if m₁.1.size ≤ m₂.1.size then m₁.filter (fun k _ => !m₂.contains k) else (eraseManyEntries m₁ m₂.1).1


section

variable {β : Type v}
Expand All @@ -505,6 +508,10 @@ def Const.get? [BEq α] [Hashable α] (m : Raw₀ α (fun _ => β)) (a : α) : O
let ⟨i, h⟩ := mkIdx buckets.size h (hash a)
buckets[i].get? a

/-- Internal implementation detail of the hash map -/
def Const.beq [BEq α] [Hashable α] [BEq β] (m₁ m₂ : Raw₀ α (fun _ => β)) : Bool :=
if m₁.1.size ≠ m₂.1.size then false else m₁.1.all (fun k v => Const.get? m₂ k == some v)

/-- Internal implementation detail of the hash map -/
def Const.get [BEq α] [Hashable α] (m : Raw₀ α (fun _ => β)) (a : α)
(hma : m.contains a) : β :=
Expand Down
8 changes: 8 additions & 0 deletions src/Std/Data/DHashMap/Internal/Raw.lean
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ theorem inter_eq [BEq α] [Hashable α] {m₁ m₂ : Raw α β} (h₁ : m₁.WF)
m₁.inter m₂ = Raw₀.inter ⟨m₁, h₁.size_buckets_pos⟩ ⟨m₂, h₂.size_buckets_pos⟩ := by
simp [Raw.inter, h₁.size_buckets_pos, h₂.size_buckets_pos]

theorem beq_eq [BEq α] [Hashable α] [LawfulBEq α] [∀ k, BEq (β k)] {m₁ m₂ : Raw α β} (h₁ : m₁.WF) (h₂ : m₂.WF) :
m₁.beq m₂ = Raw₀.beq ⟨m₁, h₁.size_buckets_pos⟩ ⟨m₂, h₂.size_buckets_pos⟩ := by
simp [Raw.beq, h₁.size_buckets_pos, h₂.size_buckets_pos]

theorem Const.beq_eq {β : Type v} [BEq α] [Hashable α] [BEq β] {m₁ m₂ : Raw α (fun _ => β)} (h₁ : m₁.WF) (h₂ : m₂.WF) :
Raw.Const.beq m₁ m₂ = Raw₀.Const.beq ⟨m₁, h₁.size_buckets_pos⟩ ⟨m₂, h₂.size_buckets_pos⟩ := by
simp [Raw.Const.beq, h₁.size_buckets_pos, h₂.size_buckets_pos]

theorem diff_eq [BEq α] [Hashable α] {m₁ m₂ : Raw α β} (h₁ : m₁.WF) (h₂ : m₂.WF) :
m₁.diff m₂ = Raw₀.diff ⟨m₁, h₁.size_buckets_pos⟩ ⟨m₂, h₂.size_buckets_pos⟩ := by
simp [Raw.diff, h₁.size_buckets_pos, h₂.size_buckets_pos]
Expand Down
46 changes: 35 additions & 11 deletions src/Std/Data/DHashMap/Internal/RawLemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import all Std.Data.DHashMap.Internal.Defs
public import Std.Data.DHashMap.Internal.WF
import all Std.Data.DHashMap.Raw
import all Std.Data.DHashMap.Basic
import all Std.Data.DHashMap.RawDef
meta import Std.Data.DHashMap.Basic

public section
Expand Down Expand Up @@ -162,7 +163,10 @@ private meta def queryMap : Std.DHashMap Name (fun _ => Name × Array (MacroM (T
⟨`getEntry?, (``getEntry?_eq_getEntry?, #[`(getEntry?_of_perm _)])⟩,
⟨`getEntryD, (``getEntryD_eq_getEntryD, #[`(getEntryD_of_perm _)])⟩,
⟨`getEntry!, (``getEntry!_eq_getEntry!, #[`(getEntry!_of_perm _)])⟩,
⟨`all, (``Raw.all_eq_all_toListModel, #[])⟩,
⟨`toList, (``Raw.toList_eq_toListModel, #[])⟩,
⟨`Const.beq, (``Raw₀.Const.beq_eq_beqModel, #[])⟩,
⟨`beq, (``beq_eq_beqModel, #[])⟩,
⟨`keys, (``Raw.keys_eq_keys_toListModel, #[`(perm_keys_congr_left)])⟩,
⟨`Const.toList, (``Raw.Const.toList_eq_toListModel_map, #[`(perm_map_congr_left)])⟩,
⟨`foldM, (``Raw.foldM_eq_foldlM_toListModel, #[])⟩,
Expand Down Expand Up @@ -1453,16 +1457,7 @@ theorem any_eq_false [LawfulBEq α] {p : (a : α) → β a → Bool} (h : m.1.WF
omit [Hashable α] [BEq α] in
theorem all_toList {p : (a : α) → β a → Bool} :
m.1.toList.all (fun x => p x.1 x.2) = m.1.all p := by
simp only [Raw.all, ForIn.forIn, Bool.not_eq_true, bind_pure_comp, map_pure, Id.run_bind]
rw [forIn_eq_forIn_toList, forIn_eq_forIn']
induction m.val.toList with
| nil => simp
| cons hd tl ih =>
simp only [forIn'_eq_forIn, List.all_cons]
by_cases h : p hd.fst hd.snd = false
· simp [h]
· simp only [forIn'_eq_forIn] at ih
simp [h, ih]
simp_to_model

omit [Hashable α] [BEq α] in
theorem all_eq_not_any_not {p : (a : α) → β a → Bool} :
Expand Down Expand Up @@ -2590,8 +2585,37 @@ end Const

end insertMany

section Union
section BEq
variable {m₁ m₂ : Raw₀ α β} [LawfulBEq α] [∀ k, BEq (β k)]

theorem Equiv.beq [∀ k, ReflBEq (β k)] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) : m₁.1.Equiv m₂.1 → beq m₁ m₂ := by
simp_to_model using List.beqModel_eq_true_of_perm

theorem equiv_of_beq [∀ k, LawfulBEq (β k)] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) : beq m₁ m₂ = true → m₁.1.Equiv m₂.1 := by
simp_to_model using List.perm_of_beqModel

theorem Equiv.beq_congr {m₃ m₄ : Raw₀ α β} (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) (h₃ : m₃.val.WF) (h₄ : m₄.val.WF) :
m₁.1.Equiv m₃.1 → m₂.1.Equiv m₄.1 → Raw₀.beq m₁ m₂ = Raw₀.beq m₃ m₄ := by
simp_to_model using List.beqModel_congr

end BEq

section

variable {β : Type v} {m₁ m₂ : Raw₀ α (fun _ => β)}

theorem Const.Equiv.beq [LawfulHashable α] [EquivBEq α] [BEq β] [ReflBEq β] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) : m₁.1.Equiv m₂.1 → Const.beq m₁ m₂ := by
simp_to_model using List.Const.beqModel_eq_true_of_perm

theorem Const.equiv_of_beq [LawfulBEq α] [BEq β] [LawfulBEq β] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) : beq m₁ m₂ = true → m₁.1.Equiv m₂.1 := by
simp_to_model using List.Const.perm_of_beqModel

theorem Const.Equiv.beq_congr [LawfulBEq α] {m₃ m₄ : Raw₀ α (fun _ => β)} [BEq β] (h₁ : m₁.val.WF) (h₂ : m₂.val.WF) (h₃ : m₃.val.WF) (h₄ : m₄.val.WF) :
m₁.1.Equiv m₃.1 → m₂.1.Equiv m₄.1 → Const.beq m₁ m₂ = Const.beq m₃ m₄ := by
simp_to_model using List.Const.beqModel_congr
end

section Union
variable (m₁ m₂ : Raw₀ α β)

variable {m₁ m₂}
Expand Down
22 changes: 22 additions & 0 deletions src/Std/Data/DHashMap/Internal/WF.lean
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ theorem forIn_eq_forIn_toListModel {δ : Type w} {l : Raw α β} {m : Type w →
· simp
· simpa using ih'

theorem all_eq_all_toListModel {p : (a: α) → β a → Bool} {m : Raw α β} :
m.all p = (toListModel m.buckets).all (fun x => p x.1 x.2) := by
simp only [Raw.all, ForIn.forIn, Bool.not_eq_true, bind_pure_comp, map_pure, Id.run_bind]
rw [forIn_eq_forIn_toListModel, ← toList_eq_toListModel, forIn_eq_forIn']
induction m.toList with
| nil => simp only [all_nil, forIn'_nil, Id.run_pure]
| cons hd tl ih =>
simp only [forIn'_eq_forIn, List.all_cons]
by_cases h : p hd.fst hd.snd = false
· simp [h]
· simp only [forIn'_eq_forIn] at ih
simp [h, ih]

end Raw

namespace Raw₀
Expand Down Expand Up @@ -1584,4 +1597,13 @@ theorem Const.wf_insertManyIfNewUnit₀ [BEq α] [Hashable α] [EquivBEq α] [La
{l : ρ} (h' : m.WF) : (Const.insertManyIfNewUnit ⟨m, h⟩ l).1.1.WF :=
(Raw₀.Const.insertManyIfNewUnit ⟨m, h⟩ l).2 _ Raw.WF.insertIfNew₀ h'

theorem beq_eq_beqModel [BEq α] [LawfulBEq α] [Hashable α] [∀ k, BEq (β k)] {m₁ m₂ : Raw₀ α β} (h₁ : Raw.WFImp m₁.1) (h₂ : Raw.WFImp m₂.1) :
beq m₁ m₂ = beqModel (toListModel m₁.1.buckets) (toListModel m₂.1.buckets) := by
simp [beq, beqModel, Raw.size_eq_length h₁, Raw.size_eq_length h₂, Raw.all_eq_all_toListModel,
get?_eq_getValueCast? h₂]

theorem Const.beq_eq_beqModel {β : Type v} [BEq α] [PartialEquivBEq α] [Hashable α] [LawfulHashable α] [BEq β] {m₁ m₂ : Raw₀ α (fun _ => β)} (h₁ : Raw.WFImp m₁.1) (h₂ : Raw.WFImp m₂.1) :
beq m₁ m₂ = Const.beqModel (toListModel m₁.1.buckets) (toListModel m₂.1.buckets) := by
simp [beq, Const.beqModel, Raw.size_eq_length h₁, Raw.size_eq_length h₂, Raw.all_eq_all_toListModel, get?_eq_getValue? h₂]

end Raw₀
35 changes: 35 additions & 0 deletions src/Std/Data/DHashMap/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,41 @@ theorem isEmpty_of_isEmpty_insertMany [EquivBEq α] [LawfulHashable α]
{l : ρ} : (m.insertMany l).isEmpty → m.isEmpty :=
Raw₀.isEmpty_of_isEmpty_insertMany ⟨m.1, _⟩ m.2

section BEq
variable {m₁ m₂ : DHashMap α β} [LawfulBEq α] [∀ k, BEq (β k)]

theorem Equiv.beq [∀ k, ReflBEq (β k)] (h : m₁ ~m m₂) : m₁ == m₂ := by
simp [BEq.beq]
apply Raw₀.Equiv.beq m₁.2 m₂.2 h.1

theorem equiv_of_beq [∀ k, LawfulBEq (β k)] (h : m₁ == m₂) : m₁ ~m m₂ := by
constructor
have := @Raw₀.equiv_of_beq α β _ _ ⟨m₁.1, m₁.2.size_buckets_pos⟩ ⟨m₂.1, m₂.2.size_buckets_pos⟩ _ _ _ m₁.2 m₂.2 h
simp only at this
exact this

theorem Equiv.beq_congr {m₃ m₄ : DHashMap α β} : m₁ ~m m₃ → m₂ ~m m₄ → (m₁ == m₂) = (m₃ == m₄) := by
intro h1 h2
exact @Raw₀.Equiv.beq_congr α β _ _ ⟨m₁.1, m₁.2.size_buckets_pos⟩ ⟨m₂.1, m₂.2.size_buckets_pos⟩ _ _ ⟨m₃.1, m₃.2.size_buckets_pos⟩ ⟨m₄.1, m₄.2.size_buckets_pos⟩ m₁.2 m₂.2 m₃.2 m₄.2 h1.1 h2.1
end BEq

section
variable {β : Type v} {m₁ m₂ : DHashMap α (fun _ => β)} [BEq β]

theorem Const.Equiv.beq [LawfulHashable α] [EquivBEq α] [ReflBEq β] (h : m₁ ~m m₂) : DHashMap.Const.beq m₁ m₂ := by
apply Raw₀.Const.Equiv.beq m₁.2 m₂.2 h.1

theorem Const.equiv_of_beq [LawfulBEq α] [LawfulBEq β] (h : Const.beq m₁ m₂) : m₁ ~m m₂ := by
constructor
have := @Raw₀.Const.equiv_of_beq α _ _ _ ⟨m₁.1, m₁.2.size_buckets_pos⟩ ⟨m₂.1, m₂.2.size_buckets_pos⟩ _ _ _ m₁.2 m₂.2 h
simp only at this
exact this

theorem Const.Equiv.beq_congr [LawfulBEq α] {m₃ m₄ : DHashMap α (fun _ => β)} : m₁ ~m m₃ → m₂ ~m m₄ → Const.beq m₁ m₂ = Const.beq m₃ m₄ := by
intro h1 h2
exact @Raw₀.Const.Equiv.beq_congr α _ _ _ ⟨m₁.1, m₁.2.size_buckets_pos⟩ ⟨m₂.1, m₂.2.size_buckets_pos⟩ _ ⟨m₃.1, m₃.2.size_buckets_pos⟩ ⟨m₄.1, m₄.2.size_buckets_pos⟩ _ m₁.2 m₂.2 m₃.2 m₄.2 h1.1 h2.1
end

section Union

variable (m₁ m₂ : DHashMap α β)
Expand Down
33 changes: 22 additions & 11 deletions src/Std/Data/DHashMap/Raw.lean
Original file line number Diff line number Diff line change
Expand Up @@ -476,17 +476,6 @@ only those mappings where the function returns `some` value.
@[inline] def keysArray (m : Raw α β) : Array α :=
m.fold (fun acc k _ => acc.push k) (.emptyWithCapacity m.size)

/-- Checks if all elements satisfy the predicate, short-circuiting if a predicate fails. -/
@[inline] def all (m : Raw α β) (p : (a : α) → β a → Bool) : Bool := Id.run do
for a in m do
if ¬ p a.1 a.2 then return false
return true

/-- Checks if any element satisfies the predicate, short-circuiting if a predicate succeeds. -/
@[inline] def any (m : Raw α β) (p : (a : α) → β a → Bool) : Bool := Id.run do
for a in m do
if p a.1 a.2 then return true
return false
/--
Computes the union of the given hash maps. If a key appears in both maps, the entry contained in
the second argument will appear in the result.
Expand Down Expand Up @@ -522,6 +511,28 @@ This function always merges the smaller map into the larger map, so the expected

instance [BEq α] [Hashable α] : Inter (Raw α β) := ⟨inter⟩

/-- Internal implementation detail of the hash map. -/
def beq [BEq α] [Hashable α] [LawfulBEq α] [∀ k, BEq (β k)] (m₁ m₂ : Raw α β) : Bool :=
if h₁ : 0 < m₁.buckets.size then
if h₂ : 0 < m₂.buckets.size then
Raw₀.beq ⟨m₁, h₁⟩ ⟨m₂, h₂⟩
else
false
else
false

instance [BEq α] [Hashable α] [LawfulBEq α] [∀ k, BEq (β k)] : BEq (Raw α β) := ⟨beq⟩

/-- Internal implementation detail of the hash map. -/
def Const.beq {β : Type v} [BEq α] [Hashable α] [BEq β] (m₁ m₂ : Raw α (fun _ => β)) : Bool :=
if h₁ : 0 < m₁.buckets.size then
if h₂ : 0 < m₂.buckets.size then
Raw₀.Const.beq ⟨m₁, h₁⟩ ⟨m₂, h₂⟩
else
false
else
false

/--
Computes the difference of the given hash maps.

Expand Down
12 changes: 12 additions & 0 deletions src/Std/Data/DHashMap/RawDef.lean
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ instance [Monad m] : ForM m (Raw α β) ((a : α) × β a) where
instance [Monad m] : ForIn m (Raw α β) ((a : α) × β a) where
forIn m init f := m.forIn (fun a b acc => f ⟨a, b⟩ acc) init

/-- Checks if all elements satisfy the predicate, short-circuiting if a predicate fails. -/
@[inline] def all (m : Raw α β) (p : (a : α) → β a → Bool) : Bool := Id.run do
for a in m do
if ¬ p a.1 a.2 then return false
return true

/-- Checks if any element satisfies the predicate, short-circuiting if a predicate succeeds. -/
@[inline] def any (m : Raw α β) (p : (a : α) → β a → Bool) : Bool := Id.run do
for a in m do
if p a.1 a.2 then return true
return false

end Raw

end Std.DHashMap
42 changes: 40 additions & 2 deletions src/Std/Data/DHashMap/RawLemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ prelude
public import Std.Data.DHashMap.Internal.Raw
public import Std.Data.DHashMap.Internal.RawLemmas
import all Std.Data.DHashMap.Raw

public section

/-!
Expand Down Expand Up @@ -48,7 +47,7 @@ private meta def baseNames : Array Name :=
``getKey?_eq, ``getKey_eq, ``getKey!_eq, ``getKeyD_eq,
``insertMany_eq, ``Const.insertMany_eq, ``Const.insertManyIfNewUnit_eq, ``ofArray_eq, ``Const.ofArray_eq,
``ofList_eq, ``Const.ofList_eq, ``Const.unitOfList_eq, ``Const.unitOfArray_eq,
``alter_eq, ``Const.alter_eq, ``modify_eq, ``Const.modify_eq, ``union_eq, ``inter_eq, ``diff_eq]
``alter_eq, ``Const.alter_eq, ``modify_eq, ``Const.modify_eq, ``union_eq, ``inter_eq, ``diff_eq, ``beq_eq, ``Const.beq_eq]


/-- Internal implementation detail of the hash map -/
Expand Down Expand Up @@ -3759,6 +3758,45 @@ variable [BEq α] [Hashable α]

open Internal.Raw Internal.Raw₀

section BEq
variable {m₁ m₂ : Raw α β} [LawfulBEq α] [∀ k, BEq (β k)]

theorem Equiv.beq [∀ k, ReflBEq (β k)] (h₁ : m₁.WF) (h₂ : m₂.WF) : m₁ ~m m₂ → m₁ == m₂ := by
simp only [BEq.beq]
simp_to_raw
intro h
exact Raw₀.Equiv.beq h₁ h₂ h

theorem equiv_of_beq [∀ k, LawfulBEq (β k)] (h₁ : m₁.WF) (h₂ : m₂.WF) : beq m₁ m₂ = true → m₁ ~m m₂ := by
simp_to_raw using Raw₀.equiv_of_beq

theorem Equiv.beq_congr {m₃ m₄ : Raw α β} (h₁ : m₁.WF) (h₂ : m₂.WF) (h₃ : m₃.WF) (h₄ : m₄.WF) :
m₁ ~m m₃ → m₂ ~m m₄ → Raw.beq m₁ m₂ = Raw.beq m₃ m₄ := by
simp_to_raw
intro w1 w2
exact Raw₀.Equiv.beq_congr h₁ h₂ h₃ h₄ w1 w2

end BEq

section
variable {β : Type v} {m₁ m₂ : Raw α (fun _ => β)}

theorem Const.Equiv.beq [LawfulHashable α] [EquivBEq α] [BEq β] [ReflBEq β] (h₁ : m₁.WF) (h₂ : m₂.WF) : m₁ ~m m₂ → beq m₁ m₂ := by
simp_to_raw
intro h
exact Raw₀.Const.Equiv.beq h₁ h₂ h

theorem Const.equiv_of_beq [LawfulBEq α] [BEq β] [LawfulBEq β] (h₁ : m₁.WF) (h₂ : m₂.WF) : beq m₁ m₂ = true → m₁ ~m m₂ := by
simp_to_raw using Raw₀.Const.equiv_of_beq

theorem Const.Equiv.beq_congr [LawfulBEq α] [BEq β] {m₃ m₄ : Raw α (fun _ => β)} (h₁ : m₁.WF) (h₂ : m₂.WF) (h₃ : m₃.WF) (h₄ : m₄.WF) :
m₁ ~m m₃ → m₂ ~m m₄ → Raw.Const.beq m₁ m₂ = Raw.Const.beq m₃ m₄ := by
simp_to_raw
intro w1 w2
exact Raw₀.Const.Equiv.beq_congr h₁ h₂ h₃ h₄ w1 w2

end

@[simp, grind =]
theorem ofArray_eq_ofList (a : Array ((a : α) × (β a))) :
ofArray a = ofList a.toList := by
Expand Down
Loading
Loading