E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ reverse_horner

auto eve::reverse_horner = functor<reverse_horner_t>
inlineconstexpr

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto reverse_horner(floating_value auto x, value auto ci...) noexcept; // 1
constexpr auto reverse_horner(floating_value auto x, kumi::non_empty_product_type auto tci) noexcept; // 2
// Semantic options
constexpr auto reverse_horner[pedantic](/*any of the above overloads*/) noexcept; // 3
}
The concept floating_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:116
The concept value<T> is satisfied if and only if T satisfies either eve::scalar_value or eve::simd_va...
Definition value.hpp:34
constexpr auto reverse_horner
implement the horner scheme to evaluate polynomials with coefficients in increasing power order
Definition reverse_horner.hpp:101
EVE Main Namespace.
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 or a kumi::tuple containing the coefficients

Parameters

Return value

If \((c_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:

\(\qquad\qquad\displaystyle p(x) = (((c_{n-1}x+c_{n-2})x+ ... )x + c_0)\)

  1. The value of the polynom at x is returned.
  2. same as the call with the elements of the tuple. 3.fma[pedantic] instead of fma is used in internal computations. This is intended to insure more accurate computations where needed. This has no cost (and is automatically done) if the system has hard wired fma but is very expansive if it is not the case.
Note
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

External references

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide xd = {-0.3, 0.5, 0.0, 2.0};
eve::wide b = {-2.0, 10.5, -4.0, 0.1};
double x(0.2);
kumi::tuple v {1.0, -2.0, 3.0, -4.0};
using w_t = decltype(xd);
kumi::tuple wv{ w_t{1.5, 1, 2, 3}, w_t{4, 5, 6, 7}, w_t{8, 9, 10, 11} };
auto t = kumi::tuple{1.5,4.0,8.0};
std::cout << "<- xd = " << xd << '\n';
std::cout << "<- x = " << x << '\n';
std::cout << "<- v = " << v << '\n';
std::cout << "<- wv = " << wv << '\n';
std::cout << "-> reverse_horner(xd, 1.0, -2.0, 3.0, -4.0) = " << eve::reverse_horner(xd, 1.0, -2.0, 3.0, -4.0) << '\n';
std::cout << "-> reverse_horner(0.5, 1, b, 3, -4) = " << eve::reverse_horner(0.5, 1, b, 3, -4) << '\n';
std::cout << "-> reverse_horner(x, 1, -2, 3, -4) = " << eve::reverse_horner(xd, 1, -2, 3, -4) << '\n';
std::cout << "-> reverse_horner(xd, v) = " << eve::reverse_horner(xd, v) << '\n';
std::cout << "-> reverse_horner(xd, t) = " << eve::reverse_horner(xd, t) << '\n';
std::cout << "-> reverse_horner(x, t) = " << eve::reverse_horner(x, t) << '\n';
std::cout << "-> reverse_horner(x, wv) = " << eve::reverse_horner(x, wv) << '\n';
std::cout << "-> reverse_horner(0.5f, wv) = " << eve::reverse_horner(0.5, wv) << '\n';
std::cout << "-> reverse_horner(xd, wv) = " << eve::reverse_horner(xd, wv) << '\n';
std::cout << "-> reverse_horner(1.0, t) = " << eve::reverse_horner(1.0, t) << '\n';
}
Wrapper for SIMD registers.
Definition wide.hpp:70