nthmonomial -- the
n-th monomial of a polynomial
Introductionnthmonomial(p, n) returns the
n-th non-trivial monomial of the polynomial
p.
Call(s)nthmonomial(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: LexOrder,
or DegreeOrder, or DegInvLexOrder, or a user-defined term ordering
of type Dom::MonomOrdering. The default
is the lexicographical ordering LexOrder. |
Returnsa polynomial of the same type as p. An expression is
returned if p is an expression. FAIL is returned if n is
larger than the actual number of terms of the polynomial.
p
Related
Functionscoeff, degree, degreevec, ground, lcoeff, ldegree, lmonomial, lterm, nterms, nthcoeff, 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 nthmonomial.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.lmonomial.nthmonomial returned the n-th non-trivial
monomial with respect to the lexicographical ordering, unless a
different ordering is specified via the argument order.
Cf. example 3.nthmonomial is not fully evaluated. It
can be evaluated by the functions mapcoeffs and eval. Cf. example 5.nthmonomial returns
FAIL.nthmonomial 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]): nthmonomial(p, 1), nthmonomial(p, 2), nthmonomial(p, 3)
100 49 7
poly(100 x , [x]), poly(49 x , [x]), poly(7 x , [x])
>> nthmonomial(p, 4)
FAIL
>> nthmonomial(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: nthmonomial(p, [x, y], 2), nthmonomial(p, [y, x], 2)
2 2
3 x y , 2 x y
>> p := poly(2*x^2*y + 3*x*y^2 + 6, [x, y]): nthmonomial(p, 2), nthmonomial(p, [y, x], 2)
2 2
poly(3 x y , [x, y]), poly(2 y x , [y, x])
>> 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]): nthmonomial(p, 1), nthmonomial(p, 1, DegreeOrder), nthmonomial(p, 1, DegInvLexOrder)
4 3 2
poly(5 x , [x, y, z]), poly(4 x y z , [x, y, z]),
2 3
poly(3 x y z, [x, y, z])
>> delete p:
Example
4This 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]): nthmonomial(p, 2, order)
3 2
poly(4 x y z , [x, y, z])
The following call produces all monomials:
>> nthmonomial(p, i, order) $ i = 1..nterms(p)
2 3 3 2
poly(3 x y z, [x, y, z]), poly(4 x y z , [x, y, z]),
4
poly(5 x , [x, y, z]), poly(2, [x, y, z])
>> delete order, p:
Example
5We demonstrate the evaluation strategy of
nthmonomial:
>> p := poly(3*x^3 + 6*x^2*y^2 + 2, [x]): y := 4: nthmonomial(p, 2)
2 2
poly((6 y ) x , [x])
Evaluation is enforced by eval:
>> mapcoeffs(%, eval)
2
poly(96 x , [x])
>> delete p, y:
DOM_POLY as
well.nthmonomial was a
kernel function.