coeff -- the coefficients of a
polynomial
Introductioncoeff(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)
Parametersp |
- | 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 |
Returnsone or more coefficients of the coefficient
ring of the polynomial, or a polynomial, or FAIL.
p, f
Related
Functionscollect, content, degree, degreevec, ground, icontent, lcoeff, ldegree, lmonomial, lterm, nterms, nthcoeff, nthmonomial, nthterm, poly, poly2list, tcoeff
Detailsf is not element of a polynomial
domain, then coeff converts the expression internally to a
polynomial of type DOM_POLY via poly(f). If a list of
indeterminates is specified, the polynomial poly(f, vars) is
considered.
Coefficients of polynomial expressions f are returned
as arithmetical expressions.
coeff with a polynomial
p of type DOM_POLY:
coeff(p) returns a sequence of all
nonzero coefficients of p. They are ordered according to
the lexicographical term ordering.
The returned coefficients are elements of the coefficient ring of
p.
coeff(p, x, n) regards p as
a univariate polynomial in the variable x and returns the
coefficient of the term x^n.
For univariate polynomials, the returned coefficients are elements
of the coefficient ring of p.
For multivariate polynomials, the coefficients are returned as
polynomials of type DOM_POLY in the ``remaining''
variables.
coeff(p, n) is equivalent to
coeff(p, x, n), where x is the
``main variable'' of p. This variable is the first element
of the list of indeterminates op(p, 2).coeff returns 0 or a zero polynomial if the
polynomial does not contain a term corresponding to the specified power
n. In particular, this happens if n is larger
than the degree of the polynomial.coeff returns FAIL if an expression
cannot be regarded as a polynomial.coeff is not fully evaluated. Evaluation
can be enforced by the function eval. Cf. example 5.coeff is a function of the system kernel.
Example
1coeff(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
2We 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
3The 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
4In 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
5The 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: