nthterm
-- the n-th
term of a polynomialnthterm(
p, n)
returns the
n
-th non-zero term of the polynomial p
.
nthterm(p, <vars,> n <, order>)
p |
- | 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. |
a polynomial of the same type as p
. 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 of the polynomial.
p
coeff
, degree
, degreevec
, ground
, lcoeff
, ldegree
, lmonomial
, lterm
, nterms
, nthcoeff
, nthmonomial
, poly
, poly2list
, tcoeff
p
can either be a polynomial expression,
or a polynomial generated by poly
, or an element of some polynomial
domain overloading nthterm
.p
is
regarded as a polynomial in these indeterminates. The return value is a
polynomial in these indeterminates as well. Note that the specified
list does not have to coincide with the indeterminates of the input
polynomial.lterm
.nthterm
returned the n
-th non-zero term
with respect to the lexicographical ordering, unless a different
ordering is specified via the argument order
. Cf.
example 3.nthterm
returns
FAIL
.nthterm
is a library routine. If no term ordering is
specified, the arguments are passed to a fast kernel routine.We give some self explaining examples:
>> p := poly(100*x^100 + 49*x^49 + 7*x^7, [x]): nthterm(p, 1), nthterm(p, 2), nthterm(p, 3)
100 49 7 poly(x , [x]), poly(x , [x]), poly(x , [x])
>> nthterm(p, 4)
FAIL
>> nthterm(poly(0, [x]), 1)
FAIL
>> delete p:
We demonstrate how the indeterminates influence the result:
>> p := 2*x^2*y + 3*x*y^2 + 6: nthterm(p, [x, y], 2), nthterm(p, [y, x], 2)
2 2 x y , x y
>> p := poly(2*x^2*y + 3*x*y^2 + 6, [x, y]): nthterm(p, 2), nthterm(p, [y,x], 2)
2 2 poly(x y , [x, y]), poly(y x , [y, x])
>> delete p:
We 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]): nthterm(p, 1), nthterm(p, 1, DegreeOrder), nthterm(p, 1, DegInvLexOrder)
4 3 2 poly(x , [x, y, z]), poly(x y z , [x, y, z]), 2 3 poly(x y z, [x, y, z])
>> delete p:
This example features a user defined term ordering. Here we use the reverse lexicographical order on 3 indeterminates:
>> order := Dom::MonomOrdering(RevLex(3)): p := poly(5*x^4 + 4*x^3*y*z^2 + 3*x^2*y^3*z + 2, [x,y,z]): nthterm(p, 2, order)
3 2 poly(x y z , [x, y, z])
The following call produces all terms:
>> nthterm(p, i, order) $ i = 1..nterms(p)
2 3 3 2 poly(x y z, [x, y, z]), poly(x y z , [x, y, z]), 4 poly(x , [x, y, z]), poly(1, [x, y, z])
>> delete order, p:
The n-th monomial is the product of the n-th coefficient and the n-th term:
>> p := poly(2*x^2*y + 3*x*y^2 + 6, [x, y]): mapcoeffs(nthterm(p, 2), nthcoeff(p, 2)) = nthmonomial(p, 2)
2 2 poly(3 x y , [x, y]) = poly(3 x y , [x, y])
>> delete p:
DOM_POLY
as
well.nthterm
was a kernel
function.