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

◆ reverse_horner

kyosu::reverse_horner = eve::functor<reverse_horner_t>
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 increasing power order, the reverse Horner scheme evaluates the polynom \(p\) at \(x\) by : \(\displaystyle p(x) = (((a_{n-1}x+a_{n-2})x+ ... )x + a_0)\).
For non commutative cases it is a left-reverse_horner scheme: coefficients are at the left of the x powers.

using the right semantic modifyier allows to use a right-reverse Horner scheme: coefficients are at the right of the x powers).

Header file

#include <kyosu/functions.hpp>

Callable Signatures

namespace eve
{
template< auto T, auto C ...> auto reverse_horner(T x, C ... coefs) noexcept; //1
template< auto C, auto K> auto reverse_horner(T x, K tup) noexcept; //2
Semantic modifyiers
template<auto T, auto C ...> auto reverse_horner[left](T x, C ... coefs) noexcept; //1
template<auto C, auto K> auto reverse_horner[left]r(T x, K tup) noexcept; //2
template<auto T, auto C ...> auto reverse_horner[right](T x, C ... coefs) noexcept; //3
template<auto C, auto K> auto reverse_horner[right]r(T x, K tup) noexcept; //3
}
constexpr auto reverse_horner
Implement the reverse_horner scheme to evaluate polynomials.
Definition: reverse_horner.hpp:122

! Parameters

 * `x` :  real or cayley-dickson argument.

 * `coefs...` :  real or cayley-dickson arguments. The coefficients by increasing power order

 * `tup` : kumi tuple containing The coefficients by decreasing power order.

Return value

  1. Polynom is evaluated at x the other inputs are the polynomial coefficients. 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 left-reverse_horner scheme.
  2. Polynom is evaluated at x the other input is a kumi tuple containing the coefficients
  3. the right modifyier is useful only when dealing wirh cayley-dickson non commutative algebras.
    The value of the polynom at x is returned, according to the formula: \(\displaystyle p(x) = (x (x (x a_{n-1}+a_{n-2})+ ... )+a_0)\).
    Of course for real or complex entries left and right have no specific actions

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

External references

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, c2, a[2]) " << kyosu::reverse_horner(x, o1, c2, a[2]) << std::endl;
std::cout << "reverse_horner(x, o1, o2, o3) " << kyosu::reverse_horner(x, o1, o2, o3) << std::endl;
};
constexpr auto complex
Constructs a kyosu::complex_t instance.
Definition: to_complex.hpp:75
constexpr auto quaternion
Constructs a kyosu::quaternion_t instance.
Definition: to_quaternion.hpp:83
Cayley-Dickson algebra main abstraction It is built so that all operation over C, Q and other such al...
Definition: cayley_dickson.hpp:32