I don't understand the continuing discussion on this point.
What Stavros has written does not provide an expression
as a SUM OF MONOMIALS, which was the original request.
So far as I can tell, RATEXPAND does exactly, precisely,
what was requested, in that an expression is translated into
a SUM of MONOMIALS. The only remaining requirement is
the ordering.
Since Maxima has its own way of ordering terms, you can insist
on your own in a few ways; e.g. by ratvars() and simp:off,
or by picking out the terms in a sorted list.
Perhaps the simplest way of doing the latter is something like
e1:ratexpand(%);
makelist(coeff(e1,x,i),i,0,hipow(e1,x));
though a faster way would be to make the expression e1 into
a list and then use sort.
For an expression with N terms, ratexpand is like
N calls to ratcoeff, except it is hugely faster.
Am I missing something that ratexpand DOESN'T do the job?
RJF
Stavros Macrakis wrote:
> Here is a simple way to re-express something as a polynomial in var:
>
> polyform(expr,var):= ev(ratdisrep(rat(isolate(expr,var),var)),eval);
>
> If there are non-polynomial parts, they end up in the 0th order
> (constant) polynomial term.
>
> I don't much like the way it uses "ev" to substitute back the
> E-variables, but I don't know any simple way of making that cleaner.
> This means that the variables in your expression should not have been
> assigned values.
>
> Here are some examples comparing polyform to rat:
>
> ex: x*(y+1)^3-(x+1)*a;
>
> rat(ex,x) => (y^3+3*y^2+3*y-a+1)*x-a
> -- expands y subexpression unnecessarily
> polyform(ex,x) => x*((y+1)^3-a)-a
> -- does not expand y terms
>
> rat(ex,y) => x*y^3+3*x*y^2+3*x*y+(-a+1)*x-a
> -- canonicalizes x terms
> polyform(ex,y) => x*y^3+3*x*y^2+3*x*y-a*(x+1)+x
> -- does not combine x terms
>
> rat(ex,a) => (-x-1)*a+x*y^3+3*x*y^2+3*x*y+x
> polyform(ex,a) => x*(y+1)^3+a*(-x-1)
> -- does not expand
> -- though the a^1 term does not appear first, the exprssion
> -- is nonetheless a polynomial in a.
> -- This has to do with Maxima's variable order canonicalization
>
> rat(ex,xxx) => x*y^3+3*x*y^2+3*x*y+(-a+1)*x-a
> -- expands unnecessarily
> polyform(ex,xxx) => x*(y+1)^3-a*(x+1)
> -- leaves expression untouched
>
> _______________________________________________
> Maxima mailing list
> Maxima@www.math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima