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

◆ reverse_horner

kyosu::reverse_horner = {}
inlineconstexpr

Implement the reverse_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 Reverse_Horner scheme evaluates the polynom \(p\) at \(x\) by : \(\displaystyle p(x) = (((a_0x+a_1)x+ ... )x + a_{n-1})\).
For non commutative cases it is a left-reverse_horner scheme. The coefficients are at the left of the x powers.

Defined in header

#include <kyosu/kyosu.hpp>

Callable Signatures

namespace eve
{
template<auto T, auto C ...> auto reverse_horner(T x, C ... coefs) noexcept; //1
template< auto C, kumi::tuple T> auto reverse_horner(C x, T t) noexcept; //2
}
constexpr tags::callable_reverse_horner reverse_horner
Implement the reverse_horner scheme to evaluate polynomials.
Definition: reverse_horner.hpp:111
  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
  • t : kumi::tuple 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+a_{n-2})x+ ... )x + a_0)\).
For non commutative cases it is a rigt-reverse_horner scheme. See left_reverse_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 << "reverse_horner(a[0],a[1],a[2],a[3], a[4]) " << kyosu::reverse_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 << "reverse_horner(x, q1, q2, q3) " << kyosu::reverse_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 << "reverse_horner(x, q1, c2, a[2]) " << kyosu::reverse_horner(x, q1, c2, a[12]) << std::endl;
std::cout << "reverse_horner(x, c1, c2, c3) " << kyosu::reverse_horner(x, c1, c2, c3) << std::endl;
std::cout << "reverse_horner(x1, c1, c2, c3) " << kyosu::reverse_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 << "reverse_horner(x, o1, o2, o3) " << kyosu::reverse_horner(x, o1, o2, o3) << std::endl;
std::cout << "reverse_horner(x, o1, c2, a[2]) " << kyosu::reverse_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