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

◆ horner

auto eve::horner = functor<horner_t>
inlineconstexpr

If \((c_i)_{0\le i\le n-1}\) denotes the coefficients of the polynomial by decreasing power order, the Horner scheme evaluates the polynom \(p\) at \(x\) by :

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

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto horner(floating_value auto x, value auto ...ci) noexcept; // 1
constexpr auto horner(floating_value auto x, kumi::non_empty_product_type auto tci) noexcept; // 2
// Lanes masking
constexpr auto horner[conditional_expr auto c](*any of the above overloads*/) noexcept; // 3
constexpr auto horner[logical_value auto m](*any of the above overloads*/) noexcept; // 3
// Semantic options
constexpr auto horner[pedantic](/*any of the above overloads*/) noexcept; // 4
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
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 logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:132
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 callable_any_ any
Computes a bool value which is true if and only if any elements of x is not zero.
Definition any.hpp:56
constexpr auto horner
Implement the horner scheme to evaluate polynomials with coefficients in decreasing power order.
Definition horner.hpp:104
EVE Main Namespace.
Definition abi.hpp:18

Parameters

Return value

If \((c_i)_{0\le i\le n-1}\) denotes the coefficients of the polynomial by decreasing power order, the Horner scheme evaluates the polynom \(p\) at \(x\) by : \(\qquad\qquad\displaystyle p(x) = (((c_0x+c_1)x+ ... )x + c_{n-1})\)

  1. The value of the polynom at x is returned.
  2. Same as the call with the elements of the tuple.
  3. The operation is performed conditionnaly.
  4. fma[pedantic] instead of fma is used in internal computations.
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 TODO
#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 << "-> horner(xd, 1.0, -2.0, 3.0, -4.0) = " << eve::horner(xd, 1.0, -2.0, 3.0, -4.0) << '\n';
std::cout << "-> horner(0.5, 1, b, 3, -4) = " << eve::horner(0.5, 1, b, 3, -4) << '\n';
std::cout << "-> horner(x, 1, -2, 3, -4) = " << eve::horner(xd, 1, -2, 3, -4) << '\n';
std::cout << "-> horner(xd, v) = " << eve::horner(xd, v) << '\n';
std::cout << "-> horner(xd, t) = " << eve::horner(xd, t) << '\n';
std::cout << "-> horner(x, t) = " << eve::horner(x, t) << '\n';
std::cout << "-> horner(x, wv) = " << eve::horner(x, wv) << '\n';
std::cout << "-> horner(0.5f, wv) = " << eve::horner(0.5, wv) << '\n';
std::cout << "-> horner(xd, wv) = " << eve::horner(xd, wv) << '\n';
std::cout << "-> horner(1.0, t) = " << eve::horner(1.0, t) << '\n';
}
Wrapper for SIMD registers.
Definition wide.hpp:70