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.
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