2 * Copyright Nick Thompson, 2019
3 * Use, modification and distribution are subject to the
4 * Boost Software License, Version 1.0. (See accompanying file
5 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #include "math_unit_test.hpp"
13 #include <boost/math/special_functions/jacobi.hpp>
14 #ifdef BOOST_HAS_FLOAT128
15 #include <boost/multiprecision/float128.hpp>
16 using boost::multiprecision::float128;
20 using boost::math::jacobi;
21 using boost::math::jacobi_derivative;
23 template<typename Real>
24 void test_to_quadratic()
27 for (Real alpha = -1 + h; alpha < 2; alpha += h) {
28 for (Real beta = -1 + h; beta < 2; beta += h) {
29 for (Real x = -1; x < 1; x += h) {
31 Real computed = jacobi(0, alpha, beta, x);
32 CHECK_ULP_CLOSE(expected, computed, 0);
34 expected = (alpha + 1) + (alpha + beta +2)*(x-1)/2;
35 computed = jacobi(1, alpha, beta, x);
36 CHECK_ULP_CLOSE(expected, computed, 0);
38 expected = (alpha + 1)*(alpha+2)/2 + (alpha + 2)*(alpha + beta + 3)*(x-1)/2 + (alpha + beta + 3)*(alpha + beta + 4)*(x-1)*(x-1)/8;
39 computed = jacobi(2, alpha, beta, x);
40 CHECK_ULP_CLOSE(expected, computed, 1);
47 template<typename Real>
51 for (Real alpha = -1 + h; alpha < 2; alpha += h) {
52 for (Real beta = -1 + h; beta < 2; beta += h) {
53 for (Real x = -1; x < 1; x += h) {
54 for (size_t n = 0; n < 20; n += 2)
56 Real expected = jacobi(n, beta, alpha , -x);
57 Real computed = jacobi(n, alpha, beta, x);
58 CHECK_ULP_CLOSE(expected, computed, 0);
60 expected = jacobi(n+1, beta, alpha, -x);
61 computed = -jacobi(n+1, alpha, beta, x);
62 CHECK_ULP_CLOSE(expected, computed, 0);
69 template<typename Real>
70 void test_derivative()
73 for (Real alpha = -1 + h; alpha < 2; alpha += h) {
74 for (Real beta = -1 + h; beta < 2; beta += h) {
75 for (Real x = -1; x < 1; x += h) {
77 Real computed = jacobi_derivative(0, alpha, beta, x, 1);
78 CHECK_ULP_CLOSE(expected, computed, 0);
80 expected = (alpha + beta + 2)/2;
81 computed = jacobi_derivative(1, alpha, beta, x, 1);
82 CHECK_ULP_CLOSE(expected, computed, 0);
84 expected = (alpha + 2)*(alpha + beta + 3)/2 + (alpha + beta + 3)*(alpha + beta + 4)*(x-1)/4;
85 computed = jacobi_derivative(2, alpha, beta, x, 1);
86 CHECK_ULP_CLOSE(expected, computed, 0);
88 expected = (alpha + beta + 3)*(alpha + beta + 4)/4;
89 computed = jacobi_derivative(2, alpha, beta, x, 2);
90 CHECK_ULP_CLOSE(expected, computed, 0);
98 test_to_quadratic<double>();
99 test_to_quadratic<long double>();
101 test_symmetry<float>();
102 test_symmetry<double>();
103 test_symmetry<long double>();
105 test_derivative<float>();
106 test_derivative<double>();
107 test_derivative<long double>();
109 #ifdef BOOST_HAS_FLOAT128
110 test_to_quadratic<boost::multiprecision::float128>();
111 test_symmetry<boost::multiprecision::float128>();
112 test_derivative<boost::multiprecision::float128>();
115 return boost::math::test::report_errors();