Zulip Chat Archive

Stream: Is there code for X?

Topic: Summing equalities over a Fintype


Snir Broshi (Aug 15 2025 at 19:40):

Hello, is there a theorem similar to the following:

import Mathlib.Algebra.BigOperators.Group.Finset.Defs

theorem sum_eq_sum
    {ι : Type*} [Fintype ι]
    {A : Type*} [AddCommMonoid A]
    {lhs rhs : ι  A} (h :  i, lhs i = rhs i) :
     i, lhs i =  i, rhs i := by
  sorry

I found the inductive case in a weird corner of mathlib:

import Mathlib.Algebra.BigOperators.Group.Finset.Defs

#check Mathlib.Tactic.LinearCombination.add_eq_eq

Thanks

Aaron Liu (Aug 15 2025 at 19:41):

import Mathlib.Algebra.BigOperators.Group.Finset.Defs

theorem sum_eq_sum
    {ι : Type*} [Fintype ι]
    {A : Type*} [AddCommMonoid A]
    {lhs rhs : ι  A} (h :  i, lhs i = rhs i) :
     i, lhs i =  i, rhs i :=
  congrArg Finset.univ.sum (funext h)

Aaron Liu (Aug 15 2025 at 19:42):

oh it's docs#Fintype.sum_congr

Aaron Liu (Aug 15 2025 at 19:43):

import Mathlib.Data.Fintype.BigOperators

theorem sum_eq_sum
    {ι : Type*} [Fintype ι]
    {A : Type*} [AddCommMonoid A]
    {lhs rhs : ι  A} (h :  i, lhs i = rhs i) :
     i, lhs i =  i, rhs i :=
  Fintype.sum_congr lhs rhs h

Snir Broshi (Aug 15 2025 at 19:44):

Woah, thanks! Can I ask how did you find those? My search-fu is still weak

Aaron Liu (Aug 15 2025 at 19:44):

I'll reproduce my search here

Aaron Liu (Aug 15 2025 at 19:45):

@loogle Finset.univ, Finset.sum, "congr"

loogle (Aug 15 2025 at 19:45):

:search: Finset.sum_congr_set, Fintype.sum_congr, and 1 more

Aaron Liu (Aug 15 2025 at 19:45):

It's the second result

Aaron Liu (Aug 15 2025 at 19:45):

For the other one, is just a simple congruence

Aaron Liu (Aug 15 2025 at 19:46):

you can also use the congr() syntax like this:

import Mathlib.Algebra.BigOperators.Group.Finset.Defs

theorem sum_eq_sum
    {ι : Type*} [Fintype ι]
    {A : Type*} [AddCommMonoid A]
    {lhs rhs : ι  A} (h :  i, lhs i = rhs i) :
     i, lhs i =  i, rhs i :=
  congr( i, $(h i))

Aaron Liu (Aug 15 2025 at 19:47):

I think it actually produces almost the exact same term

Snir Broshi (Aug 15 2025 at 19:48):

In what sense is it a congruence? I thought the proof would use induction

Aaron Liu (Aug 15 2025 at 19:51):

well since lhs = rhs

Aaron Liu (Aug 15 2025 at 19:52):

then ∑ i, lhs i = ∑ i, rhs i just by substituting

Ruben Van de Velde (Aug 15 2025 at 20:22):

It's simpler because you're summing over the whole type; docs#Fintype.sum_congr is slightly more involved because it only requires equality on the set you're summing over


Last updated: Dec 20 2025 at 21:32 UTC