## `evalp` -- evaluate a polynomial at a point

#### Introduction

`evalp(`p, x = v`)` evaluates the polynomial `p` in the variable `x` at the point `v`.

#### Call(s)

`evalp(p, x = v...)`
`evalp(f, <vars,> x = v...)`

#### Parameters

`p` | - | a polynomial of type `DOM_POLY`
`x` | - | an indeterminate
`v` | - | the value for `x`: an element of the coefficient ring of the polynomial
`f` | - | a polynomial expression
`vars` | - | a list of indeterminates of the polynomial: typically, identifiers or indexed identifiers

#### Returns

an element of the coefficient ring, or a polynomial, or a polynomial expression, or `FAIL`

### Overloadable:

`p`, `f`

#### Related Functions

`eval`, `poly`

#### Details

- `evalp(`p, x = v`)` evaluates the polynomial `p` in the variable `x` at the point `v`. An error occurs if `x` is not an indeterminate of `p`. The value `v` may be any object that could also be used as coefficient. The result is an element of the coefficient ring of `p` if `p` is univariate. If `p` is multivariate, the result is a polynomial in the remaining variables.
- If several evaluation points are given, the evaluations take place in succession from left to right. Each evaluation follows the rules above.
- For a polynomial `p` in the variables `x1,x2,...`, the syntax `p(v1,v2,...)` can be used instead of `evalp(p,x1=v1,x2=v2,...)`.
- `evalp(`f, vars, x = v...`)` first converts the polynomial expression `f` to a polynomial with the variables given by `vars`. If no variables are given, they are searched for in `f`. See `poly` about details of the conversion. `FAIL` is returned if `f` cannot be converted to a polynomial. A successfully converted polynomial is evaluated as above. The result is converted to an expression.
- Horner's rule is used to evaluate the polynomial. The evaluation of variables at the point `0` is most efficient and should take place first. After that, the remaining main variable should be evaluated first.
- The result of `evalp` is not evaluated further. One may use `eval` to fully evaluate the result.
- `evalp` is a function of the system kernel.

#### Example 1

`evalp` is used to evaluate the polynomial expression x2 + 2x + 3 at the point x=a+2. The form of the resulting expression reflects the fact that Horner's rule was used:

    >> evalp(x^2 + 2*x + 3, x = a + 2)

                                (a + 2) (a + 4) + 3

#### Example 2

`evalp` is used to evaluate a polynomial in the indeterminates x and y at the point x=3. The result is a polynomial in the remaining indeterminate y:

    >> p := poly(x^2 + x*y + 2, [x, y]): evalp(p, x = 3)

                                poly(3 y + 11, [y])

    >> delete p:

#### Example 3

Polynomials may be called like functions in order to evaluate all variables:

    >> p := poly(x^2 + x*y, [x, y]): evalp(p, x = 3, y = 2) = p(3, 2)

                                      15 = 15

    >> delete p:

#### Example 4

If not all variables are replaced by values, the result is a polynomial in the remaining variables:

    >> evalp(poly(x*y*z + x^2 + y^2 + z^2, [x, y, z]), x = 1, y = 1)

                                     2
                               poly(z  + z + 2, [z])

#### Example 5

The result of `evalp` is not evaluated further. We first define a polynomial `p` with coefficient `a` and then change the value of `a`. The change is not reflected by `p`, because polynomials do not evaluate their coefficients implicitly. One must map the function `eval` onto the coefficients in order to enforce evaluation:

    >> p := poly(x^2 + a*y + 1, [x,y]): a := 2:
       p, mapcoeffs(p, eval)

                    2                           2
              poly(x  + a y + 1, [x, y]), poly(x  + 2 y + 1, [x, y])

If we use `evalp` to evaluate `p` at the point x=1, the result is not fully evaluated. One must use `eval` to get fully evaluated coefficients:

    >> r := evalp(p, x = 1):
       r, mapcoeffs(r, eval)

                      poly(a y + 2, [y]), poly(2 y + 2, [y])

    >> delete p, a, r:

#### Changes

- no changes

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