@@ -538,13 +538,33 @@ end cons
538
538
/-- `disj_union s t h` is the set such that `a ∈ disj_union s t h` iff `a ∈ s` or `a ∈ t`.
539
539
It is the same as `s ∪ t`, but it does not require decidable equality on the type. The hypothesis
540
540
ensures that the sets are disjoint. -/
541
- def disj_union {α} (s t : finset α) (h : ∀ a ∈ s, a ∉ t) : finset α :=
541
+ def disj_union (s t : finset α) (h : ∀ a ∈ s, a ∉ t) : finset α :=
542
542
⟨s.1 + t.1 , multiset.nodup_add.2 ⟨s.2 , t.2 , h⟩⟩
543
543
544
544
@[simp] theorem mem_disj_union {α s t h a} :
545
545
a ∈ @disj_union α s t h ↔ a ∈ s ∨ a ∈ t :=
546
546
by rcases s with ⟨⟨s⟩⟩; rcases t with ⟨⟨t⟩⟩; apply list.mem_append
547
547
548
+ lemma disj_union_comm (s t : finset α) (h : ∀ a ∈ s, a ∉ t) :
549
+ disj_union s t h = disj_union t s (λ a ht hs, h _ hs ht) :=
550
+ eq_of_veq $ add_comm _ _
551
+
552
+ @[simp] lemma empty_disj_union (t : finset α) (h : ∀ a' ∈ ∅, a' ∉ t := λ a h _, not_mem_empty _ h) :
553
+ disj_union ∅ t h = t :=
554
+ eq_of_veq $ zero_add _
555
+
556
+ @[simp] lemma disj_union_empty (s : finset α) (h : ∀ a' ∈ s, a' ∉ ∅ := λ a h, not_mem_empty _) :
557
+ disj_union s ∅ h = s :=
558
+ eq_of_veq $ add_zero _
559
+
560
+ lemma singleton_disj_union (a : α) (t : finset α) (h : ∀ a' ∈ {a}, a' ∉ t) :
561
+ disj_union {a} t h = cons a t (h _ $ mem_singleton_self _) :=
562
+ eq_of_veq $ multiset.singleton_add _ _
563
+
564
+ lemma disj_union_singleton (s : finset α) (a : α) (h : ∀ a' ∈ s, a' ∉ {a}) :
565
+ disj_union s {a} h = cons a s (λ ha, h _ ha $ mem_singleton_self _) :=
566
+ by rw [disj_union_comm, singleton_disj_union]
567
+
548
568
/-! ### insert -/
549
569
550
570
section decidable_eq
@@ -1522,6 +1542,31 @@ lemma subset_coe_filter_of_subset_forall (s : finset α) {t : set α}
1522
1542
theorem filter_singleton (a : α) : filter p (singleton a) = if p a then singleton a else ∅ :=
1523
1543
by { classical, ext x, simp, split_ifs with h; by_cases h' : x = a; simp [h, h'] }
1524
1544
1545
+ theorem filter_cons_of_pos (a : α) (s : finset α) (ha : a ∉ s) (hp : p a):
1546
+ filter p (cons a s ha) = cons a (filter p s) (mem_filter.not.mpr $ mt and.left ha) :=
1547
+ eq_of_veq $ multiset.filter_cons_of_pos s.val hp
1548
+
1549
+ theorem filter_cons_of_neg (a : α) (s : finset α) (ha : a ∉ s) (hp : ¬p a):
1550
+ filter p (cons a s ha) = filter p s :=
1551
+ eq_of_veq $ multiset.filter_cons_of_neg s.val hp
1552
+
1553
+ theorem filter_disj_union (s : finset α) (t : finset α) (h : ∀ (a : α), a ∈ s → a ∉ t) :
1554
+ filter p (disj_union s t h) = (filter p s).disj_union (filter p t)
1555
+ (λ a hs ht, h a (mem_of_mem_filter _ hs) (mem_of_mem_filter _ ht)) :=
1556
+ eq_of_veq $ multiset.filter_add _ _ _
1557
+
1558
+ theorem filter_cons {a : α} (s : finset α) (ha : a ∉ s) :
1559
+ filter p (cons a s ha) = (if p a then {a} else ∅ : finset α).disj_union (filter p s) (λ b hb, by
1560
+ { split_ifs at hb,
1561
+ { rw finset.mem_singleton.mp hb,
1562
+ exact (mem_filter.not.mpr $ mt and.left ha) },
1563
+ { cases hb } }) :=
1564
+ begin
1565
+ split_ifs with h,
1566
+ { rw [filter_cons_of_pos _ _ _ ha h, singleton_disj_union] },
1567
+ { rw [filter_cons_of_neg _ _ _ ha h, empty_disj_union] },
1568
+ end
1569
+
1525
1570
variable [decidable_eq α]
1526
1571
1527
1572
theorem filter_union (s₁ s₂ : finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p :=
0 commit comments