Coding Complex Summation formulas

I have a pretty nasty sum that consists of n number of nestedsummations. n is a parameter. I need a nice way of coding it. I'm thinking recursion but there might be a better way. for some reason I can't find much references on this.nikita
[289 byte] By [Nikita04a] at [2007-9-28 11:44:51]
# 1
could you please be a little bit more specific about your problem?How does the formula look like?Zerjillo
Zerjioa at 2007-7-12 2:32:58 > top of Java-index,Other Topics,Algorithms...
# 2

Ok, here it is, following the convention for the summation.

sum(lowerIndex; upperLimit; <expression>)

sum(i=d;n;sum(j1=d-1;i-1;sum(j2=j1;i-1; ... sum(jd=jd-1; i-1;

prod(k=0 where k != j1-(d-1), j2-(d-1-1), ..., jd; i-1,x-x[k])))))

Looks much better using sigma and pi :)

Btw, 5 dukes to anyone who knows what this formula represents. Note that the formula is not complete.

Nikita04a at 2007-7-12 2:32:58 > top of Java-index,Other Topics,Algorithms...
# 3

Don't know if this is what you are looking for, but I think you should obviously use recursion. I have tried to solve your problem, but there are some things I really don't catch... For example, what's x? An array? a Variable? both things?

Well, here is the code I have made, I hope if this is not exactly what you are looking for at least give you hints on how to solve your complex sums.

And of course I have no idea of what this formula is about... But believe me, I don't care too much (i'm joking).

public class Sumas {

private double x;

private double[] xs;

private int d;

private int n;

public Sumas() { // Here you should intialize x, xs, d and n. The actual initialization is an example

n = 5;

d = 3;

x = 10;

xs = new double[n];

for (int i = 0 ; i < n ; i++) {

xs[i] = i;

}

}

private double calculate() {

int[] js = new int[d];

double aux = 0.0;

for (int i = d ; i <= n ; i++) {

aux += sum(js, 0, i);// In the beggining the depth is 0

}

return aux;

}

private double sum(int[] js, int depth, int i) {

double aux = 0.0;

if (depth == d - 1) { // If we are in the lower level of the recursion

return mul(js, i);

}

for (js[depth] = d - 1 ; js[depth] <= i - 1 ; js[depth]++) {

aux += sum(js, depth + 1, i);

}

return aux;

}

private double mul(int[] js, int i) {

double aux = 1.0;

for (int k = 0 ; k <= i - 1 ; k++) {

boolean shouldBeAvoided = false;

for (int h = 1 ; h <= js.length ; h++) {

if (k == js[h - 1] - (d - h)) {

shouldBeAvoided = true;

break;

}

}

if (!shouldBeAvoided) {

aux *= x - xs[k];

}

}

return aux;

}

public static void main(String[] args) {

Sumas aux = new Sumas();

System.out.println(aux.calculate());

}

}

Hints: js is an array containig all j1 ... jd values. Note that in Java are indexed from 0, not 1.

depth controls in which sum we are... Again 0 is the "j1" and depth = d - 1 is the one with jd.

Hope this helps

Zerjillo

Zerjioa at 2007-7-12 2:32:58 > top of Java-index,Other Topics,Algorithms...
# 4
>> 5 dukes to anyone who knows what this formula representsI *love* quizzes! But I don't feel like getting into the function, so I'll give it a random guess.sin?
levi_ha at 2007-7-12 2:32:58 > top of Java-index,Other Topics,Algorithms...
# 5
don't think so... i really don't understand it because of the x[] part...it should be a function that uses an array...Maybe nik will tell us :-PZerjillo
Zerjioa at 2007-7-12 2:32:58 > top of Java-index,Other Topics,Algorithms...
# 6
Thanks for the input guys.The formula parameters are:- x array containing domain elements- d,n are non-negative integers- x is a domain value at which function value we want to know of
Nikita04a at 2007-7-12 2:32:58 > top of Java-index,Other Topics,Algorithms...
# 7
well, if you say what it represents (in case you know it of course), then we here might be able to give you a formula to solve it or sumthin'anyhow...could you give it with sigma and pi, so it would be little bit easier to understand.
VaskoLa at 2007-7-12 2:32:58 > top of Java-index,Other Topics,Algorithms...
# 8
I coded it and recursion seemes to be the best choice. I'm having some problems building the string as I expand this formula but I will eventually fix it.here is the formula: http://www.geocities.com/nikitaruziv/Pk.jpg
Nikita04a at 2007-7-12 2:32:58 > top of Java-index,Other Topics,Algorithms...
# 9
Try this, http://www.geocities.com/nikitaruziv/Pk.htm
Nikita04a at 2007-7-12 2:32:58 > top of Java-index,Other Topics,Algorithms...