E.V.E  0.1-beta

◆ newton

constexpr callable_newton_ eve::newton = {}
inlineconstexpr

Callable object computing the newton operation: \(\sum_{i = 0}^n c_i\prod_{j = 0}^i (x-n_i)\).

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

Members Functions

Member Effect
operator() the newton operation
operator[] Construct a conditional version of current function object

auto operator()(value auto x, range auto c, range auto n) const noexcept;
auto operator()(value x, std::inputiterator auto firstcoef, std::inputiterator auto sentinel, std::inputiterator auto firstnode) const noexcept;
Definition: value.hpp:31

Parameters

x: value x.

c, n`: values Range containing the coefficients

firstcoef, sentinel,firstnode: std::input_iterator conforming pair of iterators through the coefficients and start of the nodes

Return value

Returns elementwise the value of polynomial function(s) represented in newton form by the coefficients and the nodes.

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 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::newton

Parameters

cond : conditional expression

Return value

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


Supported decorators

  • eve::pedantic

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

    The expression pedantic(newton)(...) 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/newton.hpp>

    The expression numeric(newton)(...) 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/newton.hpp>
#include <eve/wide.hpp>
#include <iostream>
#include <list>
#include <vector>
int main()
{
wide_ft xd = {-0.3, 0.5, 0.0, 2.0};
wide_ft x(0.5);
std::vector<float> v {1, -2, 3, -4};
std::list<float> l {1, -2, 3, -4};
std::vector<float> n {1, 2, 6};
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'
<< "<- n contains { 1, 2, 6} "<< '\n'
<< "<- wv contains { {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11} }"<< '\n'
<< "-> newton(xd, l, n) = " << eve::newton(xd, l, n) << '\n'
<< "-> newton(xd, v, n) = " << eve::newton(xd, v, n) << '\n'
<< "-> newton(xd, &l[0], &v[4], &n[0]) = " << eve::newton(xd, &v[0], &v[4], &n[0]) << '\n'
<< "-> newton(xd, wv, n) = " << eve::newton(xd, wv, n) << '\n';
return 0;
}
constexpr callable_newton_ newton
Callable object computing the newton operation: .
Definition: newton.hpp:14
Wrapper for SIMD registers.
Definition: wide.hpp:65