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

◆ horner

kyosu::horner = eve::functor<horner_t>
inlineconstexpr

Implement the 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 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-horner scheme: coefficients are at the left of the x powers.

using the right semantic modifyier allows to use a right-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 horner(T x, C ... coefs) noexcept; //1
template< auto C, auto K> auto horner(T x, K tup) noexcept; //2
Semantic modifyiers
template<auto T, auto C ...> auto horner[left](T x, C ... coefs) noexcept; //1
template<auto C, auto K> auto horner[left]r(T x, K tup) noexcept; //2
template<auto T, auto C ...> auto horner[right](T x, C ... coefs) noexcept; //3
template<auto C, auto K> auto horner[right]r(T x, K tup) noexcept; //3
}
constexpr auto horner
Implement the horner scheme to evaluate polynomials.
Definition: horner.hpp:118

! Parameters

 * `x` :  real or cayley-dickson argument.
 * `coefs...` :  real or cayley-dickson arguments. The coefficients by decreasing 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_0x+a_1)x+ ... )x + a_{n-1})\).
    For non commutative cases it is a left-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_0+a_1)+ ... )+a_{n-1})\).
    Of course for real or complex entries left and right leads to the same result

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 << "horner(a[0],a[1],a[2],a[3], a[4]) " << kyosu::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 << "horner(x, q1, q2, q3) " << kyosu::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 << "horner(x, q1, c2, a[2]) " << kyosu::horner(x, q1, c2, a[12]) << std::endl;
std::cout << "horner(x, c1, c2, c3) " << kyosu::horner(x, c1, c2, c3) << std::endl;
std::cout << "horner(x1, c1, c2, c3) " << kyosu::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 << "horner(x, o1, c2, a[2]) " << kyosu::horner(x, o1, c2, a[2]) << std::endl;
std::cout << "horner(x, o1, o2, o3) " << kyosu::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