## `nthterm` -- the n-th term of a polynomial

#### Introduction

`nthterm(`p, n`)` returns the `n`-th non-zero term of the polynomial `p`.

#### Call(s)

`nthterm(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: either `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 a polynomial expression is used as input. `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`, `nthmonomial`, `poly`, `poly2list`, `tcoeff`

#### Details

- The argument `p` can either be a polynomial expression, or a polynomial generated by `poly`, or an element of some polynomial domain overloading `nthterm`.
- The identity nthterm(p, n) * nthcoeff(p, n) = nthmonomial(p, n) holds.
- If a list of indeterminates is provided, then `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.
- The ``first'' term is the leading term as returned by `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.
- A zero polynomial has no terms: `nthterm` returns `FAIL`.
- `nthterm` is a library routine. If no term ordering is specified, the arguments are passed to a fast kernel routine.

#### Example 1

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:

#### Example 2

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:

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

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

#### Example 5

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:

#### Changes

- Now it is possible to specify user defined term orderings.
- Indeterminates can now be specified for polynomials of type `DOM_POLY` as well.
- In previous MuPAD releases `nthterm` was a kernel function.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000