[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] [Axiom-mail] coefficients of a polynomial (or expr int

From: root
Subject: [Axiom-developer] [Axiom-mail] coefficients of a polynomial (or expr int)
Date: Sun, 18 Sep 2005 21:01:35 -0500


So we create a Polynomial(Integer) thus:

m := 3*x^2 + 2*x +6

and we ask for the monomials:

p := monomials(m)

which returns a List(Polynomial(Integer))

We can ask for the length of the list using the # operator


We can ask for an element of the list using the elt operator


or just use the notation p.1, p.2, etc

We can ask for the coefficient of a monomial with


where x is the variable of interest (it might be multivariate)
and 2 is the power (we could have used the whole polynomial
directly as in


We can generate a list with the notation

[ function for i in a..b]

So we can directly create a list of the coefficients in the
variable 'x' with

[coefficient(elt(p,i),x,#p-i) for i in 1..#p]

Of course, Axiom is strongly typed and cannot guarantee that the
expression #p-i will always be non-negative. It will complain about
this and "step thru" (interpret) the expression. You can cure this
by explicitly telling it that the expression is always a non-negative
integer (NNI) thus:

[coefficient(elt(p,i),x,(#p-i)::NNI) for i in 1..#p]

which will return a list of the coefficients of the monomials.

The same thing will work if you start with an Expression(Integer).

n:EXPR(INT) := 3*x^2 + 2*x +6

which returns a LIST(POLY(INT)) and you are back to the previous case


Axiom-mail mailing list

forwarded from

reply via email to

[Prev in Thread] Current Thread [Next in Thread]