# Thread: Dealing with Nested Summations (Series)

1. ## Dealing with Nested Summations (Series)

Expressions in a probability problem look like this (see attached image).
P(d=6)
P(d=8)
P(d=10)
P(d=12) etc.

Each expression contains (d-6)/2 nested sums, each one nested into the former. The lower limit of each nested sum depends on the present value of the summation index of its parent sum.

I have attempted to describe the general formula P(d=d). How could this be programmed into mathematical software, e.g. Maple 12, because I am interested in evaluating P(d=d) for very high values of d?

(E.g. The formula for P(d=100) would contain (100-6)/2 = 47 sums, each one nested into its parent. It would take a long time to program that into a computer! )

So how can I describe this general formula in a way so that I can assign a value for d and simply execute a little program which builds the appropriate expression and evaluates it?

2. This was indeed a headache but think i finally solved it:

Take a look at this algorithm

E(1):=1;E(2)=1 .........E(5):=1;

For (k=1; k<=p; k++)

{

For (i=1;i<=5;i++)

{ V(1)=0; v(2)=0; ............v(5)=0;

For(j=1;j<=5;j++)

{
V(i)=V(i)+j(7-j)*E(j)
}
E(i):=V(i);
}

}

S:= E(1)+E(2)+E(3)+E(4)+E(5);

And that's all

Enjoy and have a nice day !

3. Hush_Hush,
Thank you for looking at this, however I am struggling to comprehend your solution. This is partly due to my lack of experience with do loops but is also because the figures your algorithm produces don't seem to correlate with the figures I get from manual evaluation of my nested summations.

Please would you kindly explain the properties of your solution (e.g. what is p?) and how I can adapt it to my needs.

Many thanks

4. Maybe i put something wrong there .... i'm not Einstein at writing code without compiling it

My algorithm is the following:

E=(1,1,1,1,1) is a vector to keep values of sums

E(1) is keeping the value of sums 1 to 5
E(2)....................................... 2 to 5
.................................................. ...
E(5)........................................5 to 5

Then we will define the number of sums inside the sums to calculate

For (k=1; k<=p; k++) -This loop will repeat for p times

For (i=1;i<=5;i++)-This loop will be 5 times in order to fill E(1),E(2)...E(5) with the new values

V=(0,0,0,0,0) is a vector for the sums calculated in this loop

For(j=1;j<=5;j++)

{
V(i)=V(i)+j(7-j)*E(j)
}

This last loop will calculate the sums 1 to 5, 2 to 5,.... i to 5 ..... 5 to 5

(HERE I FOUND A MISTAKE IT IS For(j=i;j<=5;j++) because it calculates partial sums)

E(i):=V(i); this one is important because it stores the value of temporary vector V(i) to E(i) because V(i) it will be reinitialized at the next loop.

S:= E(1)+E(2)+E(3)+E(4)+E(5); - i don't know if this one is necessary because it depends if you want to calculate for p or for p+1

************************************************** ***

Your E(...) will look like this at different steps

Step 0 : $E_{0}=(1,1,1,1,1)$
Step 1 : $E_{1}=(\sum_{i=1}^{5}i*(7-i)*E_{0}(1),\sum_{i=2}^{5}i*(7-i)*E_{0}(2),$ $\sum_{i=3}^{5}i*(7-i)*E_{0}(3),\sum_{i=4}^{5}i*(7-i)*E_{0}(4),\sum_{i=5}^{5}i*(7-i)*E_{0}(5))$

Step 2 : $E_{2}=(\sum_{i=1}^{5}i*(7-i)*E_{1}(1),\sum_{i=2}^{5}i*(7-i)*E_{1}(2),$ $\sum_{i=3}^{5}i*(7-i)*E_{1}(3),\sum_{i=4}^{5}i*(7-i)*E_{1}(4),\sum_{i=5}^{5}i*(7-i)*E_{1}(5))$

.................................................. ...........................................

Step 1 : $E_{p+1}=(\sum_{i=1}^{5}i*(7-i)*E_{p}(1),\sum_{i=2}^{5}i*(7-i)*E_{p}(2),$ $\sum_{i=3}^{5}i*(7-i)*E_{p}(3),\sum_{i=4}^{5}i*(7-i)*E_{p}(4),\sum_{i=5}^{5}i*(7-i)*E_{p}(5))$

Maybe there are a few mistakes left but if you understand the method you will find the way to solve it.

This is a very complex problem , i'll be happy if i will know that i helped you even with 1%.

Tx for this beautiful problem.

Have a nice day,

Alex.

5. Hush_Hush you are a genius.
You set S:= E(1) at the end, i.e. not E(1)+E(2)+....+E(5) because E(1) is the value of the sum which is already made up of the "child" sums E(2) to E(5).

This is great news, now I can press on and draw some graphs!

Thank you!

Mult'umesc foarte mult

6. This is why i told you it's a matter of p or p+1 because the last sum is not necessary , only if you have to calculate P+1

Thank u for Multumesc

