Previous Page Next Page Contents

coeff -- the coefficients of a polynomial

Introduction

coeff(p) returns a sequence of all nonzero coefficients of the polynomial p.

coeff(p, x, n) regards p as a univariate polynomial in x and returns the coefficient of the term x^n.

Call(s)

coeff(p)
coeff(p, <x,> n)
coeff(f <, vars>)
coeff(f, <vars,> <x,> n)

Parameters

p - a polynomial of type DOM_POLY
x - an indeterminate
n - the power: a nonnegative integer
f - a polynomial expression
vars - a list of indeterminates of the polynomial: typically, identifiers or indexed identifiers

Returns

one or more coefficients of the coefficient ring of the polynomial, or a polynomial, or FAIL.

Overloadable:

p, f

Related Functions

collect, content, degree, degreevec, ground, icontent, lcoeff, ldegree, lmonomial, lterm, nterms, nthcoeff, nthmonomial, nthterm, poly, poly2list, tcoeff

Details

Example 1

coeff(f) returns a sequence of all nonzero coefficients:

>> f := 10*x^10 + 5*x^5 + 2*x^2: coeff(f)
                                 10, 5, 2

coeff(f, i) returns a single coefficient:

>> coeff(f, i) $ i = 0..15
              0, 0, 2, 0, 0, 5, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0
>> delete f:

Example 2

We demonstrate how the indeterminates influence the result:

>> f := 3*x^3 + x^2*y^2 + 17*x + 23*y + 2
                                       3    2  2
                      17 x + 23 y + 3 x  + x  y  + 2
>> coeff(f); coeff(f, [x, y]); coeff(f, [y, x])
                              1, 23, 3, 17, 2
      
                              3, 1, 17, 23, 2
      
                              1, 23, 3, 17, 2
>> delete f:

Example 3

The coefficients of f are selected with respect to the main variable x which is the first entry of the list of indeterminates:

>> f := 3*x^3 + x^2*y^2 + 2: coeff(f, [x, y], i) $ i = 0..3
                                       2
                                2, 0, y , 3

The coefficients of f can be selected with respect to another main variable (in this case, y):

>> coeff(f, [y, x], i) $ i = 0..2
                                 3          2
                              3 x  + 2, 0, x

Alternatively:

>> coeff(f, y, i) $ i = 0..2
                                 3          2
                              3 x  + 2, 0, x
>> delete f:

Example 4

In the same way, coeff may be applied to polynomials of type DOM_POLY:

>> p := poly(3*x^3 + x, [x], Dom::IntegerMod(7)):
   coeff(p)
                             3 mod 7, 1 mod 7
>> coeff(p, i) $ i = 0..3
                    0 mod 7, 1 mod 7, 0 mod 7, 3 mod 7

For multivariate polynomials, the coefficients with respect to an indeterminate are polynomials in the other indeterminates:

>> p := poly(3*x^3 + x^2*y^2 + 2, [x, y]): 
>> coeff(p, y, 0), coeff(p, y, 1), coeff(p, y, 2);
                     3                                2
             poly(3 x  + 2, [x]), poly(0, [x]), poly(x , [x])
>> coeff(p, x, 0), coeff(p, x, 1), coeff(p, x, 2)
                                                   2
                 poly(2, [y]), poly(0, [y]), poly(y , [y])

Note that the indeterminates passed to coeff will be used, even if the polynomial provides different indeterminates :

>> coeff(p, z, 0), coeff(p, z, 1), coeff(p, z, 2)
              3    2  2
      poly(3 x  + x  y  + 2, [x, y]), poly(0, [x, y]),
      
         poly(0, [x, y])
>> delete p:

Example 5

The result of coeff is not fully evaluated:

>> p := poly(27*x^2 + a*x, [x]): a := 5:
   coeff(p, x, 1), eval(coeff(p, x, 1))
                                   a, 5
>> delete p, a:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000