Previous Page Next Page Contents

nthmonomial -- the n-th monomial of a polynomial

Introduction

nthmonomial(p, n) returns the n-th non-trivial monomial of the polynomial p.

Call(s)

nthmonomial(p, <vars,> n <, order>)

Parameters

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: LexOrder, or DegreeOrder, or DegInvLexOrder, or a user-defined term ordering of type Dom::MonomOrdering. The default is the lexicographical ordering LexOrder.

Returns

a 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.

Overloadable:

p

Related Functions

coeff, degree, degreevec, ground, lcoeff, ldegree, lmonomial, lterm, nterms, nthcoeff, nthterm, poly, poly2list, tcoeff

Details

Example 1

We 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 2

We 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 3

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]):
   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 4

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]):
   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 5

We 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:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000