Hash map lemmas #
This module contains lemmas about Std.Data.HashMap
. Most of the lemmas require
EquivBEq α
and LawfulHashable α
for the key type α
. The easiest way to obtain these instances
is to provide an instance of LawfulBEq α
.
@[reducible, inline, deprecated Std.HashMap.isEmpty_empty (since := "2025-03-12")]
Equations
@[reducible, inline, deprecated Std.HashMap.contains_empty (since := "2025-03-12")]
abbrev
Std.HashMap.contains_emptyc
{α : Type u_1}
{β : Type u_2}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{a : α}
:
@[reducible, inline, deprecated Std.HashMap.not_mem_empty (since := "2025-03-12")]
abbrev
Std.HashMap.not_mem_emptyc
{α : Type u_1}
{β : Type u_2}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{a : α}
:
Equations
@[reducible, inline, deprecated Std.HashMap.size_empty (since := "2025-03-12")]
Equations
@[reducible, inline, deprecated Std.HashMap.erase_empty (since := "2025-03-12")]
abbrev
Std.HashMap.erase_emptyc
{α : Type u_1}
{β : Type u_2}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{a : α}
:
Equations
@[reducible, inline, deprecated Std.HashMap.getElem?_empty (since := "2025-03-12")]
abbrev
Std.HashMap.getElem?_emptyc
{α : Type u_1}
{β : Type u_2}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{a : α}
:
@[reducible, inline, deprecated Std.HashMap.getD_empty (since := "2025-03-12")]
abbrev
Std.HashMap.getD_emptyc
{α : Type u_1}
{β : Type u_2}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{a : α}
{fallback : β}
:
Equations
@[reducible, inline, deprecated Std.HashMap.getKey?_empty (since := "2025-03-12")]
abbrev
Std.HashMap.getKey?_emptyc
{α : Type u_1}
{β : Type u_2}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{a : α}
:
Equations
theorem
Std.HashMap.getKey?_beq
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k : α}
:
@[reducible, inline, deprecated Std.HashMap.getKeyD_empty (since := "2025-03-12")]
abbrev
Std.HashMap.getKeyD_emptyc
{α : Type u_1}
{β : Type u_2}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{a fallback : α}
:
Equations
@[simp]
theorem
Std.HashMap.isEmpty_insertIfNew
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k : α}
{v : β}
:
@[simp]
theorem
Std.HashMap.contains_insertIfNew
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k a : α}
{v : β}
:
theorem
Std.HashMap.contains_insertIfNew_self
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k : α}
{v : β}
:
theorem
Std.HashMap.mem_insertIfNew_self
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k : α}
{v : β}
:
theorem
Std.HashMap.mem_of_mem_insertIfNew
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k a : α}
{v : β}
:
theorem
Std.HashMap.contains_of_contains_insertIfNew'
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k a : α}
{v : β}
:
This is a restatement of contains_of_contains_insertIfNew
that is written to exactly match the proof
obligation in the statement of getElem_insertIfNew
.
theorem
Std.HashMap.mem_of_mem_insertIfNew'
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k a : α}
{v : β}
:
This is a restatement of mem_of_mem_insertIfNew
that is written to exactly match the proof obligation
in the statement of getElem_insertIfNew
.
theorem
Std.HashMap.size_le_size_insertIfNew
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k : α}
{v : β}
:
theorem
Std.HashMap.size_insertIfNew_le
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k : α}
{v : β}
:
instance
Std.HashMap.instLawfulGetElemMemOfEquivBEqOfLawfulHashable
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
:
LawfulGetElem (HashMap α β) α β fun (m : HashMap α β) (a : α) => a ∈ m
theorem
Std.HashMap.distinct_keys
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
:
List.Pairwise (fun (a b : α) => (a == b) = false) m.keys
theorem
Std.HashMap.find?_toList_eq_some_iff_getKey?_eq_some_and_getElem?_eq_some
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k k' : α}
{v : β}
:
theorem
Std.HashMap.getElem?_insertMany_list_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{l : List (α × β)}
{k k' : α}
(k_beq : (k == k') = true)
{v : β}
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : (k, v) ∈ l)
:
theorem
Std.HashMap.getElem_insertMany_list_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{l : List (α × β)}
{k k' : α}
(k_beq : (k == k') = true)
{v : β}
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : (k, v) ∈ l)
{h : k' ∈ m.insertMany l}
:
theorem
Std.HashMap.getElem!_insertMany_list_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
[Inhabited β]
{l : List (α × β)}
{k k' : α}
(k_beq : (k == k') = true)
{v : β}
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : (k, v) ∈ l)
:
theorem
Std.HashMap.getD_insertMany_list_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{l : List (α × β)}
{k k' : α}
(k_beq : (k == k') = true)
{v fallback : β}
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : (k, v) ∈ l)
:
theorem
Std.HashMap.getKey?_insertMany_list_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{l : List (α × β)}
{k k' : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : k ∈ List.map Prod.fst l)
:
theorem
Std.HashMap.getKey_insertMany_list_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{l : List (α × β)}
{k k' : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : k ∈ List.map Prod.fst l)
{h : k' ∈ m.insertMany l}
:
theorem
Std.HashMap.getKey!_insertMany_list_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
[Inhabited α]
{l : List (α × β)}
{k k' : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : k ∈ List.map Prod.fst l)
:
theorem
Std.HashMap.getKeyD_insertMany_list_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{l : List (α × β)}
{k k' fallback : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : k ∈ List.map Prod.fst l)
:
theorem
Std.HashMap.size_le_size_insertMany_list
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{l : List (α × β)}
:
theorem
Std.HashMap.getKey?_insertManyIfNewUnit_list_of_not_mem_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α Unit}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k k' : α}
(k_beq : (k == k') = true)
(not_mem : ¬k ∈ m)
(distinct : List.Pairwise (fun (a b : α) => (a == b) = false) l)
(mem : k ∈ l)
:
theorem
Std.HashMap.getKey?_insertManyIfNewUnit_list_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α Unit}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k : α}
(mem : k ∈ m)
:
theorem
Std.HashMap.getKey_insertManyIfNewUnit_list_of_not_mem_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α Unit}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k k' : α}
(k_beq : (k == k') = true)
(not_mem : ¬k ∈ m)
(distinct : List.Pairwise (fun (a b : α) => (a == b) = false) l)
(mem : k ∈ l)
{h : k' ∈ m.insertManyIfNewUnit l}
:
theorem
Std.HashMap.getKey_insertManyIfNewUnit_list_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α Unit}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k : α}
(mem : k ∈ m)
{h : k ∈ m.insertManyIfNewUnit l}
:
theorem
Std.HashMap.getKey!_insertManyIfNewUnit_list_of_not_mem_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α Unit}
[EquivBEq α]
[LawfulHashable α]
[Inhabited α]
{l : List α}
{k k' : α}
(k_beq : (k == k') = true)
(not_mem : ¬k ∈ m)
(distinct : List.Pairwise (fun (a b : α) => (a == b) = false) l)
(mem : k ∈ l)
:
theorem
Std.HashMap.getKeyD_insertManyIfNewUnit_list_of_not_mem_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α Unit}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k k' fallback : α}
(k_beq : (k == k') = true)
(not_mem : ¬k ∈ m)
(distinct : List.Pairwise (fun (a b : α) => (a == b) = false) l)
(mem : k ∈ l)
:
theorem
Std.HashMap.getKeyD_insertManyIfNewUnit_list_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α Unit}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k fallback : α}
(mem : k ∈ m)
:
theorem
Std.HashMap.size_insertManyIfNewUnit_list
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α Unit}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
(distinct : List.Pairwise (fun (a b : α) => (a == b) = false) l)
:
theorem
Std.HashMap.size_le_size_insertManyIfNewUnit_list
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α Unit}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
:
theorem
Std.HashMap.getKey_ofList_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List (α × β)}
{k k' : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : k ∈ List.map Prod.fst l)
{h : k' ∈ ofList l}
:
theorem
Std.HashMap.getKey!_ofList_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
[Inhabited α]
{l : List (α × β)}
{k k' : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : k ∈ List.map Prod.fst l)
:
theorem
Std.HashMap.getKeyD_ofList_of_mem
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List (α × β)}
{k k' fallback : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α × β) => (a.fst == b.fst) = false) l)
(mem : k ∈ List.map Prod.fst l)
:
@[simp]
@[simp]
theorem
Std.HashMap.unitOfList_cons
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{hd : α}
{tl : List α}
:
@[simp]
theorem
Std.HashMap.contains_unitOfList
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k : α}
:
@[simp]
theorem
Std.HashMap.mem_unitOfList
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k : α}
:
@[simp]
theorem
Std.HashMap.getElem_unitOfList
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{l : List α}
{k : α}
{h : k ∈ unitOfList l}
:
theorem
Std.HashMap.getKey?_unitOfList_of_contains_eq_false
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k : α}
(contains_eq_false : l.contains k = false)
:
theorem
Std.HashMap.getKey?_unitOfList_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k k' : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α) => (a == b) = false) l)
(mem : k ∈ l)
:
theorem
Std.HashMap.getKey_unitOfList_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k k' : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α) => (a == b) = false) l)
(mem : k ∈ l)
{h : k' ∈ unitOfList l}
:
theorem
Std.HashMap.getKeyD_unitOfList_of_contains_eq_false
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k fallback : α}
(contains_eq_false : l.contains k = false)
:
theorem
Std.HashMap.getKeyD_unitOfList_of_mem
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
{k k' fallback : α}
(k_beq : (k == k') = true)
(distinct : List.Pairwise (fun (a b : α) => (a == b) = false) l)
(mem : k ∈ l)
:
theorem
Std.HashMap.size_unitOfList
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
(distinct : List.Pairwise (fun (a b : α) => (a == b) = false) l)
:
theorem
Std.HashMap.size_unitOfList_le
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
:
@[simp]
theorem
Std.HashMap.isEmpty_unitOfList
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{l : List α}
:
@[deprecated Std.HashMap.getElem?_alter (since := "2025-02-09")]
@[deprecated Std.HashMap.getElem_alter (since := "2025-02-09")]
@[deprecated Std.HashMap.getElem_alter_self (since := "2025-02-09")]
@[deprecated Std.HashMap.getElem!_alter (since := "2025-02-09")]
@[deprecated Std.HashMap.getElem!_alter_self (since := "2025-02-09")]
theorem
Std.HashMap.getKeyD_alter
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k k' fallback : α}
{f : Option β → Option β}
:
@[deprecated Std.HashMap.getElem?_modify (since := "2025-02-09")]
@[deprecated Std.HashMap.getElem?_modify_self (since := "2025-02-09")]
theorem
Std.HashMap.get?_modify_self
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k : α}
{f : β → β}
:
@[deprecated Std.HashMap.getElem_modify (since := "2025-02-09")]
@[deprecated Std.HashMap.getElem_modify_self (since := "2025-02-09")]
@[deprecated Std.HashMap.getElem!_modify (since := "2025-02-09")]
@[deprecated Std.HashMap.getElem!_modify_self (since := "2025-02-09")]
theorem
Std.HashMap.get!_modify_self
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
{k : α}
[Inhabited β]
{f : β → β}
:
theorem
Std.HashMap.Equiv.insertIfNew
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m₁ m₂ : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
(k : α)
(v : β)
(h : m₁.Equiv m₂)
:
(m₁.insertIfNew k v).Equiv (m₂.insertIfNew k v)
theorem
Std.HashMap.Equiv.insertMany_list
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m₁ m₂ : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
(l : List (α × β))
(h : m₁.Equiv m₂)
:
(m₁.insertMany l).Equiv (m₂.insertMany l)
theorem
Std.HashMap.Equiv.insertManyIfNewUnit_list
{α : Type u}
{x✝ : BEq α}
{x✝¹ : Hashable α}
[EquivBEq α]
[LawfulHashable α]
{m₁ m₂ : HashMap α Unit}
(l : List α)
(h : m₁.Equiv m₂)
:
(m₁.insertManyIfNewUnit l).Equiv (m₂.insertManyIfNewUnit l)
theorem
Std.HashMap.Equiv.filter
{α : Type u}
{β : Type v}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m₁ m₂ : HashMap α β}
(f : α → β → Bool)
(h : m₁.Equiv m₂)
:
(HashMap.filter f m₁).Equiv (HashMap.filter f m₂)
theorem
Std.HashMap.Equiv.map
{α : Type u}
{β : Type v}
{γ : Type w}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m₁ m₂ : HashMap α β}
(f : α → β → γ)
(h : m₁.Equiv m₂)
:
(HashMap.map f m₁).Equiv (HashMap.map f m₂)
theorem
Std.HashMap.Equiv.filterMap
{α : Type u}
{β : Type v}
{γ : Type w}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m₁ m₂ : HashMap α β}
(f : α → β → Option γ)
(h : m₁.Equiv m₂)
:
(HashMap.filterMap f m₁).Equiv (HashMap.filterMap f m₂)
@[reducible, inline, deprecated Std.HashMap.equiv_empty_iff_isEmpty (since := "2025-03-12")]
abbrev
Std.HashMap.equiv_emptyc_iff_isEmpty
{α : Type u_1}
{β : Type u_2}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
:
@[reducible, inline, deprecated Std.HashMap.empty_equiv_iff_isEmpty (since := "2025-03-12")]
abbrev
Std.HashMap.emptyc_equiv_iff_isEmpty
{α : Type u_1}
{β : Type u_2}
{x✝ : BEq α}
{x✝¹ : Hashable α}
{m : HashMap α β}
[EquivBEq α]
[LawfulHashable α]
: