RFC: extracting coefficients of a multivariate polynomial



 Try timing this..

my_coeff4(v,exps,poly) := block(

        [c:[],k,l,h,rpoly,lv:length(v)],

        rpoly : rat(poly,v),
        for k : 1 thru length(exps) do block(
                h : rpoly,
                for l : 1 thru length(v) do block(
                        h : ratcoeff(h,v[lv+1-l],exps[k][lv+1-l])),
                c : cons(h,c)),

        return(reverse(c))

)$

RJF

> -----Original Message-----
> From: maxima-bounces at math.utexas.edu 
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of andre maute
> Sent: Thursday, April 24, 2008 12:17 PM
> To: maxima at math.utexas.edu
> Subject: Re: [Maxima] RFC: extracting coefficients of a 
> multivariate polynomial
> 
> On Thursday 24 April 2008, Stavros Macrakis wrote:
> > For operations on polynomials, it is best to represent your
> > expressions in Canonical Rational Expression (CRE) form, 
> which you do
> > using the rat(...) operation.  After that, ratcoeff(expr, 
> var, degree)
> > is efficient, especially if the variable is the main variable of the
> > expression.
> 
> I did some timings for my application with the new functions 
> (see below)
> and the old one posted in the first mail.
> 
> I used time under linux
> 
> my_coeff  : 14m9.087s (winner)
> my_coeff2 : 15m5.661s
> my_coeff3 : 14m52.244s
> 
> so the first one is the winner. ;-)
> looks like i'll have to stick with the old one :-(
> 
> Regards
> Andre
> 
> 
> -------------------------------------------------------------
> my_coeff2(v,exps,poly) := block(
> 
>         [c,k,l,h,rpoly],
> 
>         rpoly : rat(poly,v),
> 
>         c : [],
>         for k : 1 thru length(exps) do block(
>                 h : rpoly,
>                 for l : 1 thru length(v) do block(
>                         h : ratcoeff(h,v[l],exps[k][l])
>                 ),
>                 c : append(c,[h])
>         ),
> 
>         return(c)
> 
> )$
> -------------------------------------------------------------
> my_coeff3(v,exps,poly) := block(
> 
>         [c,k,l,h,rpoly],
> 
>         rpoly : rat(poly,v),
> 
>         c : [],
>         for k : 1 thru length(exps) do block(
>                 h : rpoly,
>                 for l : 1 thru length(v) do block(
>                         h : ratcoeff(h,v[length(v)+1-l],exps[k]
> [length(v)+1-l])
>                 ),
>                 c : append(c,[h])
>         ),
> 
>         return(c)
> 
> )$
> -------------------------------------------------------------
> 
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>