# [Maxima] operations on polynomial expressions

Fabrizio Caruso caruso at dm.unipi.it
Tue Dec 19 11:55:03 CST 2006

```Hi

The problem is to write a multivariate polynomial
in x_1,x_2,...,x_n as a sum of monomials
(coefficients X power products)
where no x_i occurs in coefficients
and where monomials with the same power products
are summed up together.

Example:
x(y+z)+c xy -> (c+1)xy + xz
(c does not have to be a number)

Fabrizio

On Tue, 19 Dec 2006, Richard Fateman wrote:

> I don't know why this task needs extra programs or many arguments.
>
> Consider
>   ans:[]\$
> makealist(r,x):= for i:hipow(r,x) step -1 thru 0 do
> ans:cons(ratcoef(r,x,i),ans)\$
>
> makealist(a*x^3+b*x+c,x);  -->  [c,b,0,a]
>
> If the argument r is originally put in rational form, e.g.  r:rat(r,x)\$
> this should be very fast.
>
> I don't know what you want to do with the coefficients, so I show how to put
> them in a list.  You can multiply them by x^i or something else, and sum
> them up, if you wish.  Or you can just use ratexpand(r), as I've mentioned
> before here.
> RJF
>
>
>
> > -----Original Message-----
> > From: maxima-bounces at math.utexas.edu [mailto:maxima-
> > bounces at math.utexas.edu] On Behalf Of Fabrizio Caruso
> > Sent: Tuesday, December 19, 2006 9:00 AM
> > To: Andrej Vodopivec
> > Cc: maxima at math.utexas.edu; Chris Sangwin
> > Subject: Re: [Maxima] operations on polynomial expressions
> >
> > Hi
> >
> > load(coeflist) produces the following error:
> > "
> > /usr/share/maxima/5.10.0/share/contrib/format/coeflist.lisp
> >  -- an error.  Quitting.  To debug this try debugmode(true);
> > "
> > I am using Maxima 5.10.0 and clisp.
> > Note: gcl does not let me call functions with a
> > high number of arguments.
> >
> > My original problem was to write a multivariate polynomial
> > as a sum of monomials with coefficients free of the variables.
> >
> >   Fabrizio
> >
> > On Sat, 25 Nov 2006, Andrej Vodopivec wrote:
> >
> > > Also load the coeflist package:
> > >
> > > (%i3) a*(x+y+z)^2 + b*(x-y-z)^2;
> > > (%o3) a*(z+y+x)^2+b*(-z-y+x)^2
> > > (%i4) format(%, %poly(x,y,z));
> > > (%o4) (b+a)*z^2+(2*b+2*a)*y*z+(2*a-2*b)*x*z+(b+a)*y^2+(2*a-
> > 2*b)*x*y+(b+a)*x^2
> > >
> > > Andrej
> > >
> > > On 11/25/06, Chris Sangwin <sangwinc at for.mat.bham.ac.uk> wrote:
> > > >
> > > > Fabrizio,
> > > >
> > > > I suggest you look at the "format" package.  It is useful for these
> > kinds
> > > > of manipulations.
> > > >
> > > >
> > > > There is some documentation online at
> > > >
> > > > http://matsrv3.bham.ac.uk/scripts/maxima/format/format.pdf
> > > >
> > > > (I can't find it in the "proper" place, sorry!)
> > > >
> > > > Chris
> > >
> > _______________________________________________
> > Maxima mailing list
> > Maxima at math.utexas.edu
> > http://www.math.utexas.edu/mailman/listinfo/maxima
>
```