Hash map lemmas #
This module contains lemmas about Std.Data.HashMap.Raw
. 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 α
.
@[simp]
theorem
Std.HashMap.Raw.insert_eq_insert
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
{p : α × β}
:
Insert.insert p m = m.insert p.fst p.snd
@[simp]
theorem
Std.HashMap.Raw.mem_insert_self
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
{v : β}
:
k ∈ m.insert k v
theorem
Std.HashMap.Raw.size_le_size_insert
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
{v : β}
:
m.size ≤ (m.insert k v).size
theorem
Std.HashMap.Raw.size_erase_le
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
:
(m.erase k).size ≤ m.size
theorem
Std.HashMap.Raw.contains_eq_isSome_getElem?
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{a : α}
:
m.contains a = m[a]?.isSome
@[simp]
theorem
Std.HashMap.Raw.getElem_insert_self
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
{v : β}
:
(m.insert k v)[k] = v
@[simp]
theorem
Std.HashMap.Raw.getD_insert_self
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
{fallback v : β}
:
(m.insert k v).getD k fallback = v
@[simp]
theorem
Std.HashMap.Raw.getD_erase_self
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
{fallback : β}
:
(m.erase k).getD k fallback = fallback
theorem
Std.HashMap.Raw.getD_eq_getD_getElem?
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{a : α}
{fallback : β}
:
m.getD a fallback = m[a]?.getD fallback
theorem
Std.HashMap.Raw.contains_eq_isSome_getKey?
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{a : α}
:
m.contains a = (m.getKey? a).isSome
@[simp]
theorem
Std.HashMap.Raw.getKey_insert_self
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
{v : β}
:
(m.insert k v).getKey k ⋯ = k
@[simp]
theorem
Std.HashMap.Raw.getKeyD_insert_self
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k fallback : α}
{v : β}
:
(m.insert k v).getKeyD k fallback = k
@[simp]
theorem
Std.HashMap.Raw.getKeyD_erase_self
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k fallback : α}
:
(m.erase k).getKeyD k fallback = fallback
theorem
Std.HashMap.Raw.getKeyD_eq_getD_getKey?
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{a fallback : α}
:
m.getKeyD a fallback = (m.getKey? a).getD fallback
theorem
Std.HashMap.Raw.mem_insertIfNew_self
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
{v : β}
:
k ∈ m.insertIfNew k v
theorem
Std.HashMap.Raw.contains_of_contains_insertIfNew'
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k a : α}
{v : β}
:
This is a restatement of contains_insertIfNew
that is written to exactly match the proof
obligation in the statement of getElem_insertIfNew
.
theorem
Std.HashMap.Raw.mem_of_mem_insertIfNew'
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k a : α}
{v : β}
:
This is a restatement of mem_insertIfNew
that is written to exactly match the proof obligation
in the statement of getElem_insertIfNew
.
theorem
Std.HashMap.Raw.size_le_size_insertIfNew
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
{v : β}
:
m.size ≤ (m.insertIfNew k v).size
@[simp]
theorem
Std.HashMap.Raw.length_keys
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
:
m.keys.length = m.size
@[simp]
theorem
Std.HashMap.Raw.isEmpty_keys
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
:
m.keys.isEmpty = m.isEmpty
@[simp]
theorem
Std.HashMap.Raw.contains_keys
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
{k : α}
:
m.keys.contains k = m.contains k
theorem
Std.HashMap.Raw.distinct_keys
{α : Type u}
{β : Type v}
{m : Raw α β}
[BEq α]
[Hashable α]
[EquivBEq α]
[LawfulHashable α]
(h : m.WF)
:
List.Pairwise (fun (a b : α) => (a == b) = false) m.keys