I am trying to input $\sum_{a_1=1}^{n-1}$$\sum_{a_2=1}^{{a_1}-1}$$\sum_{a_3=1}^{{a_2}-1}$$\sum_{a_4=1}^{{a_3}-1}$$...f({{a_1},{a_2},{a_3},{a_4}...})$ into Mathematica. The number of sums should be a variable, not a constant.

I do not know how to nest a variable amount of sums without having to modify the code every time that variable changes. Could someone please give me an example?


1 Answer 1


Something like this ought to work for you:

With[{m = 4}, 
     Sum[F @@ Array[K, m], 
         Evaluate[Sequence @@ Prepend[Table[{K[j + 1], 1, K[j] - 1}, {j, m - 1}],
                                      {K[1], 1, n - 1}]]]]

which yields

$$\sum_{\tt K[1]=1}^{\tt -1+n} \sum_{\tt K[2]=1}^{\tt -1+K[1]} \sum_{\tt K[3]=1}^{\tt -1+K[2]} \sum_{\tt K[4]=1}^{\tt -1+K[3]} {\tt F[K[1],K[2],K[3],K[4]]}$$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.