kyosu v0.1.0
Complex Without Complexes
 
Loading...
Searching...
No Matches

◆ right_horner

kyosu::right_horner = {}
inlineconstexpr

Implement the right_horner scheme to evaluate polynomials.

If \((a_i)_{0\le i\le n-1}\) denotes the coefficients of the polynomial by decreasing power order, the Right_Horner scheme evaluates the polynom \(p\) at \(x\) by : \(\displaystyle p(x) = (a_{n-1}+x(...+x (a_1+ x a_0)) ))\).
For non commutative cases it is a right_horner scheme (the coefficients are at the right of the x powers).

Defined in header

#include <eve/module/polynomial.hpp>

Callable Signatures

namespace eve
{
template<auto T, auto C ...> auto right_horner(T x, C ... coefs) noexcept; //1
template< auto C, eve::Range R> auto right_horner(T x, R r) noexcept; //2
}
constexpr tags::callable_right_horner right_horner
Implement the right_horner scheme to evaluate polynomials.
Definition: right_horner.hpp:110
  1. Polynom is evaluated at x the other inputs are the polynomial coefficients.
  2. Polynom is evaluated at x the other input is a range containing the coefficients

Parameters

  • x : real or cayley-dickson argument.
  • coefs... : real or cayley-dickson arguments. The coefficients by decreasing power order
  • r : Range containing The coefficients by decreasing power order.

Return value

The value of the polynom at x is returned, according to the formula: \(\displaystyle p(x) = (a_{n-1}+x(...+x (a_1+ x a_0)) ))\).
For non commutative cases it is a rigt-right_horner scheme. See horner for the left scheme

Notes

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

Example

#include <kyosu/kyosu.hpp>
#include <eve/wide.hpp>
#include <iostream>
#include <array>
int main()
{
std::array<double, 16> a{1, 2, 3, 4, 5, 6, 7, 8, 11, 21, 31, 41, 51, 61, 71, 81};
std::cout << "right_horner(a[0],a[1],a[2],a[3], a[4]) " << kyosu::right_horner(a[0],a[1],a[2],a[3], a[4]) << std::endl;
auto x = kyosu::quaternion(a[0],a[1],a[2],a[3]);
auto q1= kyosu::quaternion(a[4],a[5],a[6],a[7]);
auto q2= kyosu::quaternion(a[8],a[9],a[10],a[11]);
auto q3= kyosu::quaternion(a[12],a[13],a[14],a[15]);
std::cout << "right_horner(x, q1, q2, q3) " << kyosu::right_horner(x, q1, q2, q3) << std::endl;
auto x1= kyosu::complex(a[1],a[6]);
auto c1= kyosu::complex(a[4],a[3]);
auto c2= kyosu::complex(a[8],a[9]);
auto c3= kyosu::complex(a[1],a[2]);
std::cout << "right_horner(x1, q1, c2, a[2]) " << kyosu::right_horner(x1, q1, c2, a[12]) << std::endl;
// auto z = kyosu::right_horner(x1, c1, c2, c3);
// std::cout << z << std::endl;
std::cout << "right_horner(x, c1, c2, c3) " << kyosu::right_horner(x, c1, c2, c3) << std::endl;
std::cout << "right_horner(x1, c1, c2, c3) " << kyosu::right_horner(x1, c1, c2, c3) << std::endl;
auto o1= kyosu::cayley_dickson(a[4],a[5],a[6],a[7], a[8],a[9],a[10],a[11]);
auto o2= kyosu::cayley_dickson(a[0],a[1],a[2],a[3], a[8],a[9],a[10],a[11]);
auto o3= kyosu::cayley_dickson(a[12],a[13],a[14],a[15],a[4],a[5],a[6],a[7]);
std::cout << "right_horner(x, o1, o2, o3 ) " << kyosu::right_horner(x, o1, o2, o3 ) << std::endl;
std::cout << "right_horner(x, o1, c2, a[2]) " << kyosu::right_horner(x, o1, c2, a[12]) << std::endl;
};
constexpr tags::callable_complex complex
Constructs a kyosu::complex.
Definition: to_complex.hpp:70
constexpr tags::callable_quaternion quaternion
Constructs a kyosu::quaternion.
Definition: to_quaternion.hpp:72