McLaughlin, James on Fri, 03 Jun 2011 19:27:02 +0200

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

RE: Multiple Summation Question

Thanks to Karim and Hauke for their suggestions. I will try to make them work (I am a very basic programmer in pari).

I may have mis-stated the problem, or maybe over simplified it by stating the example I gave, so here is another attempt to describe in more detail is what i hope to do.

F(k)=Sum_{j_1=1}^1 Sum_{j_2=1}^2 ... Sum_{j_k=1}^k Product_{i=1}^k f_i (j_1,j_2, ..., j_i, other parameters)

each f_i has a similar form, say
 f_i (j_1,j_2, ..., j_i, other parameters)
 = 1+ j_1*j_2*...*j_i + q^(i*j_i - (i-1)*j_{i-1}) + a_1*a_2*...*a_i/a_{k-i+1}.

(q and a_1, a_2, ...  are previously defined values).

I would like to set up something like Karim's loop(k) function that would return F(k) for any integer k.

My apologies if the previous explanations also cover this case - as I said my pari skills are pretty basic.

Jimmy Mc Laughlin

From: Karim Belabas []
Sent: Thursday, June 02, 2011 4:05 AM
Subject: 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.


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
F-33405 Talence (France)  [PARI/GP]