Skip to content

Commit b049dc5

Browse files
committed
Move up
1 parent 6a93f55 commit b049dc5

File tree

5 files changed

+140
-4
lines changed

5 files changed

+140
-4
lines changed

src/Std/Data/HashMap/Basic.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,15 @@ instance [BEq α] [Hashable α] : Inter (HashMap α β) := ⟨inter⟩
283283

284284
instance [BEq α] [Hashable α] : SDiff (HashMap α β) := ⟨diff⟩
285285

286-
section Unverified
287-
288-
/-! We currently do not provide lemmas for the functions below. -/
289-
290286
@[inline, inherit_doc DHashMap.partition] def partition (f : α → β → Bool)
291287
(m : HashMap α β) : HashMap α β × HashMap α β :=
292288
let ⟨l, r⟩ := m.inner.partition f
293289
⟨⟨l⟩, ⟨r⟩⟩
294290

291+
section Unverified
292+
293+
/-! We currently do not provide lemmas for the functions below. -/
294+
295295
@[inline, inherit_doc DHashMap.values] def values (m : HashMap α β) : List β :=
296296
m.inner.values
297297

src/Std/Data/HashMap/Lemmas.lean

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,14 @@ theorem distinct_keys_toList [EquivBEq α] [LawfulHashable α] :
943943
m.toList.Pairwise (fun a b => (a.1 == b.1) = false) :=
944944
DHashMap.Const.distinct_keys_toList
945945

