Question: How to do double Summation with recursion?

Having trouble with a double summation function that calls itself recursively.


S2 := (p, k, n)-> piecewise(0 <= n and n < k, 1, n < 0, 0, sum(sum(p^y*(1-p)^(m-y)*S2(p, k, n-m), m = y+1 .. y+k-1), y = 1 .. n-k+1));


When evaluated with S2(p,2,-1) and S2(p,2,1) it works correctly (first two conditions are working)

However, when I try evaluate S2(p,2,2) Maple appears to run unbounded(?) and chokes. In fact, doing the limits by hand, I expect the function to call itself recursively once.


(For reference, the correct answer to S2(p,2,2) is p-p^2)

A working example of a double summation with recursion might help me as well.

Please Wait...