Skip to content

Commit

Permalink
feat: add Finsupp.sum_cons (#6604)
Browse files Browse the repository at this point in the history
Adds `Finsupp.sum_cons`. Analogous to `Fin.sum_cons`, but for the Finsupp version.



Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
  • Loading branch information
BoltonBailey and eric-wieser committed Sep 8, 2023
1 parent 9afc13a commit 4df62d3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Mathlib/Algebra/BigOperators/Finsupp.lean
Expand Up @@ -7,6 +7,8 @@ import Mathlib.Data.Finsupp.Indicator
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Algebra.BigOperators.Order
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Data.Finsupp.Fin
import Mathlib.GroupTheory.Submonoid.Membership

#align_import algebra.big_operators.finsupp from "leanprover-community/mathlib"@"842328d9df7e96fd90fc424e115679c15fb23a71"
Expand Down Expand Up @@ -627,6 +629,18 @@ lemma prod_indicator_index [Zero M] [CommMonoid N]
(indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=
(prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))

lemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :
(sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by
rw [sum_fintype _ _ (fun _ => rfl), sum_fintype _ _ (fun _ => rfl)]
exact Fin.sum_cons i σ

lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)
(f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :
(sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by
rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]
simp_rw [Fin.sum_univ_succ, cons_zero, cons_succ]
congr

end Finsupp

theorem Finset.sum_apply' : (∑ k in s, f k) i = ∑ k in s, f k i :=
Expand Down

0 comments on commit 4df62d3

Please sign in to comment.