6#ifndef THEORETICA_POLYN_ORTHOGONAL_H 
    7#define THEORETICA_POLYN_ORTHOGONAL_H 
   10#include "../optimization/roots.h" 
   20        = std::function<polynomial<real>(polynomial<real>, polynomial<real>, 
unsigned int)>;
 
   42        for (
unsigned int l = 2; l <= n; ++l) {
 
 
   59        polynomial<real> P0, polynomial<real> P1, 
unsigned int l) {
 
   61        return ((2 * l - 1) * P1 * polynomial<real>({0, 1}) - (l - 1) * P0) / l;
 
 
   79        return sqrt((2 * n + 1) / 2.0);
 
 
   84    inline std::function<
real(
real)> assoc_legendre_polynomial(
unsigned int l, 
int m) {
 
   95        for (
int i = 0; i < m; ++i)
 
  102                return pow(1 - x * x, m / 2) * L(x) / K;
 
  108                return sqrt(
pow(1 - x * x, m)) * L(x) / K;
 
  115    inline polynomial<real> assoc_legendre_polynomial_even(
unsigned int l, 
int m) {
 
  118            TH_MATH_ERROR(
"assoc_legendre_polynomial_even", m, IMPOSSIBLE_OPERATION);
 
  128        polynomial<real> P = 
ipow(polynomial<real>({1, 0, -1}), m / 2);
 
  130        for (
int i = 0; i < m; ++i)
 
  142        polynomial<real> L0, polynomial<real> L1, 
unsigned int i) {
 
  144        return (polynomial<real>({2 * (
real) i - 1, -1}) * L1 - (i - 1) * L0) / i;
 
 
  163        polynomial<real> L0, polynomial<real> L1, 
real alpha, 
unsigned int i) {
 
  165        return (polynomial<real>({2 * (
real) i + alpha - 1, -1}) * L1 - (i + alpha - 1) * L0) / i;
 
 
  176            {1}, {1 + alpha, -1},
 
  177            [alpha](polynomial<real> L0, polynomial<real> L1, 
unsigned int i) {
 
 
  188        polynomial<real> H0, polynomial<real> H1, 
unsigned int i) {
 
  190        return polynomial<real>({0, 2}) * H1 - 2 * (i - 1) * H0;
 
 
  218        polynomial<real> T0, polynomial<real> T1, 
unsigned int i) {
 
  220        return polynomial<real>({0, 2}) * T1 - T0;
 
 
  258        std::vector<real> 
roots;
 
  261        for (
unsigned int i = 1; i <= n; ++i) {
 
 
  276        const unsigned int n = 
roots.size();
 
  279        std::vector<real> weights;
 
  282        for (
unsigned int i = 0; i < n; ++i) {
 
 
  297        const unsigned int n = 
roots.size();
 
  300        std::vector<real> weights;
 
  303        for (
unsigned int i = 0; i < n; ++i) {
 
 
  318        const unsigned int n = 
roots.size();
 
  321        std::vector<real> weights;
 
  324        for (
unsigned int i = 0; i < n; ++i) {
 
 
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compiling opti...
Definition error.h:225
 
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
 
std::vector< real > hermite_weights(const std::vector< real > &roots)
Hermite weights for Gauss-Hermite quadrature of n-th order.
Definition orthogonal.h:316
 
double real
A real number, defined as a floating point type.
Definition constants.h:198
 
polynomial< real > chebyshev1_polynomial(unsigned int n)
Compute the nth Chebyshev polynomial of the first kind.
Definition orthogonal.h:226
 
polynomial< real > laguerre_polyn_recurr(polynomial< real > L0, polynomial< real > L1, unsigned int i)
Recursion formula for Laguerre polynomials.
Definition orthogonal.h:141
 
real root_newton(RealFunction f, RealFunction Df, real guess=0.0, real tol=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_NEWTON_ITER)
Find a root of a univariate real function using Newton's method.
Definition roots.h:217
 
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition dual2_functions.h:54
 
polynomial< real > hermite_polyn_recurr(polynomial< real > H0, polynomial< real > H1, unsigned int i)
Recursion formula for Hermite polynomials.
Definition orthogonal.h:187
 
polynomial< real > chebyshev2_polynomial(unsigned int n)
Compute the nth Chebyshev polynomial of the second kind.
Definition orthogonal.h:237
 
constexpr real SQRTPI
The square root of Pi.
Definition constants.h:234
 
std::vector< real > legendre_weights(const std::vector< real > &roots)
Legendre weights for Gauss-Legendre quadrature of n-th order.
Definition orthogonal.h:274
 
std::vector< real > laguerre_weights(const std::vector< real > &roots)
Laguerre weights for Gauss-Laguerre quadrature of n-th order.
Definition orthogonal.h:295
 
TH_CONSTEXPR T ipow(T x, unsigned int n, T neutral_element=T(1))
Compute the n-th positive power of x (where n is natural)
Definition real_analysis.h:643
 
polynomial< real > gen_polyn_recurr(polynomial< real > P0, polynomial< real > P1, polyn_recurr_formula f, unsigned int n)
Generate a polynomial basis using a recursion formula.
Definition orthogonal.h:29
 
std::vector< real > roots(RealFunction f, real a, real b, real tol=OPTIMIZATION_TOL, real steps=10)
Find the roots of a univariate real function inside a given interval, by first searching for candidat...
Definition roots.h:650
 
real hermite_polyn_normalization(unsigned int n)
Normalization constant for the nth Hermite polynomial.
Definition orthogonal.h:206
 
TH_CONSTEXPR IntType fact(unsigned int n)
Compute the factorial of n.
Definition real_analysis.h:670
 
polynomial< real > general_laguerre_polyn_recurr(polynomial< real > L0, polynomial< real > L1, real alpha, unsigned int i)
Recursion formula for Generalized Laguerre polynomials.
Definition orthogonal.h:162
 
polynomial< real > general_laguerre_polynomial(real alpha, unsigned int n)
Compute the nth Laguerre polynomial.
Definition orthogonal.h:170
 
polynomial< real > chebyshev_polyn_recurr(polynomial< real > T0, polynomial< real > T1, unsigned int i)
Recursion formula for Chebyshev polynomials The formula is the same for first and second kind polynom...
Definition orthogonal.h:217
 
real legendre_polyn_normalization(unsigned int n)
Normalization constant for the nth Legendre polynomial.
Definition orthogonal.h:77
 
polynomial< real > legendre_polynomial(unsigned int n)
Compute the nth Legendre polynomial.
Definition orthogonal.h:67
 
std::function< polynomial< real >(polynomial< real >, polynomial< real >, unsigned int)> polyn_recurr_formula
Polynomial sequence recurrence formula type Used for computing orthogonal polynomial basis elements.
Definition orthogonal.h:20
 
polynomial< Field > deriv(const polynomial< Field > &p)
Compute the exact derivative of a polynomial function.
Definition deriv.h:21
 
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition dual2_functions.h:23
 
std::vector< real > legendre_roots(unsigned int n)
Roots of the n-th Legendre polynomial.
Definition orthogonal.h:249
 
polynomial< real > legendre_polyn_recurr(polynomial< real > P0, polynomial< real > P1, unsigned int l)
Recursion formula for Legendre polynomials.
Definition orthogonal.h:58
 
polynomial< real > laguerre_polynomial(unsigned int n)
Compute the nth Laguerre polynomial.
Definition orthogonal.h:149
 
dual2 pow(dual2 x, int n)
Compute the n-th power of a second order dual number.
Definition dual2_functions.h:41
 
polynomial< real > hermite_polynomial(unsigned int n)
Compute the nth Hermite polynomial.
Definition orthogonal.h:196
 
Polynomial storage and manipulation.