axiom-mail
[Top][All Lists]
Advanced

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

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


From: root
Subject: [Axiom-mail] coefficients of a polynomial (or expr int)
Date: Sun, 18 Sep 2005 21:34:32 -0400

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

#p

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

elt(p,1)

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

We can ask for the coefficient of a monomial with

coefficient(p.1,x,2) 

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

   coefficient(m,x,2)

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
p:=monomials(n)

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


Tim




reply via email to

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