RFC: extracting coefficients of a multivariate polynomial
Subject: RFC: extracting coefficients of a multivariate polynomial
From: andre maute
Date: Thu, 24 Apr 2008 21:16:34 +0200
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)
)$
-------------------------------------------------------------