E.V.E
v2022.03.00

◆ newton

eve::newton = {}
inlineconstexpr

Implement the Newton scheme to evaluate polynomials.

If \((a_i)_{0\le i\le n-1}\) denotes the coefficients of the polynomial by decreasing power order, and \((c_i)_{0\le i\le n-2}\) the nodes, the Newton scheme evaluates the polynom \(p\) at \(x\) using the following formula :

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

Defined in header

#include <eve/module/polynomial.hpp>

Callable Signatures

namespace eve
{
template< eve::floating_real_value T, eve::Range C, eve::Range N>
T newton(T x, C c, N n) noexcept;
}
constexpr callable_newton_ newton
Implement the Newton scheme to evaluate polynomials.
Definition: newton.hpp:77
Definition: all_of.hpp:22

Parameters

  • x : real floating argument.
  • r : range containing The coefficients by decreasing power order.
  • n : range containing The nodes by decreasing power order.

Return value

The value of the polynom at x is returned.

Notes

If the coefficients or nodes 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()
{
wide_ft xd = {-0.3, 0.5, 0.0, 2.0};
std::vector<float> v {1, -2, 3, -4};
std::list<float> l {1, -2, 3, -4};
std::vector<float> n {1, 2, 6};
std::cout << "---- simd" << '\n'
<< "<- xd = " << xd << '\n'
<< "<- l and v contain {1, -2, 3, -4} "<< '\n'
<< "<- n contains { 1, 2, 6} "<< '\n'
<< "-> newton(xd, l, n) = " << eve::newton(xd, l, n) << '\n'
<< "-> newton(xd, v, n) = " << eve::newton(xd, v, n) << '\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::newton)(...) 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.