1 #ifndef GINAC_EVAL_UPOLY_TCC
2 #define GINAC_EVAL_UPOLY_TCC
4 #include "ring_traits.hpp"
9 /// Evaluate the polynomial using Horner rule.
11 /// - a better algorithm for small polynomials (use SIMD instructions)
12 /// - a better algorithm for large polynomials (use Karatsuba trick)
13 /// - a better algorithm for modular polynomials (especially for small
15 template<typename T> static typename T::value_type
16 eval(const T& p, const typename T::value_type& x)
18 // p(x) = c_n x^n + c_{n-1} x^{n-1} + \ldots + c_0 =
19 // c_0 + x (c_1 + x (c_2 + x ( \ldots (c_{n-1} + c_n x) \ldots )))
21 typedef typename T::value_type ring_t;
28 // read the formula above from the right to the left
29 for (std::size_t i = p.size() - 1; i-- != 0; )
37 #endif // GINAC_EVAL_UPOLY_TCC