Sum index in a Recursive Procedure Call in Maple

168 Views Asked by At

I'm trying to reproduce Buchholz Polynomials in Maple as outlined by J. Sesma and J. Abad in their paper (equation 14).

The definition given above is a recursive one and so is the code I've created in Maple. I run into problems when using the index of the sum() command in the recursive call. The MWE that produces this error is:

P0 := 1:
P := []:

Pz := proc(n, b, z, P, P0)
        local exp1, exp2, k;
        option trace;
        exp1 := (2*k-1)*(2^(2*k)*bernoulli(2*k))/factorial(2*k);
        exp2 := (2^(2*k)*bernoulli(2*k))/factorial(2*k);
        print(n);
        if n <= 0 then
                return P0;
        else
                return [op(P), (z/2)*sum(exp1*thisproc(n-2*k+1,b,z,P,P0),k=1..(n+1)/2) + (b-2)*sum(exp2*thisproc(n-2*k,b,z,P,P0),k=1..n/2)];
        end if:
end proc:

Pz(1,b,z,P,P0);

The error I get is:

Error, (in Pz) cannot determine if this expression is true or false: -2*k <= -2

Which I believe suggests the sum() command is not passing the current value of the indexing variable k as the sum() command runs the recursive call.

Based on the definition provided by J. Sesma and J. Abad I would expect that P[1]=z/6.

1

There are 1 best solutions below

2
On BEST ANSWER

I don't understand what you are trying to do by having it return a list.

But as far as the use of the index k goes, perhaps this is what you're after.

restart;
P0 := 1:
P := []:

Pz := proc(n, b, z, P, P0) #option trace;
  local exp1, exp2, k;
  exp1 := (2*k-1)*(2^(2*k)*bernoulli(2*k))/factorial(2*k);
  exp2 := (2^(2*k)*bernoulli(2*k))/factorial(2*k);
  if n <= 0 then
    return P0;
  else
    return (z/2)*add(eval(exp1,k=kk)
                     *thisproc(n-2*kk+1,b,z,P,P0),
                     kk=1..(n+1)/2)
           + (b-2)*add(eval(exp2,k=kk)
                       *thisproc(n-2*kk,b,z,P,P0),
                       kk=1..n/2);
  end if:
end proc:

Pz(1,b,z,P,P0):

        1/6*z

Pz(2,b,z,P,P0):

    1/36*z^2+1/3*b-2/3