E.V.E
v2023.02.15

◆ reverse_horner

eve::reverse_horner = {}
inlineconstexpr

implement the horner scheme to evaluate polynomials with coefficients in increasing power order

If \((a_i)_{0\le i\le n-1}\) denotes the coefficients of the polynomial by increasing power order, the Reverse Horner scheme evaluates the polynom \(p\) at \(x\) using the following formula:

\(\displaystyle p(x) = (((a_{n-1}x+a_{n-2})x+ ... )x + a_0)\)

Defined in header

#include <eve/module/polynomial.hpp>

Callable Signatures

namespace eve
{
T reverse_horner(T x, C ... coefs) noexcept; //1
template< eve::floating_ordered_value T, eve::Range R>
T reverse_horner(T x, R r) noexcept; //2
}
Definition: value.hpp:114
constexpr callable_reverse_horner_ reverse_horner
implement the horner scheme to evaluate polynomials with coefficients in increasing power order
Definition: reverse_horner.hpp:83
Definition: abi.hpp:18
  1. Polynom is evaluated at x the other inputs are the polynomial coefficients.
  2. Polynom is evaluated at x the other input is a range containing the coefficients

Parameters

Return value

The value of the polynom at x is returned.

Notes

If the coefficients are simd values of cardinal N, this means you simultaneously compute the values of N polynomials.

  • If x is scalar, the polynomials are all computed at the same point
  • If x is SIMD, the nth polynomial is computed on the nth value of x

Example

#include <eve/module/polynomial.hpp>
#include <eve/wide.hpp>
#include <iostream>
#include <list>
#include <vector>
int main()
{
w_t xd = {-0.3, 0.5, 0.0, 2.0};
w_t x(0.5);
kumi::tuple<float, float, float, float> t{-4, 3, -2, 1};
kumi::tuple<w_t, w_t, w_t> wv { w_t{0.f, 1.f, 2.f, 3.f}, w_t{4.f, 5.f, 6.f, 7.f}, w_t{8.f, 9.f, 10.f, 11.f} };
std::cout << "---- simd" << '\n'
<< "<- xd = " << xd << '\n'
<< "<- x = " << x << '\n'
<< "<- t contains {-4, 3, -2, 1} "<< '\n'
<< "<- wv contains { {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11} }"<< '\n'
<< "-> reverse_horner(xd, 1, -2, 3, -4) = " << eve::reverse_horner(xd, 1, -2, 3, -4) << '\n'
<< "-> reverse_horner(x, 1, -2, 3, -4) = " << eve::reverse_horner(xd, 1, -2, 3, -4) << '\n'
<< "-> reverse_horner(xd, t) = " << eve::reverse_horner(xd, t) << '\n'
<< "-> reverse_horner(xd, wv) = " << eve::reverse_horner(xd, wv) << '\n'
;
double xs = 0.1;
std::cout << "---- scalar" << '\n'
<< "<- xs = " << xs << '\n'
<< "-> reverse_horner(xs, 1.5, 2.0, 4.0) = " << eve::reverse_horner(xs, 1.5, 2.0, 4.0) << '\n';
return 0;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • eve::pedantic, eve::numeric

    If d denotes one of these modifiers, the expression d(eve::reverse_horner)(...) computes the result using d(eve::fma) instead of eve::fma in internal computation.

    This is intended to insure more accurate computations where needed. This has no cost if the system has hard wired fma but is very expansive if it is not the case.