946+
theorem nodup_toList [EquivBEq α] [LawfulHashable α] :
947+
m.toList.Nodup := DHashMap.Const.nodup_toList
948+
949+
theorem mem_toList_insert_of_not_mem [EquivBEq α] [LawfulHashable α]
950+
{k : α} {v : β} {x : α × β} (h' : ¬ k ∈ m) :
951+
x ∈ (m.insert k v).toList ↔ x = ⟨k, v⟩ ∨ x ∈ m.toList :=
952+
DHashMap.Const.mem_toList_insert_of_not_mem h'
953+
946954
@[simp]
947955
theorem toArray_toList :
948956
m.toList.toArray = m.toArray :=
@@ -3478,5 +3486,36 @@ theorem getKeyD_map [EquivBEq α] [LawfulHashable α]
34783486
DHashMap.getKeyD_map
34793487

34803488
end map
3489+
3490+
variable {m : HashMap α β}
3491+
3492+
@[simp]
3493+
theorem size_fst_partition_add_size_snd_partition_eq_size [EquivBEq α] [LawfulHashable α]
3494+
{f : α → β → Bool} :
3495+
(m.partition f).1.size + (m.partition f).2.size = m.size :=
3496+
DHashMap.size_fst_partition_add_size_snd_partition_eq_size
3497+
3498+
@[simp]
3499+
theorem fst_partition_not_eq_snd_partition [EquivBEq α] [LawfulHashable α]
3500+
{f : α → β → Bool} :
3501+
(m.partition (fun a b => ! f a b)).fst = (m.partition f).snd := by
3502+
simp [partition, DHashMap.fst_partition_not_eq_snd_partition]
3503+
3504+
@[simp]
3505+
theorem snd_partition_not_eq_fst_partition [EquivBEq α] [LawfulHashable α]
3506+
{f : α → β → Bool} :
3507+
(m.partition (fun a b => ! f a b)).snd = (m.partition f).fst := by
3508+
simp [partition, DHashMap.snd_partition_not_eq_fst_partition]
3509+
3510+
theorem fst_partition_equiv_filter [EquivBEq α] [LawfulHashable α]
3511+
{f : α → β → Bool} :
3512+
(m.partition f).fst ~m m.filter f :=
3513+
⟨DHashMap.fst_partition_equiv_filter⟩
3514+
3515+
theorem snd_partition_equiv_filter_not [EquivBEq α] [LawfulHashable α]
3516+
{f : α → β → Bool} :
3517+
(m.partition f).snd ~m m.filter (fun a b => ! f a b) :=
3518+
⟨DHashMap.snd_partition_equiv_filter_not⟩
3519+
34813520
attribute [simp] contains_eq_false_iff_not_mem
34823521
end Std.HashMap

src/Std/Data/HashMap/RawLemmas.lean

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,14 @@ theorem distinct_keys_toList [EquivBEq α] [LawfulHashable α] (h : m.WF) :
953953
m.toList.Pairwise (fun a b => (a.1 == b.1) = false) :=
954954
DHashMap.Raw.Const.distinct_keys_toList h.out
955955

956+
theorem nodup_toList [EquivBEq α] [LawfulHashable α] (h : m.WF) :
957+
m.toList.Nodup := DHashMap.Raw.Const.nodup_toList h.out
958+
959+
theorem mem_toList_insert_of_not_mem [EquivBEq α] [LawfulHashable α] (h : m.WF)
960+
{k : α} {v : β} {x : α × β} : ¬ k ∈ m →
961+
(x ∈ (m.insert k v).toList ↔ x = ⟨k, v⟩ ∨ x ∈ m.toList) :=
962+
DHashMap.Raw.Const.mem_toList_insert_of_not_mem h.out
963+
956964
@[simp]
957965
theorem toArray_toList (h : m.WF) :
958966
m.toList.toArray = m.toArray :=
@@ -3538,6 +3546,35 @@ theorem getD_map_of_getKey?_eq_some [EquivBEq α] [LawfulHashable α]
35383546
DHashMap.Raw.Const.getD_map_of_getKey?_eq_some h.out h'
35393547

35403548
end map
3549+
3550+
@[simp]
3551+
theorem size_fst_partition_add_size_snd_partition_eq_size [EquivBEq α] [LawfulHashable α]
3552+
{p : α → β → Bool} (h : m.WF) :
3553+
(m.partition p).1.size + (m.partition p).2.size = m.size :=
3554+
DHashMap.Raw.size_fst_partition_add_size_snd_partition_eq_size h.out
3555+
3556+
@[simp]
3557+
theorem fst_partition_not_eq_snd_partition [EquivBEq α] [LawfulHashable α]
3558+
{p : α → β → Bool} (h : m.WF) :
3559+
(m.partition (fun a b => ! p a b)).fst = (m.partition p).snd := by
3560+
simp [partition, DHashMap.Raw.fst_partition_not_eq_snd_partition h.out]
3561+
3562+
@[simp]
3563+
theorem snd_partition_not_eq_fst_partition [EquivBEq α] [LawfulHashable α]
3564+
{p : α → β → Bool} (h : m.WF) :
3565+
(m.partition (fun a b => ! p a b)).snd = (m.partition p).fst := by
3566+
simp [partition, DHashMap.Raw.snd_partition_not_eq_fst_partition h.out]
3567+
3568+
theorem fst_partition_equiv_filter [EquivBEq α] [LawfulHashable α]
3569+
{p : α → β → Bool} (h : m.WF) :
3570+
(m.partition p).fst ~m m.filter p :=
3571+
⟨DHashMap.Raw.fst_partition_equiv_filter h.out⟩
3572+
3573+
theorem snd_partition_equiv_filter_not [EquivBEq α] [LawfulHashable α]
3574+
{p : α → β → Bool} (h : m.WF) :
3575+
(m.partition p).snd ~m m.filter (fun a b => ! p a b) :=
3576+
⟨DHashMap.Raw.snd_partition_equiv_filter_not h.out⟩
3577+
35413578
attribute [simp] contains_eq_false_iff_not_mem
35423579
end Raw
35433580

src/Std/Data/HashSet/Lemmas.lean

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,5 +1523,36 @@ theorem getD_filter [EquivBEq α] [LawfulHashable α]
15231523
HashMap.getKeyD_filter_key
15241524

15251525
end filter
1526+
1527+
variable {m : HashSet α}
1528+
1529+
@[simp]
1530+
theorem size_fst_partition_add_size_snd_partition_eq_size [EquivBEq α] [LawfulHashable α]
1531+
{f : α → Bool} :
1532+
(m.partition f).1.size + (m.partition f).2.size = m.size :=
1533+
HashMap.size_fst_partition_add_size_snd_partition_eq_size
1534+
1535+
@[simp]
1536+
theorem fst_partition_not_eq_snd_partition [EquivBEq α] [LawfulHashable α]
1537+
{f : α → Bool} :
1538+
(m.partition (fun a => ! f a)).fst = (m.partition f).snd := by
1539+
simp [partition, HashMap.fst_partition_not_eq_snd_partition]
1540+
1541+
@[simp]
1542+
theorem snd_partition_not_eq_fst_partition [EquivBEq α] [LawfulHashable α]
1543+
{f : α → Bool} :
1544+
(m.partition (fun a => ! f a)).snd = (m.partition f).fst := by
1545+
simp [partition, HashMap.snd_partition_not_eq_fst_partition]
1546+
1547+
theorem fst_partition_equiv_filter [EquivBEq α] [LawfulHashable α]
1548+
{f : α → Bool} :
1549+
(m.partition f).fst ~m m.filter f :=
1550+
⟨HashMap.fst_partition_equiv_filter⟩
1551+
1552+
theorem snd_partition_equiv_filter_not [EquivBEq α] [LawfulHashable α]
1553+
{f : α → Bool} :
1554+
(m.partition f).snd ~m m.filter (fun a => ! f a) :=
1555+
⟨HashMap.snd_partition_equiv_filter_not⟩
1556+
15261557
attribute [simp] contains_eq_false_iff_not_mem
15271558
end Std.HashSet

src/Std/Data/HashSet/RawLemmas.lean

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,35 @@ theorem get_filter [EquivBEq α] [LawfulHashable α]
15941594

15951595
end filter
15961596

1597+
@[simp]
1598+
theorem size_fst_partition_add_size_snd_partition_eq_size [EquivBEq α] [LawfulHashable α]
1599+
{p : α → Bool} (h : m.WF) :
1600+
(m.partition p).1.size + (m.partition p).2.size = m.size :=
1601+
HashMap.Raw.size_fst_partition_add_size_snd_partition_eq_size h.out
1602+
1603+
@[simp]
1604+
theorem fst_partition_not_eq_snd_partition [EquivBEq α] [LawfulHashable α]
1605+
{p : α → Bool} (h : m.WF) :
1606+
(m.partition (fun a => ! p a)).fst = (m.partition p).snd := by
1607+
simp [partition, HashMap.Raw.fst_partition_not_eq_snd_partition h.out]
1608+
1609+
@[simp]
1610+
theorem snd_partition_not_eq_fst_partition [EquivBEq α] [LawfulHashable α]
1611+
{p : α → Bool} (h : m.WF) :
1612+
(m.partition (fun a => ! p a)).snd = (m.partition p).fst := by
1613+
simp [partition, HashMap.Raw.snd_partition_not_eq_fst_partition h.out]
1614+
1615+
theorem fst_partition_equiv_filter [EquivBEq α] [LawfulHashable α]
1616+
{p : α → Bool} (h : m.WF) :
1617+
(m.partition p).fst ~m m.filter p :=
1618+
⟨HashMap.Raw.fst_partition_equiv_filter h.out⟩
1619+
1620+
theorem snd_partition_equiv_filter_not [EquivBEq α] [LawfulHashable α]
1621+
{p : α → Bool} (h : m.WF) :
1622+
(m.partition p).snd ~m m.filter (fun a => ! p a) :=
1623+
⟨HashMap.Raw.snd_partition_equiv_filter_not h.out⟩
1624+
1625+
15971626
attribute [simp] contains_eq_false_iff_not_mem
15981627
end Raw
15991628

0 commit comments

Comments
 (0)