7. Hi Hush_Hush,
I need you to help me a tiny bit more! I found that my formulas were slightly incorrect. Instead of each summation's lower limit being the present value of the parent sum's summation variable, it should be that value MINUS ONE.

I have attached the amended formulas, but I need help changing this in the program that you wrote for me. I spent all day yesterday trying to get it to work but I really struggle with do loops!

I'd be very grateful if you could have one last look at it for me.

By the way, it should not matter whether the lower limit of the first summation is 0 or 1.

Many thanks

8. Did u use "for" or "while" because for While You put i++ at the begining not the end in order for the first i to be 1

9. This is what I have at the moment. This outputs E[0]=E[1]=1512 but the figure it should be is 1956. I think I know why this is: it is because I haven't changed the program from "for j from i to 5 do" to "for j from i-1 to 5 do", but you see, if I do this then I need a value E[-1], which doesn't seem to make sense.

(I am using Maple 12 for this program. What software would you choose?)
Many thanks

--------------------------------------------------------------
d:= 10;
p:= (d-6)*(1/2);

E[0]:= 1; E[1]:= 1; E[2]:= 1; E[3]:= 1; E[4]:= 1; E[5]:= 1;

for k from 1 to p do
{
for i from 0 to 5 do
{
v[0]:= 0; v[1]:= 0; v[2]:= 0; v[3]:= 0; v[4]:= 0; v[5]:= 0;
for j from i to 5 do
{
v[i]:= v[i]+j*(7-j)*E[j];
} od;
E[i]:= v[i];
} od;
} od;

S:= (6!/(6^d))*E[0];

10. d:= 10;
p:= (d-6)*(1/2);

E[0]:= 1; E[1]:= 1; E[2]:= 1; E[3]:= 1; E[4]:= 1; E[5]:= 1;// why do you need E(0)?

for k from 1 to p do
{
for i from 0 to 5 do //1 to 5
{
v[0]:= 0; v[1]:= 0; v[2]:= 0; v[3]:= 0; v[4]:= 0; v[5]:= 0;//don't need v[0]
for j from i to 5 do
{
v[i]:= v[i]+j*(7-j)*E[j];
} od;
E[i]:= v[i];
} od;
} od;

S:= (6!/(6^d))*E[0];//in my opinion should be E[1]

11. If I make those changes I just end up with the original program which you wrote for me.
I need it to work for the updated formulas I sent in post 288228.

The problem is that the outermost summation needs to go from u=1..5 (or 0 to 5 - it doesn't matter which), then the next summation goes from (u-1)..5, the next from (u-2)..5, etc

12. Now i think i understand what your problem is, i tought that this new formula you attached is an error you get on compilation

d:= 10;
p:= (d-6)*(1/2);

E[0]:= 1; E[1]:= 1; E[2]:= 1; E[3]:= 1; E[4]:= 1; E[5]:= 1;

for k from 1 to p do
{
for i from 1 to 5 do
{
v[0]:= 0; v[1]:= 0; v[2]:= 0; v[3]:= 0; v[4]:= 0; v[5]:= 0;
for j from i-1 to 5 do
{
v[i]:= v[i]+j*(7-j)*E[j];
} od;
E[i]:= v[i];
} od;
} od;

S:= (6!/(6^d))*E[0];

In my opinion all you have to do is to change this 2 values in red . Please tell me what you obtained after compilation, i'm curious .

13. There is a problem somewhere with that. The closest I have got is attached as an image.

For each successive nested summation, the lower limit decreases by 1, so you need the j line to read something like:
for j from (i-k) to 5 do

but then there is a problem with the redefinition of v[i], because if you leave it as it is,
v[i]:= v[i] + j(7-j)E[j]
it doesn't work because when k is 2, the E[j] necessitates a value for E[-1], which doesn't make sense.

So I tried changing it to:
v[i]:= v[i] + j(7-j)E[i]
but I am not convinced this makes sense either.

However the answer that this (the attached program) gives is very close numerically to what it should be. (It should be 815/34992 but it's giving 875/34992).

Any ideas? I am confident the problem lies within the j loop

14. I need few hours to think to this new formula. I took this one to easy at the beginning thinking it's the same as the previous but it needs a new approach because u don't have 5 terms in each sum and the length of vectors is variable.

I'll find a solution and i will post it as soon as i can.

Best wishes,

Hush_Hush.

15. Take a look at this code it may need few adjustments but try it first and tell me what u obtained:

for (i=1;i<=(d+4)/2;i++)

{
v[i]=(i-(d-6)/2)(7-i+(d-6)/2);

S[i]=1
}

for(k=0;k<=(d-8)/2;k++)
{

for(i=1;i<=(d+4)/2-k;i++)

{

for(j=1;j<=(d+4)/2;j++)

{
E(j)=0;
}

for (j=i+k;j<=(d+4)/2;j++)

{

E[i]=V[j]*S[j-k-i+1]+E[i];

}

S[i]=E[i];

}

}

I'm not shure about k<=(d-8)/2 try also k<=(d-6)/2 .

At the results you should watch for S[1] to S[5] or S[6].

Have a nice day

Hush.

Page 1 of 2 12 Last