Karim Belabas on Thu, 02 Jun 2011 10:07:03 +0200

 Re: Multiple Summation Question

```* McLaughlin, James [2011-06-01 22:42]:
> How can I set up a program to do multiple summation of the form, say,
> Sum_{j_1=1}^1 Sum_{j_2=1}^2 ... Sum_{j_k=1}^k  ( j_1^j_1+ j_2^j_2 + j_k^j_k) that will work for any integer k >=1?
>
> What I would like is a single program that would compute the value of
> this sum for an particular, after specifying the only the value of k.
> My problems are that I do not know how to write a program that creates
> the k different summation variables j_1, ... j_k after specifying only
> what particular value k has,

The first problem is simple :

? loop(k) = forvec(J = vector(k,i,[1,i]), print(J));
? loop(3)
[1, 1, 1]
[1, 1, 2]
[1, 1, 3]
[1, 2, 1]
[1, 2, 2]
[1, 2, 3]

> and even if I can define these summation variables, how do I set up the
> k-fold summation Sum_{j_1=1}^1 Sum_{j_2=1}^2 ... Sum_{j_k=1}^k .

? f(J) = sum(i=1,#J, J[i]^J[i])
? SUM(k) = my (s=0); forvec(J = vector(k,i,[1,i]), s += f(J)); s;

For the simple sum above, you'd precompute the values x^x for x <= k.
With more programming effort you can save many of the internal additions :
it's wasteful to recompute the whole of f(J) when only one component of
J changes.

Cheers,

K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite Bordeaux 1          Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux1.fr/~belabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux1.fr/  [PARI/GP]
`

```