E.V.E  0.1-beta

◆ horner

eve::horner = {}
inlineconstexpr

Callable object computing the horner operation.

Required header: #include <eve/function/horner.hpp>

Members Functions

Member Effect
operator() evaluate a polynomial using the horner algorithm
operator[] Construct a conditional version of current function object

auto operator()(value auto x, value auto... args) const noexcept;
auto operator()(value auto x, range auto r) const noexcept;
auto operator()(value auto x, std::inputiterator auto first, std::inputiterator auto sentinel) const noexcept;
auto operator()(value auto x, callable_one_ const & o, value auto... args) const noexcept;
auto operator()(value auto x, callable_one_ const & o, range auto r) const noexcept;
auto operator()(value auto x, callable_one_ const & o, std::inputiterator auto first, std::inputiterator auto sentinel) const noexcept;
Definition: value.hpp:31

Parameters

x: value x.

o: callable_one_ . Put eve::one here to have an unitary polynomial and a small optimization

args: values expansion pack associated to \((a_i)_{i_0\le i \le n}\). \(i_0\) is 1 if o is present else 0

r: values Range containing the coefficients in the same conditions

first, sentinel: std::input_iterator conforming pair of iterators through the coefficients in the same conditions

Return value

Returns elementwise the value of polynomial function(s) represented by the coefficients in decreasing power order at x.

The result type is of the compatibility type of the coefficients and the evaluation value x.

Warning
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

auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::horner

Parameters

cond : conditional expression

Return value

A Callable object so that the expression horner[cond](x, ...) is equivalent to if_else(cond,horner(x, ...),x)


Supported decorators

  • eve::pedantic

    Required header: #include <eve/function/pedantic/horner.hpp>

    The expression pedantic(horner)(...) computes the result using pedantic(fma)(a,x,b) for a*x+b instead of fma(a,x,b).

  • eve::numeric

    Required header: #include <eve/function/numeric/horner.hpp>

    The expression numeric(horner)(...) computes the result using numeric(fma)(a,x,b) for a*x+b instead of fma(a,x,b).

Example

See it live on Compiler Explorer

#include <eve/function/horner.hpp>
#include <eve/wide.hpp>
#include <eve/constant/one.hpp>
#include <iostream>
#include <list>
#include <vector>
int main()
{
wide_ft xd = {-0.3, 0.5, 0.0, 2.0};
wide_ft b = {-2, 10.5, -4, 0.1};
wide_ft x(0.5);
std::vector<float> v {1, -2, 3, -4};
std::list<float> l {1, -2, 3, -4};
float ca[4] = {1, -2, 3, -4};
std::vector<wide_ft> wv { {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11} };
std::cout << "---- simd" << '\n'
<< "<- xd = " << xd << '\n'
<< "<- x = " << x << '\n'
<< "<- l and v contain {1, -2, 3, -4} "<< '\n'
<< "<- wv contains { {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11} }"<< '\n'
<< "-> horner(xd, 1, -2, 3, -4) = " << eve::horner(xd, 1, -2, 3, -4) << '\n'
<< "-> horner(xd, eve::one, -2, 3, -4)) = " << eve::horner(xd, eve::one, -2, 3, -4) << '\n'
<< "-> horner(0.5 1, b, 3, -4) = " << eve::horner(0.5, 1, b, 3, -4) << '\n'
<< "-> horner(x, 1, -2, 3, -4) = " << eve::horner(xd, 1, -2, 3, -4) << '\n'
<< "-> horner(xd, l) = " << eve::horner(xd, l) << '\n'
<< "-> horner(xd, v) = " << eve::horner(xd, v) << '\n'
<< "-> horner(xd, eve::one, &v[1], &v[4]) = " << eve::horner(xd, eve::one, &v[1], &v[4]) << '\n'
<< "-> horner(xd, std::begin(ca), std::end(ca)) = " << eve::horner(xd, std::begin(ca), std::end(ca) ) << '\n'
<< "-> horner(xd, wv) = " << eve::horner(xd, wv) << '\n'
;
double xs = 0.1;
std::cout << "---- scalar" << '\n'
<< "<- xs = " << xs << '\n'
<< "-> horner(xs, 1.5, 2.0, 4.0) = " << eve::horner(xs, 1.5, 2.0, 4.0) << '\n';
return 0;
}
constexpr callable_one_ one
Callable object computing the 1 value.
Definition: one.hpp:50
constexpr callable_horner_ horner
Callable object computing the horner operation.
Definition: horner.hpp:107
Wrapper for SIMD registers.
Definition: wide.hpp:65