Zulip Chat Archive

Stream: new members

Topic: Managing finite sums


Vincent Beffara (Apr 26 2022 at 11:56):

What is the preferred way to manage partial sums out of a sequence, like these?

def S1 (X :   ) (n : ) :  :=  i in finset.range n, X i -- has e.g. finset.sum_add_distrib
def S2 (X :   ) (n : ) :  :=  i : finset.range n, X i
def S3 (X :   ) (n : ) :  :=  i : fin n, X i
def S4 (X :   ) (n : ) :  := ∑' i : finset.range n, X i -- has e.g. tsum_add

They feel rather equivalent to me (except for the tsum version, which wants to be noncomputable and has differently named API) but perhaps there are differences down the line and one is preferred?

Sebastien Gouezel (Apr 26 2022 at 12:01):

Definitely ∑ i in finset.range n, X i, as it avoids coercions.

Eric Wieser (Apr 26 2022 at 12:18):

S3 can be a good choice in some situations too

Eric Wieser (Apr 26 2022 at 12:20):

Note finset.sum_add_distrib works on S2 and S3 too


Last updated: Dec 20 2023 at 11:08 UTC