nthcoeff -- the n-th
non-zero coefficient of a polynomial
Introductionnthcoeff(p, n) returns the
n-th non-zero coefficient of the polynomial
p.
Call(s)nthcoeff(p, <vars,> n <, order>)
Parametersp |
- | a polynomial of type
DOM_POLY or a polynomial expression |
vars |
- | a list of indeterminates of the polynomial: typically, identifiers or indexed identifiers |
n |
- | a positive integer |
order |
- | the term ordering: either LexOrder
or DegreeOrder or DegInvLexOrder or a user-defined term ordering
of type Dom::MonomOrdering. The default
is the lexicographical ordering LexOrder. |
Returnsan element of the coefficient domain of the polynomial. An
expression is returned if a polynomial expression is used as input.
FAIL is returned if
n is larger than the actual number of terms.
p
Related
Functionscoeff, collect, degree, degreevec, ground, lcoeff, ldegree, lmonomial, lterm, nterms, nthmonomial, nthterm, poly, poly2list, tcoeff
Detailsp can either be a polynomial expression,
or a polynomial generated by poly, or an element of some polynomial
domain overloading nthcoeff.p is
regarded as a polynomial in these indeterminates. Note that the
specified list does not have to coincide with the indeterminates of the
input polynomial.lcoeff, the ``last''
coefficient is the trailing coefficient as returned by tcoeff.nthcoeff returned the n-th non-zero
coefficient with respect to the lexicographical ordering, unless a
different ordering is specified via the argument order.
Cf. example 3.nthcoeff is not fully evaluated.
Evaluation can be enforced by the function eval. Cf. example 4.nthcoeff returns
FAIL.nthcoeff is a library routine. If no term ordering is
specified, the arguments are passed to a fast kernel routine.
Example
1We give some self explaining examples:
>> p := poly(100*x^100 + 49*x^49 + 7*x^7, [x]): nthcoeff(p, 1), nthcoeff(p, 2), nthcoeff(p, 3)
100, 49, 7
>> nthcoeff(p, 4)
FAIL
>> nthcoeff(poly(0, [x]), 1)
FAIL
>> delete p:
Example
2We demonstrate how the indeterminates influence the result:
>> p := 2*x^2*y + 3*x*y^2 + 6: nthcoeff(p, [x, y], 2), nthcoeff(p, [y, x], 2)
3, 2
>> p := poly(2*x^2*y + 3*x*y^2 + 6, [x, y]): nthcoeff(p, 1), nthcoeff(p, [y, x], 1)
2, 3
>> delete p:
Example
3We demonstrate the effect of various term orders:
>> p := poly(5*x^4 + 4*x^3*y*z^2 + 3*x^2*y^3*z + 2, [x, y, z])
4 3 2 2 3
poly(5 x + 4 x y z + 3 x y z + 2, [x, y, z])
>> nthcoeff(p, 1), nthcoeff(p, 1, DegreeOrder), nthcoeff(p, 1, DegInvLexOrder)
5, 4, 3
The following call uses the reverse lexicographical order on 3 indeterminates:
>> nthcoeff(p, 1, Dom::MonomOrdering(RevLex(3)))
3
>> delete p:
Example
4We demonstrate the evaluation strategy of
nthcoeff:
>> p := poly(3*x^3 + 6*x^2*y^2 + 2, [x]): y := 4: nthcoeff(p, 2)
2
6 y
Evaluation is enforced by eval:
>> eval(%)
96
>> delete p, y:
DOM_POLY as
well.nthcoeff was a
kernel function.