Skip to content

Commit

Permalink
feat: add Finsupp.prod/sum_eq_single (#7349)
Browse files Browse the repository at this point in the history
In several places, we unfold `Finsupp.sum` just to use `Finset.sum_eq_single`; this adds the missing lemma.
  • Loading branch information
Ruben-VandeVelde committed Sep 28, 2023
1 parent 2f22e29 commit b86770a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
10 changes: 10 additions & 0 deletions Mathlib/Algebra/BigOperators/Finsupp.lean
Expand Up @@ -212,6 +212,16 @@ theorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.s
#align finsupp.prod_congr Finsupp.prod_congr
#align finsupp.sum_congr Finsupp.sum_congr

@[to_additive]
theorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}
(h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :
f.prod g = g a (f a) := by
refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)
· exact h₀ b (mem_support_iff.mp hb₁) hb₂
· simp only [not_mem_support_iff] at h
rw [h]
refine h₁ h

end SumProd

end Finsupp
Expand Down
12 changes: 6 additions & 6 deletions Mathlib/Data/Finsupp/Basic.lean
Expand Up @@ -451,11 +451,11 @@ def mapDomain (f : α → β) (v : α →₀ M) : β →₀ M :=

theorem mapDomain_apply {f : α → β} (hf : Function.Injective f) (x : α →₀ M) (a : α) :
mapDomain f x (f a) = x a := by
rw [mapDomain, sum_apply, sum, Finset.sum_eq_single a, single_eq_same]
rw [mapDomain, sum_apply, sum_eq_single a, single_eq_same]
· intro b _ hba
exact single_eq_of_ne (hf.ne hba)
· intro h
rw [not_mem_support_iff.1 h, single_zero, zero_apply]
· intro _
rw [single_zero, coe_zero, Pi.zero_apply]
#align finsupp.map_domain_apply Finsupp.mapDomain_apply

theorem mapDomain_notin_range {f : α → β} (x : α →₀ M) (a : β) (h : a ∉ Set.range f) :
Expand Down Expand Up @@ -1211,11 +1211,11 @@ theorem curry_apply (f : α × β →₀ M) (x : α) (y : β) : f.curry x y = f
rintro ⟨b₁, b₂⟩
simp [single_apply, ite_apply, Prod.ext_iff, ite_and]
split_ifs <;> simp [single_apply, *]
rw [Finsupp.curry, sum_apply, sum_apply, Finsupp.sum, Finset.sum_eq_single, this, if_pos rfl]
rw [Finsupp.curry, sum_apply, sum_apply, sum_eq_single, this, if_pos rfl]
· intro b _ b_ne
rw [this b, if_neg b_ne]
· intro hxy
rw [this (x, y), if_pos rfl, not_mem_support_iff.mp hxy]
· intro _
rw [single_zero, single_zero, coe_zero, Pi.zero_apply, coe_zero, Pi.zero_apply]
#align finsupp.curry_apply Finsupp.curry_apply

theorem sum_curry_index (f : α × β →₀ M) (g : α → β → M → N) (hg₀ : ∀ a b, g a b 0 = 0)
Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Data/Finsupp/Multiset.lean
Expand Up @@ -110,8 +110,8 @@ theorem count_toMultiset [DecidableEq α] (f : α →₀ ℕ) (a : α) : (toMult
_ = f.sum fun x n => n * ({x} : Multiset α).count a := by simp only [Multiset.count_nsmul]
_ = f a * ({a} : Multiset α).count a :=
sum_eq_single _
(fun a' _ H => by simp only [Multiset.count_singleton, if_false, H.symm, mul_zero]) fun H =>
by simp only [not_mem_support_iff.1 H, zero_mul]
(fun a' _ H => by simp only [Multiset.count_singleton, if_false, H.symm, mul_zero])
(fun _ => zero_mul _)
_ = f a := by rw [Multiset.count_singleton_self, mul_one]
#align finsupp.count_to_multiset Finsupp.count_toMultiset

Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Data/Polynomial/Coeff.lean
Expand Up @@ -224,7 +224,7 @@ end Fewnomials
@[simp]
theorem coeff_mul_X_pow (p : R[X]) (n d : ℕ) :
coeff (p * Polynomial.X ^ n) (d + n) = coeff p d := by
rw [coeff_mul, sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one]
rw [coeff_mul, Finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one]
· rintro ⟨i, j⟩ h1 h2
rw [coeff_X_pow, if_neg, mul_zero]
rintro rfl
Expand Down
6 changes: 2 additions & 4 deletions Mathlib/LinearAlgebra/Dual.lean
Expand Up @@ -737,15 +737,13 @@ open Module
variable [DecidableEq ι] (h : DualBases e ε)

theorem dual_lc (l : ι →₀ R) (i : ι) : ε i (DualBases.lc e l) = l i := by
erw [_root_.map_sum]
rw [lc, _root_.map_finsupp_sum, Finsupp.sum_eq_single i (g := fun a b ↦ (ε i) (b • e a))]
-- Porting note: cannot get at •
-- simp only [h.eval, map_smul, smul_eq_mul]
rw [Finset.sum_eq_single i]
· simp [h.eval, smul_eq_mul]
· intro q _ q_ne
simp [q_ne.symm, h.eval, smul_eq_mul]
· intro p_not_in
simp [Finsupp.not_mem_support_iff.1 p_not_in]
· simp
#align module.dual_bases.dual_lc Module.DualBases.dual_lc

@[simp]
Expand Down
5 changes: 3 additions & 2 deletions Mathlib/LinearAlgebra/Finsupp.lean
Expand Up @@ -503,10 +503,11 @@ theorem lmapDomain_disjoint_ker (f : α → α') {s : Set α}
· have : Finsupp.sum l (fun a => Finsupp.single (f a)) (f x) = 0 := by
rw [h₂]
rfl
rw [Finsupp.sum_apply, Finsupp.sum, Finset.sum_eq_single x, single_eq_same] at this
rw [Finsupp.sum_apply, Finsupp.sum_eq_single x, single_eq_same] at this
· simpa
· intro y hy xy
simp [mt (H _ (h₁ hy) _ xs) xy]
simp only [SetLike.mem_coe, mem_supported, subset_def, Finset.mem_coe, mem_support_iff] at h₁
simp [mt (H _ (h₁ _ hy) _ xs) xy]
· simp (config := { contextual := true })
· by_contra h
exact xs (h₁ <| Finsupp.mem_support_iff.2 h)
Expand Down

0 comments on commit b86770a

Please sign in to comment.