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

◆ newton

auto eve::newton = functor<newton_t>
inlineconstexpr

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

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

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto newton(floating_value auto x, floating_value auto ... cmi) noexcept; // 1
constexpr auto newton(floating_value auto x, kumi::non_empty_product_type auto ci
kumi::non_empty_product_type auto mi) noexcept; // 2
// Lanes masking
constexpr auto newton[conditional_expr auto c](*any of the above overloads*/) noexcept; // 3
constexpr auto newton[logical_value auto m](*any of the above overloads*/) noexcept; // 3
// Semantic options
constexpr auto newton[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
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 newton
Implement the Newton scheme to evaluate polynomials.
Definition newton.hpp:101
EVE Main Namespace.
Definition abi.hpp:18

Parameters

  • x: real floating argument.
  • ci: tuple containing the coefficients by decreasing power order.
  • cm: tuple containing the nodes by decreasing power order.
  • cmi...: all the coefficients followed by all the nodes, both in decreasing power order. The total number of values is to be odd. If s is this number, the (s+1)/2 first are taken as the coefs and the others are the nodes. Note that the values of the cmi are not necessarily floating but the non floating ones are to be scalar
  • c: Conditional expression masking the operation.
  • m: Logical value masking the operation.

Return value

  1. The value of the polynom at x is returned.
  2. same as the call with the elements of the tuples.
  3. The operation is performed conditionnaly.
  4. fma[pedantic] instead of fma is used in internal computations.
Note
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

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide<float> wf([](auto i, auto c){ return (1+eve::eps(eve::as<float>()))*(i-c/2);});
kumi::tuple wtc{wf,2*wf,3*wf};
kumi::tuple wtn{4*wf, 5*wf};
std::cout << std::setprecision(10);
std::cout << "<- wf = " << wf << "\n";
std::cout << "<- wtc = " << wtc << "\n";
std::cout << "<- wtn = " << wtn << "\n";
std::cout << "-> newton(wf,wf,2*wf,3*wf,4*wf,5*wf) = " << eve::newton(wf,wf,2*wf,3*wf,4*wf,5*wf) << "\n";
std::cout << "-> newton(wf,wtc,wtn) = " << eve::newton(wf, wtc,wtn) << "\n";
std::cout << "-> newton[pedantic](wf,wf,2*wf,3*wf,4*wf, 5*wf)= " << eve::newton[eve::pedantic](wf,wf,2*wf,3*wf,4*wf, 5*wf) << "\n";
}
constexpr auto eps
Computes a constant to the machine epsilon.
Definition eps.hpp:73
Lightweight type-wrapper.
Definition as.hpp:29
Wrapper for SIMD registers.
Definition wide.hpp:70