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

◆ horner

kyosu::horner = {}
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).

Defined in header

#include <eve/module/polynomial.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
}
constexpr tags::callable_horner horner
Implement the horner scheme to evaluate polynomials.
Definition: horner.hpp:109
  1. Polynom is evaluated at x the other inputs are the polynomial coefficients.
  2. Polynom is evaluated at x the other input is a kumi tuple containing the coefficients

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

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. See right_horner for the right 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 << "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 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