Grouping terms



Thanks for your interest in Maxima.

You can control the grouping of the variables using facsum.  For example:

(%i1) expr:(x+y+z+1)^2;
(%o1) (z+y+x+1)^2
(%i2) facsum(expr);
(%o2) (z+y+x+1)^2
(%i3) facsum(expr,x);                    -- express as a polynomial in x
(%o3) (z+y+1)^2+2*x*(z+y+1)+x^2
(%i4) facsum(expr,y);                    -- express as a polynomial in y
(%o4) (z+x+1)^2+2*y*(z+x+1)+y^2
(%i5) facsum(expr,x,y);                 -- express as a polynomial in x and
y
(%o5) (z+1)^2+2*y*(z+1)+2*x*(z+1)+y^2+2*x*y+x^2
(%i6) facsum(expr,x,y,z);              -- express as a polynomial in x, y,
and z
(%o6) z^2+2*y*z+2*x*z+2*z+y^2+2*x*y+2*y+x^2+2*x+1

About coeff -- it is strictly syntactic -- coeff(...,x*y,...) looks for a
term of the form EXPR*x*y, where EXPR has no x or y terms (but may have
terms *involving* x and y).  This should be better documented.

To get the coefficients regardless of the form of the input, you can either
first change the form of the input (using facsum or expand for example) and
then use coeff or you can use ratcoeff, which internally expands the
expression completely.

                -s

On Mon, Oct 4, 2010 at 03:58, Russell Shaw <rjshaw at netspace.net.au> wrote:

> Hi,
>
> In a polynomial:
>
>  (a*x + y)^2 + a*x*y + y
>
> How do i get the terms to be grouped according to x and y?:
>
> (%o40)  a*x^2 + y^2  + 3*a*x*y + y
>
> Also, coeff(%o40, x*y) gives 0.
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>