# Sum with list as its upper limit

Say I want to create the list
$$\{ \sum_{j=1}^{5} 2j, \sum_{j=1}^{6} \frac{5j}{2} \}$$
I guessed that this can be done using the code
Sum[j/{1, 2}*{2, 5}, {j, 1, {5, 6}}]
However what mathematica gives is
$$\Big{\{} \{ \sum_{j=1}^{5} 2j, \sum_{j=1}^{5} \frac{5j}{2} \}, \{ \sum_{j=1}^{6} 2j, \sum_{j=1}^{6} \frac{5j}{2} \} \Big{\}}$$
I guess I could just somehow pick out the right element of the result, but is there a more efficient way to achieve this?

EDIT: Eventually I want to apply this to a case, where I have something like
Sum[f[list,j],{j,1,list}]

• Maybe: MapThread[Sum[# j, {j, 1, #2}] &, {{2, 5/2}, {5, 6}}] – Coolwater Jun 4 at 15:03
• How can I apply this to an arbitrary list and an arbitrary function of that list, e.g. something like Sum[f[list,j],{j,1,list}]? – lomby Jun 4 at 16:14

## 2 Answers

Your question is not very well-defined. It seems that you have a list of different functions, f1, f2, f3, etc., and you want to sum each of those functions to different maximum values. Is that correct? If so:

f1[j_]=2j;
f2[j_]=5j/2;
funclist={f1,f2};
maxsumlist={5,6};
result=MapThread[Sum[#1@j,{j,1,#2}]&,{funclist,maxsumlist}]


Perhaps

sum[a_, b_, c_] := Sum[a j, {j, b, c}]
SetAttributes[sum, Listable]


Examples:

sum[{2, 5}/{1, 2}, 1, {5, 6}]


{30, 105/2}

sum[{a, b}, 1, {n, m}]


{1/2 a n (1 + n), 1/2 b m (1 + m)}

sum[{foo[j], bar[j]}, q, {n, m}] // TeXForm


$$\left\{\sum _{j=q}^n j \text{foo}(j),\sum _{j=q}^m j \text{bar}(j)\right\}$$