login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for Polynomial Coefficients revision 3 of 4

1 2 3 4
Editor: test1
Time: 2015/10/20 14:12:20 GMT+0
Note:

changed:
-in what order the coefficients themselves are listed. Remember
in what order the coefficients themselves are listed.  In fact
coefficients are listed in monomial order.  If one need to
both coeffcients and variables one can use 'monomials' to get
them together, or use 'degree' on monomials to extract variables.
\begin{axiom}
pol1 := first(Dg)
monomials(pol1)
coefficients(pol1)
map(degree, monomials(pol1))
pol2 := pol1::MPOLY([p0,p1,p2,p3], INT)
monomials(pol2)
coefficients(pol2)
map(degree, monomials(pol2))
\end{axiom}

Remember

Let's examine a simple case:

fricas
Dg :=  [p3 - 3*p2 + 3*p1 - p0,3*p2 - 6*p1 + 3*p0,3*p1 - 3*p0,p0]

\label{eq1}\left[{p 3 -{3 \  p 2}+{3 \  p 1}- p 0}, \:{{3 \  p 2}-{6 \  p 1}+{3 \  p 0}}, \:{{3 \  p 1}-{3 \  p 0}}, \: p 0 \right](1)
Type: List(Polynomial(Integer))

Now calculate coefficients in two ways:

fricas
map(coefficients, Dg::List MPOLY([p0,p1,p2,p3], INT))

\label{eq2}\left[{\left[ - 1, \: 3, \: - 3, \: 1 \right]}, \:{\left[ 3, \: - 6, \: 3 \right]}, \:{\left[ - 3, \: 3 \right]}, \:{\left[ 1 \right]}\right](2)
Type: List(List(Integer))

and

fricas
map(coefficients, Dg::List MPOLY([p3,p2,p1,p0], INT))

\label{eq3}\left[{\left[ 1, \: - 3, \: 3, \: - 1 \right]}, \:{\left[ 3, \: - 6, \: 3 \right]}, \:{\left[ 3, \: - 3 \right]}, \:{\left[ 1 \right]}\right](3)
Type: List(List(Integer))

As you see the list are all reversed, but... they were not padded with zeros. While in my opinion they should be - we have a given order of variables, and alone 1 in the last list suggests that this is a coefficient of p3 while it isn't. It is a coefficient of p0.

According to the Axiom book function coefficients does not include zeros in the list. Furthermore it does not say explicitly in what order the coefficients themselves are listed. In fact coefficients are listed in monomial order. If one need to both coeffcients and variables one can use monomials to get them together, or use degree on monomials to extract variables.

fricas
pol1 := first(Dg)

\label{eq4}p 3 -{3 \  p 2}+{3 \  p 1}- p 0(4)
Type: Polynomial(Integer)
fricas
monomials(pol1)

\label{eq5}\left[ p 3, \: -{3 \  p 2}, \:{3 \  p 1}, \: - p 0 \right](5)
Type: List(Polynomial(Integer))
fricas
coefficients(pol1)

\label{eq6}\left[ 1, \: - 3, \: 3, \: - 1 \right](6)
Type: List(Integer)
fricas
map(degree, monomials(pol1))

\label{eq7}\left[ p 3, \: p 2, \: p 1, \: p 0 \right](7)
Type: List(IndexedExponents?(Symbol))
fricas
pol2 := pol1::MPOLY([p0,p1,p2,p3], INT)

\label{eq8}- p 0 +{3 \  p 1}-{3 \  p 2}+ p 3(8)
Type: MultivariatePolynomial?([p0,p1,p2,p3],Integer)
fricas
monomials(pol2)

\label{eq9}\left[ - p 0, \:{3 \  p 1}, \: -{3 \  p 2}, \: p 3 \right](9)
Type: List(MultivariatePolynomial?([p0,p1,p2,p3],Integer))
fricas
coefficients(pol2)

\label{eq10}\left[ - 1, \: 3, \: - 3, \: 1 \right](10)
Type: List(Integer)
fricas
map(degree, monomials(pol2))

\label{eq11}\left[ p 0, \: p 1, \: p 2, \: p 3 \right](11)
Type: List(IndexedExponents?(OrderedVariableList?([p0,p1,p2,p3])))

Remember that there are also terms of degree higher than 1. In fact the two multivariate polynomials that you used above are formally identical

fricas
(Dg::List MPOLY([p0,p1,p2,p3], INT)=Dg::List MPOLY([p3,p2,p1,p0], INT))::Boolean

\label{eq12} \mbox{\rm true} (12)
Type: Boolean

To produce a list of coefficients of the terms of degree 1, including the zeros and in a specific order, use the function coefficient like this:

fricas
[[coefficient(p,x,1) for x in [p0,p1,p2,p3]] for p in Dg]

\label{eq13}\left[{\left[ - 1, \: 3, \: - 3, \: 1 \right]}, \:{\left[ 3, \: - 6, \: 3, \: 0 \right]}, \:{\left[ - 3, \: 3, \: 0, \: 0 \right]}, \:{\left[ 1, \: 0, \: 0, \: 0 \right]}\right](13)
Type: List(List(Polynomial(Integer)))

And of course you can use this to produce a matrix.

fricas
matrix %

\label{eq14}\left[ 
\begin{array}{cccc}
- 1 & 3 & - 3 & 1 
\
3 & - 6 & 3 & 0 
\
- 3 & 3 & 0 & 0 
\
1 & 0 & 0 & 0 
(14)
Type: Matrix(Polynomial(Integer))

Actually, unstated assumption in FriCAS? is that multivariate polynomials are sparse, so omiting zeros is desirable. For univariate polynomials one can use vectorise. Choosing p0 as main variable and converting to univariate polynomial in one variable we get:

fricas
[vectorise(univariate(p, p0), 2) for p in Dg]

\label{eq15}\left[{\left[{p 3 -{3 \  p 2}+{3 \  p 1}}, \: - 1 \right]}, \:{\left[{{3 \  p 2}-{6 \  p 1}}, \: 3 \right]}, \:{\left[{3 \  p 1}, \: - 3 \right]}, \:{\left[ 0, \: 1 \right]}\right](15)
Type: List(Vector(Polynomial(Integer)))