collecting terms



"Fabrizio Caruso"  wrote:

> I am looking for a command that collects all the terms
> of a polynomial w.r.t. a variable, i.e. it writes the polynomial
> as a sum of monomials with increasing/decreasing powers of
> a given variable.
> Is there one?

you may find a definition like this one useful:

rewriteAsPolynomialIn (p, t) :=
  block ([expanded, degreeInT, result],
    expanded : expand(p),
    degreeInT: hipow(expanded, t),
    result : 0,
    for idx : 0 thru degreeInT do
      result : result + t^idx*ratcoeff(expanded, t, idx),
    result
);

Usage:
 t :  (x+1)^4 + a*(x+1)^2+b*(x+1)+c;
rewriteAsPolynomialIn(t, x);


Are there better solutions?

Greetings, Boris