Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit ef43edf

Browse files
spljohoelzl
authored andcommitted
feat(data/finset): add list.to_finset theorems
1 parent 02c2b56 commit ef43edf

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

data/finset.lean

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,12 @@ multiset.to_finset_eq n
588588
@[simp] theorem mem_to_finset {a : α} {l : list α} : a ∈ l.to_finset ↔ a ∈ l :=
589589
mem_erase_dup
590590

591+
@[simp] theorem to_finset_nil : to_finset (@nil α) = ∅ :=
592+
rfl
593+
594+
@[simp] theorem to_finset_cons {a : α} {l : list α} : to_finset (a :: l) = insert a (to_finset l) :=
595+
finset.eq_of_veq $ by by_cases h : a ∈ l; simp [finset.insert_val', multiset.erase_dup_cons, h]
596+
591597
end list
592598

593599
namespace finset
@@ -995,3 +1001,20 @@ list.to_finset_eq (sort_nodup r s) ▸ eq_of_veq (sort_eq r s)
9951001
end sort
9961002

9971003
end finset
1004+
1005+
namespace list
1006+
variable [decidable_eq α]
1007+
1008+
theorem to_finset_card_of_nodup {l : list α} : l.nodup → l.to_finset.card = l.length :=
1009+
begin
1010+
induction l,
1011+
case list.nil { simp },
1012+
case list.cons : _ _ ih {
1013+
intros nd,
1014+
simp at nd,
1015+
simp [finset.card_insert_of_not_mem ((not_iff_not_of_iff mem_to_finset).mpr nd.1),
1016+
ih nd.2]
1017+
}
1018+
end
1019+
1020+
end list

data/list/basic.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,10 @@ theorem pw_filter_eq_self {l : list α} : pw_filter R l = l ↔ pairwise R l :=
26562656
rw [pw_filter_cons_of_pos (ball.imp_left (pw_filter_subset l) al), IH p],
26572657
end
26582658

2659+
@[simp] theorem pw_filter_idempotent {l : list α} :
2660+
pw_filter R (pw_filter R l) = pw_filter R l :=
2661+
pw_filter_eq_self.mpr (pairwise_pw_filter l)
2662+
26592663
theorem forall_mem_pw_filter (neg_trans : ∀ {x y z}, R x z → R x y ∨ R y z)
26602664
(a : α) (l : list α) : (∀ b ∈ pw_filter R l, R a b) ↔ (∀ b ∈ l, R a b) :=
26612665
begin
@@ -2999,6 +3003,9 @@ theorem nodup_erase_dup : ∀ l : list α, nodup (erase_dup l) := pairwise_pw_fi
29993003

30003004
theorem erase_dup_eq_self {l : list α} : erase_dup l = l ↔ nodup l := pw_filter_eq_self
30013005

3006+
@[simp] theorem erase_dup_idempotent {l : list α} : erase_dup (erase_dup l) = erase_dup l :=
3007+
pw_filter_idempotent
3008+
30023009
theorem erase_dup_append (l₁ l₂ : list α) : erase_dup (l₁ ++ l₂) = l₁ ∪ erase_dup l₂ :=
30033010
begin
30043011
induction l₁ with a l₁ IH; simp, rw ← IH,

0 commit comments

Comments
 (0)