Previous Page Next Page Contents

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

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




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000