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

Commit f77d5d6

Browse files
committed
feat(data/finset): add lemma for empty filter (#4188)
A little lemma, analogous to `filter_true_of_mem` to make it convenient to reduce a filter which always fails.
1 parent db9842c commit f77d5d6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/data/finset/basic.lean

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,11 +932,14 @@ by ext; simp
932932
@[simp] theorem filter_false {h} (s : finset α) : @filter α (λa, false) h s = ∅ :=
933933
ext $ assume a, by simp only [mem_filter, and_false]; refl
934934

935-
/-- If all elements of a `finset` satisfy the predicate `p`, `s.filter
936-
p` is `s`. -/
935+
/-- If all elements of a `finset` satisfy the predicate `p`, `s.filter p` is `s`. -/
937936
@[simp] lemma filter_true_of_mem {s : finset α} (h : ∀ x ∈ s, p x) : s.filter p = s :=
938937
ext $ λ x, ⟨λ h, (mem_filter.1 h).1, λ hx, mem_filter.2 ⟨hx, h x hx⟩⟩
939938

939+
/-- If all elements of a `finset` fail to satisfy the predicate `p`, `s.filter p` is `∅`. -/
940+
lemma filter_false_of_mem {s : finset α} (h : ∀ x ∈ s, ¬ p x) : s.filter p = ∅ :=
941+
eq_empty_of_forall_not_mem (by simpa)
942+
940943
lemma filter_congr {s : finset α} (H : ∀ x ∈ s, p x ↔ q x) : filter p s = filter q s :=
941944
eq_of_veq $ filter_congr H
942945

src/data/monoid_algebra.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ calc (f * g) x = (∑ a₁ in f.support, ∑ a₂ in g.support, F (a₁, a₂))
9090
... = ∑ p in (f.support.product g.support).filter (λ p : G × G, p.1 * p.2 = x), f p.1 * g p.2 :
9191
(finset.sum_filter _ _).symm
9292
... = ∑ p in s.filter (λ p : G × G, p.1 ∈ f.support ∧ p.2 ∈ g.support), f p.1 * g p.2 :
93-
sum_congr (by { ext, simp [hs, and_comm] }) (λ _ _, rfl)
93+
sum_congr (by { ext, simp only [mem_filter, mem_product, hs, and_comm] }) (λ _ _, rfl)
9494
... = ∑ p in s, f p.1 * g p.2 : sum_subset (filter_subset _) $ λ p hps hp,
9595
begin
9696
simp only [mem_filter, mem_support_iff, not_and, not_not] at hp ⊢,

0 commit comments

Comments
 (0)