Skip to content

Commit f884e9d

Browse files
committed
feat(Data/Finset/Filter): tag Finset.filter_congr as congr (#38695)
Tag `Finset.filter_congr` as `@[congr]`. This should force simp to eta-expand any `Fintype` instances if necessary after using the simp lemma `Fintype.card_ofFinset`. `theorem card_ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : @Fintype.card p (ofFinset s H) = #s` rewrites any `@Fintype.card p (Fintype.ofFinset s H)` in the goal to `Finset.card s`, where the finset `s` comes from the matched `Fintype` instance in the goal. This means the syntactic form of the goal will depend on the `Fintype` instance, and `Finset.filter_congr` should help normalize things after it. See [Zulip](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Possible.20SimpleGraph.20.2F.20Finset.20membership.20diamond/with/591592061).
1 parent 32df576 commit f884e9d

7 files changed

Lines changed: 10 additions & 9 deletions

File tree

Mathlib/Algebra/MvPolynomial/SchwartzZippel.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ lemma schwartz_zippel_sup_sum :
131131
{x₀ ∈ S 0 | eval (cons x₀ xₜ) p = 0}) := by
132132
rw [← filter_filter, filter_piFinset_eq_map_consEquiv S (fun r ↦ eval r pₖ ≠ 0),
133133
filter_map, card_map, product_eq_biUnion_right, filter_biUnion]
134-
simp [Function.comp_def, filter_image]
134+
simp [filter_image]
135135
rfl
136136
_ ≤ ∑ xₜ ∈ tail S ^^ n with eval xₜ pₖ ≠ 0,
137137
#(image (fun x₀ ↦ (x₀, xₜ)) {x₀ ∈ S 0 | eval (cons x₀ xₜ) p = 0}) :=

Mathlib/Algebra/Order/Antidiag/Prod.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,8 @@ theorem filter_fst_eq_antidiagonal (n m : A) [DecidablePred (· = m)] [Decidable
167167

168168
theorem filter_snd_eq_antidiagonal (n m : A) [DecidablePred (· = m)] [Decidable (m ≤ n)] :
169169
{x ∈ antidiagonal n | x.snd = m} = if m ≤ n then {(n - m, m)} else ∅ := by
170-
have : (fun x : A × A ↦ (x.snd = m)) ∘ Prod.swap = fun x : A × A ↦ x.fst = m := by
171-
ext; simp
172170
rw [← map_swap_antidiagonal, filter_map]
173-
simp [this, filter_fst_eq_antidiagonal, apply_ite (Finset.map _)]
171+
simp [filter_fst_eq_antidiagonal, apply_ite (Finset.map _)]
174172

175173
end OrderedSub
176174

Mathlib/Combinatorics/Additive/Energy.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ variable [CommMonoid α]
167167

168168
@[to_additive] lemma mulEnergy_comm (s t : Finset α) : Eₘ[s, t] = Eₘ[t, s] := by
169169
rw [mulEnergy, ← Finset.card_map (Equiv.prodComm _ _).toEmbedding, map_filter]
170-
simp [-Finset.card_map, mulEnergy, mul_comm, map_eq_image, Function.comp_def]
170+
simp [mulEnergy, mul_comm, map_eq_image]
171171

172172
end CommMonoid
173173

Mathlib/Combinatorics/SimpleGraph/Finite.lean

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,10 @@ section Finite
348348

349349
variable [Fintype V]
350350

351-
instance neighborSetFintype [DecidableRel G.Adj] (v : V) : Fintype (G.neighborSet v) :=
352-
Subtype.fintype (· ∈ G.neighborSet v)
351+
/-- `Fintype` for `neighborSet` -/
352+
@[deprecated inferInstance (since := "2026-04-29")]
353+
abbrev neighborSetFintype [DecidableRel G.Adj] (v : V) : Fintype (G.neighborSet v) :=
354+
inferInstance
353355

354356
theorem neighborFinset_eq_filter {v : V} [DecidableRel G.Adj] :
355357
G.neighborFinset v = ({w | G.Adj v w} : Finset _) := by ext; simp

Mathlib/Data/Finset/Filter.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ theorem filter_false_of_mem (h : ∀ x ∈ s, ¬p x) : s.filter p = ∅ := filte
172172
theorem filter_const (p : Prop) [Decidable p] (s : Finset α) :
173173
(s.filter fun _a => p) = if p then s else ∅ := by split_ifs <;> simp [*]
174174

175+
@[congr]
175176
theorem filter_congr {s : Finset α} (H : ∀ x ∈ s, p x ↔ q x) : filter p s = filter q s :=
176177
eq_of_veq <| Multiset.filter_congr H
177178

Mathlib/Data/Finset/Image.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ theorem filter_map {p : β → Prop} [DecidablePred p] :
176176
lemma map_filter' (p : α → Prop) [DecidablePred p] (f : α ↪ β) (s : Finset α)
177177
[DecidablePred (∃ a, p a ∧ f a = ·)] :
178178
(s.filter p).map f = (s.map f).filter fun b => ∃ a, p a ∧ f a = b := by
179-
simp [Function.comp_def, filter_map, f.injective.eq_iff]
179+
simp [filter_map]
180180

181181
lemma filter_attach' [DecidableEq α] (s : Finset α) (p : s → Prop) [DecidablePred p] :
182182
s.attach.filter p =

Mathlib/LinearAlgebra/Alternating/DomCoprod.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ theorem MultilinearMap.domCoprod_alternization [DecidableEq ιa] [DecidableEq ι
219219
simp [QuotientGroup.leftRel_apply, f, Quotient.eq]
220220
_ = ∑ τ ∈ {τ | τ⁻¹ ∈ f.range}, sign (σ * τ) • domDomCongr (σ * τ) (a.domCoprod b) := by
221221
conv_lhs => rw [← Finset.map_univ_equiv (Equiv.mulLeft σ), Finset.filter_map, Finset.sum_map]
222-
simp [Function.comp_def, -MonoidHom.mem_range]
222+
simp [-MonoidHom.mem_range]
223223
_ = ∑ τ, sign (σ * f τ) • domDomCongr (σ * f τ) (a.domCoprod b) := by
224224
simp_rw [f, Subgroup.inv_mem_iff, MonoidHom.mem_range, Finset.univ_filter_exists,
225225
Finset.sum_image sumCongrHom_injective.injOn]

0 commit comments

Comments
 (0)