RFC: extracting coefficients of a multivariate polynomial
Subject: RFC: extracting coefficients of a multivariate polynomial
From: Richard Fateman
Date: Fri, 25 Apr 2008 07:29:18 -0700
Here's another version. (I haven't run it...)
my_coeff7(v,exps,poly) := block(
[c:[],rpoly:rat(poly), ratvars:reverse(v)],
for k in exps do block([h:rpoly],
for L in v do block([e: k],
h : ratcoeff(h,L,first(e)),
e : rest(e)),
c : cons(h,c)),
return(reverse(c))
)$
/* assumes v is a list of variables like [x,y,z,w,t],
assumes exps is a list of exponents like [ [1,3,5,8,5], [2,2,2,4,5] ...],
assumes poly is a polynomial in vars x,y,z,w,t and perhaps other
parameters. */
The reason this REVERSES ratvars is important.
consider ratvars(x,y,z);
h:rat((1+x+y+z)^28)$
showtime:all$
ratcoef(h,x,2)$ takes 0.5 seconds
ratcoef(h,z,2)$ takes 0.0 seconds.
The first one has to go through all the terms in the polynomial and add up
those that are part of the (.....)x^2 term.
The second one has all that work done free, because the representation has
already added them up.
> -----Original Message-----
> From: maxima-bounces at math.utexas.edu
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of andre maute
> Sent: Friday, April 25, 2008 7:23 AM
> To: maxima at math.utexas.edu
> Subject: Re: [Maxima]RFC: extracting coefficients of a
> multivariate polynomial
>
> As Fateman pointed out,
> 'append'
> to a list in maxima needs O(n) operations,
> where n is the number of list entries.
>
> So I believe one of my problems came from a 'feature' of the
> maxima 5.13.0
> documentation. I'm a programmer with strong C++ background.
> I knew I did need a list, I knew I did need an insert
> function to lists.
> The first I found was append, you know the things children learn in
> elementary school, 'a b c ...' :-)
>
> But in C++, appending to list is an O(1) operation,
> There should really be a kind of warning in the documentation.
>
> Regards
> Andre
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>