 PolynomialTools - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Mathematics : Algebra : Polynomials : PolynomialTools : PolynomialTools/CoefficientVector

PolynomialTools

 CoefficientVector
 return a Vector of coefficients from a univariate polynomial
 CoefficientList
 return a list of coefficients from a univariate polynomial

 Calling Sequence CoefficientVector(p, x, vectoropts, orderopts) CoefficientList(p, x, orderopts)

Parameters

 p - polynom(anything, x) x - name of main variable vectoropt - (optional) a sequence of Vector constructor options; see Vector orderopts - (optional) equation of the form termorder=reverse or termorder=forward

Description

 • The CoefficientVector(p, x) calling sequence returns a Vector of coefficients from a polynomial p in x.
 • The CoefficientList(p, x) calling sequence returns a list of coefficients from a polynomial p in x.
 • If the term order is not specified or termorder=forward, for $p={a}_{0}+{a}_{1}x+...+{a}_{n}{x}^{n}$, the k-th element of the Vector or list returned corresponds to ${a}_{k-1}$.
 • If termorder=reverse is specified, then the coefficients will be stored in the reverse of the above order.
 • These commands are useful because the Maple command coeff is of linear complexity in the degree of the polynomial. Thus, a naive implementation of CoefficientVector would be of quadratic complexity. The actual implementation is of linear complexity.  In fact, for CoefficientVector, if sparse storage is specified as an option, the complexity is linear in the actual number of terms.
 • The inverse commands are FromCoefficientVector and FromCoefficientList.

Examples

 > with(PolynomialTools):
 > p := 1-13*x+x^5;
 ${p}{≔}{{x}}^{{5}}{-}{13}{}{x}{+}{1}$ (1)
 > CoefficientVector(p,x);
 $\left[\begin{array}{c}{1}\\ {-13}\\ {0}\\ {0}\\ {0}\\ {1}\end{array}\right]$ (2)
 > CoefficientVector(p,x,'termorder'='reverse');
 $\left[\begin{array}{c}{1}\\ {0}\\ {0}\\ {0}\\ {-13}\\ {1}\end{array}\right]$ (3)
 > CoefficientList(expand(p^2),x);
 $\left[{1}{,}{-26}{,}{169}{,}{0}{,}{0}{,}{2}{,}{-26}{,}{0}{,}{0}{,}{0}{,}{1}\right]$ (4)
 > CoefficientVector(1+5*x^1000000000,x,storage=sparse);
  (5)
 > CoefficientVector(1+5*x^1000000000,x,storage=sparse,termorder=reverse);
  (6)
 • For the zero polynomial, the CoefficientVector command returns a zero-dimensional Vector and the CoefficientList command returns an empty list.
 > CoefficientVector(0,x);
 $\left[\begin{array}{}\end{array}\right]$ (7)
 > CoefficientList(0.,x);
 $\left[\right]$ (8)
 • Non-expanded polynomials will also work but since collect will be called on them, this could be inefficient.
 > q := (x-1)*(x-25)*(x^2-x):
 > CoefficientList( q, x );
 $\left[{0}{,}{-25}{,}{51}{,}{-27}{,}{1}\right]$ (9)
 • The coefficients of the polynomial do not have to be numbers.
 > CoefficientList(y^3-y^2*x+(y-2)*x^2+x^3,x);
 $\left[{{y}}^{{3}}{,}{-}{{y}}^{{2}}{,}{y}{-}{2}{,}{1}\right]$ (10)

 See Also