# Sum over a list of indices

Suppose I have a sum like

$$\sum_{i_1,i_2,\dots,i_n\geq 0} f(i_1,\dots,i_n)$$

How can I write this with Mathematica? In other words, is there a way of generalizing something like the following to $$n$$ indices?

Sum[Sum[Sum[f[{i1,i2,i3}],{i1,0,Infinity}],{i2,0,Infinity}],{i3,0,Infinity}]

• Sum[f[i1, i2, i3], {i1, 0, Infinity}, {i2, 0, Infinity}, {i3, 0, Infinity}] Commented Jul 21, 2021 at 8:19
• @cvgmt That's already better, thanks, but can I define a function that takes $n$ for an argument and returns this for n indices? For example Sum[f[I], {I, 0 Infinity}] where I is a list of $n$ symbols and it is understood that {I,0,Infinity} means each symbol in the list is separately summed. Commented Jul 21, 2021 at 8:23

Here's a way to make the syntax proposed in the commands work:

Sum[f[{i1, i2, i3}], Evaluate[Sequence @@ Thread[{{i1, i2, i3}, 0, ∞}]]]


Or using a predefined list l:

l = {i1, i2, i3};
Sum[f[l], Evaluate[Sequence @@ Thread[{l, 0, ∞}]]]
(* same output *)


One way:

idx = {i1, i2, i3};
lower = {0, 1, 2};
upper = {2, 3, 4};

Sum[f[Sequence @@ idx], Evaluate[Sequence @@ Transpose[{idx, lower, upper}]]]
(* f[0, 1, 2] + f[0, 1, 3] + f[0, 1, 4] + f[0, 2, 2] + f[0, 2, 3] +
f[0, 2, 4] + f[0, 3, 2] + f[0, 3, 3] + f[0, 3, 4] + f[1, 1, 2] +
f[1, 1, 3] + f[1, 1, 4] + f[1, 2, 2] + f[1, 2, 3] + f[1, 2, 4] +
f[1, 3, 2] + f[1, 3, 3] + f[1, 3, 4] + f[2, 1, 2] + f[2, 1, 3] +
f[2, 1, 4] + f[2, 2, 2] + f[2, 2, 3] + f[2, 2, 4] + f[2, 3, 2] +
f[2, 3, 3] + f[2, 3, 4] *)