@@ -508,6 +508,9 @@ ext.2 $ λ a, by simpa only [mem_sdiff, mem_union, or_comm,
508
508
@[simp] theorem union_sdiff_of_subset {s₁ s₂ : finset α} (h : s₁ ⊆ s₂) : s₁ ∪ (s₂ \ s₁) = s₂ :=
509
509
(union_comm _ _).trans (sdiff_union_of_subset h)
510
510
511
+ theorem inter_sdiff (s t u : finset α) : s ∩ (t \ u) = s ∩ t \ u :=
512
+ by { ext x, simp [and_assoc] }
513
+
511
514
@[simp] theorem inter_sdiff_self (s₁ s₂ : finset α) : s₁ ∩ (s₂ \ s₁) = ∅ :=
512
515
eq_empty_of_forall_not_mem $
513
516
by simp only [mem_inter, mem_sdiff]; rintro x ⟨h, _, hn⟩; exact hn h
@@ -599,6 +602,19 @@ theorem filter_union_right (p q : α → Prop) [decidable_pred p] [decidable_pre
599
602
s.filter p ∪ s.filter q = s.filter (λx, p x ∨ q x) :=
600
603
ext.2 $ λ x, by simp only [mem_filter, mem_union, and_or_distrib_left.symm]
601
604
605
+ theorem filter_inter {s t : finset α} : filter p s ∩ t = filter p (s ∩ t) :=
606
+ by {ext, simp [and_assoc], rw [and.left_comm] }
607
+
608
+ theorem inter_filter {s t : finset α} : s ∩ filter p t = filter p (s ∩ t) :=
609
+ by rw [inter_comm, filter_inter, inter_comm]
610
+
611
+ theorem filter_insert (a : α) (s : finset α) :
612
+ filter p (insert a s) = if p a then insert a (filter p s) else (filter p s) :=
613
+ by { ext x, simp, split_ifs with h; by_cases h' : x = a; simp [h, h'] }
614
+
615
+ theorem filter_singleton (a : α) : filter p (singleton a) = if p a then singleton a else ∅ :=
616
+ by { ext x, simp, split_ifs with h; by_cases h' : x = a; simp [h, h'] }
617
+
602
618
theorem filter_or (s : finset α) : s.filter (λ a, p a ∨ q a) = s.filter p ∪ s.filter q :=
603
619
ext.2 $ λ _, by simp only [mem_filter, mem_union, and_or_distrib_left]
604
620
@@ -1124,6 +1140,14 @@ ext.2 $ λ x, by simp only [mem_bind, exists_prop, mem_union, mem_insert,
1124
1140
@[simp] lemma singleton_bind [decidable_eq α] {a : α} : (singleton a).bind t = t a :=
1125
1141
show (insert a ∅ : finset α).bind t = t a, from bind_insert.trans $ union_empty _
1126
1142
1143
+ theorem bind_inter (s : finset α) (f : α → finset β) (t : finset β) :
1144
+ s.bind f ∩ t = s.bind (λ x, f x ∩ t) :=
1145
+ by { ext x, simp, exact ⟨λ ⟨xt, y, ys, xf⟩, ⟨y, ys, xt, xf⟩, λ ⟨y, ys, xt, xf⟩, ⟨xt, y, ys, xf⟩⟩ }
1146
+
1147
+ theorem inter_bind (t : finset β) (s : finset α) (f : α → finset β) :
1148
+ t ∩ s.bind f = s.bind (λ x, t ∩ f x) :=
1149
+ by rw [inter_comm, bind_inter]; simp
1150
+
1127
1151
theorem image_bind [decidable_eq γ] {f : α → β} {s : finset α} {t : β → finset γ} :
1128
1152
(s.image f).bind t = s.bind (λa, t (f a)) :=
1129
1153
by haveI := classical.dec_eq α; exact
0 commit comments