1 // (C) Copyright Nick Thompson 2019.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_MATH_SPECIAL_JACOBI_HPP
7 #define BOOST_MATH_SPECIAL_JACOBI_HPP
12 namespace boost { namespace math {
14 template<typename Real>
15 Real jacobi(unsigned n, Real alpha, Real beta, Real x)
17 static_assert(!std::is_integral<Real>::value, "Jacobi polynomials do not work with integer arguments.");
23 Real y1 = (alpha+1) + (alpha+beta+2)*(x-1)/Real(2);
27 Real k_max = n*(1+std::numeric_limits<Real>::epsilon());
30 // Hoping for lots of common subexpression elimination by the compiler:
31 Real denom = 2*k*(k+alpha+beta)*(2*k+alpha+beta-2);
32 Real gamma1 = (2*k+alpha+beta-1)*( (2*k+alpha+beta)*(2*k+alpha+beta-2)*x + alpha*alpha -beta*beta);
33 Real gamma0 = -2*(k+alpha-1)*(k+beta-1)*(2*k+alpha+beta);
34 yk = (gamma1*y1 + gamma0*y0)/denom;
42 template<typename Real>
43 Real jacobi_derivative(unsigned n, Real alpha, Real beta, Real x, unsigned k)
49 for(unsigned j = 1; j <= k; ++j) {
50 scale *= (alpha + beta + n + j)/2;
53 return scale*jacobi<Real>(n-k, alpha + k, beta+k, x);
56 template<typename Real>
57 Real jacobi_prime(unsigned n, Real alpha, Real beta, Real x)
59 return jacobi_derivative<Real>(n, alpha, beta, x, 1);
62 template<typename Real>
63 Real jacobi_double_prime(unsigned n, Real alpha, Real beta, Real x)
65 return jacobi_derivative<Real>(n, alpha, beta, x, 2);