request for comments/improvements/style of first Maxima script



Thanks for sharing your source with us.

Here's how I would do it:

P(x, n) := bernpoly(x, n+1)/(n+1)!$

phi[i,s,alpha] :=
  if i=0 then product(x[i]^5,i,1,s)
  else
   phi[i-1,s,alpha]
      +
   sum(
       sum( (-1)^ni * P(x[i],ai) * subst( x[i]=ni, diff(phi[i-1,s,alpha],
x[i], ai) ),
            ni, 0, 1),
       ai, 0, alpha-1)$

phi[2,2,2];  =>

x[1]^5*x[2]^5-5*(x[1]^2-x[1]+1/6)*x[2]^5/2-(x[1]-1/2)*x[2]^5

-(5*x[1]^5-25*(x[1]^2-x[1]+1/6)/2-5*(x[1]-1/2))*(x[2]^2-x[2]+1/6)/2
                   -(x[1]^5-5*(x[1]^2-x[1]+1/6)/2-x[1]+1/2)*(x[2]-1/2)

Notice that phi does not have an (x) argument -- it is not needed, we simply
manipulate *expressions*.  Also, no loop is needed: recursion with memoizing
is enough.  Finally, I have added s and alpha as subscripts to phi so that
the same run can have different values of s and alpha without running into
the memoizing issue I mentioned earlier.

Hope this is helpful.

           -s