Debian Codegraph @

third-party/boost-math/include/boost/math/special_functions/detail/airy_ai_bi_zero.hpp

raw
1 // Copyright (c) 2013 Christopher Kormanyos
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)
5 //
6 // This work is based on an earlier work:
7 // "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations",
8 // in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469
9 //
10 // This header contains implementation details for estimating the zeros
11 // of the Airy functions airy_ai and airy_bi on the negative real axis.
12 //
13 #ifndef BOOST_MATH_AIRY_AI_BI_ZERO_2013_01_20_HPP_
14 #define BOOST_MATH_AIRY_AI_BI_ZERO_2013_01_20_HPP_
15
16 #include <boost/math/tools/config.hpp>
17 #include <boost/math/tools/tuple.hpp>
18 #include <boost/math/constants/constants.hpp>
19 #include <boost/math/special_functions/cbrt.hpp>
20
21 namespace boost { namespace math {
22 namespace detail
23 {
24 // Forward declarations of the needed Airy function implementations.
25 template <class T, class Policy>
26 BOOST_MATH_GPU_ENABLED T airy_ai_imp(T x, const Policy& pol);
27 template <class T, class Policy>
28 BOOST_MATH_GPU_ENABLED T airy_bi_imp(T x, const Policy& pol);
29 template <class T, class Policy>
30 BOOST_MATH_GPU_ENABLED T airy_ai_prime_imp(T x, const Policy& pol);
31 template <class T, class Policy>
32 BOOST_MATH_GPU_ENABLED T airy_bi_prime_imp(T x, const Policy& pol);
33
34 namespace airy_zero
35 {
36 template<class T, class Policy>
37 BOOST_MATH_GPU_ENABLED T equation_as_10_4_105(const T& z, const Policy& pol)
38 {
39 const T one_over_z (T(1) / z);
40 const T one_over_z_squared(one_over_z * one_over_z);
41
42 const T z_pow_third (boost::math::cbrt(z, pol));
43 const T z_pow_two_thirds(z_pow_third * z_pow_third);
44
45 // Implement the top line of Eq. 10.4.105.
46 const T fz(z_pow_two_thirds * ((((( + (T(162375596875.0) / 334430208UL)
47 * one_over_z_squared - ( T(108056875.0) / 6967296UL))
48 * one_over_z_squared + ( T(77125UL) / 82944UL))
49 * one_over_z_squared - ( T(5U) / 36U))
50 * one_over_z_squared + ( T(5U) / 48U))
51 * one_over_z_squared + 1));
52
53 return fz;
54 }
55
56 namespace airy_ai_zero_detail
57 {
58 template<class T, class Policy>
59 BOOST_MATH_GPU_ENABLED T initial_guess(const int m, const Policy& pol)
60 {
61 T guess;
62
63 switch(m)
64 {
65 case 0:
66 guess = T(0);
67 break;
68 case 1:
69 guess = T(-2.33810741045976703849);
70 break;
71 case 2:
72 guess = T(-4.08794944413097061664);
73 break;
74 case 3:
75 guess = T(-5.52055982809555105913);
76 break;
77 case 4:
78 guess = T(-6.78670809007175899878);
79 break;
80 case 5:
81 guess = T(-7.94413358712085312314);
82 break;
83 case 6:
84 guess = T(-9.02265085334098038016);
85 break;
86 case 7:
87 guess = T(-10.0401743415580859306);
88 break;
89 case 8:
90 guess = T(-11.0085243037332628932);
91 break;
92 case 9:
93 guess = T(-11.9360155632362625170);
94 break;
95 case 10:
96 guess = T(-12.8287767528657572004);
97 break;
98 default:
99 const T t(((boost::math::constants::pi<T>() * 3) * ((T(m) * 4) - 1)) / 8);
100 guess = -boost::math::detail::airy_zero::equation_as_10_4_105(t, pol);
101 break;
102 }
103
104 return guess;
105 }
106
107 template<class T, class Policy>
108 class function_object_ai_and_ai_prime
109 {
110 public:
111 BOOST_MATH_GPU_ENABLED explicit function_object_ai_and_ai_prime(const Policy& pol) : my_pol(pol) { }
112
113 #ifdef BOOST_MATH_ENABLE_CUDA
114 # pragma nv_diag_suppress 20012
115 #endif
116
117 BOOST_MATH_GPU_ENABLED function_object_ai_and_ai_prime(const function_object_ai_and_ai_prime&) = default;
118
119 #ifdef BOOST_MATH_ENABLE_CUDA
120 # pragma nv_diag_default 20012
121 #endif
122
123 BOOST_MATH_GPU_ENABLED boost::math::tuple<T, T> operator()(const T& x) const
124 {
125 // Return a tuple containing both Ai(x) and Ai'(x).
126 return boost::math::make_tuple(
127 boost::math::detail::airy_ai_imp (x, my_pol),
128 boost::math::detail::airy_ai_prime_imp(x, my_pol));
129 }
130
131 private:
132 const Policy& my_pol;
133 const function_object_ai_and_ai_prime& operator=(const function_object_ai_and_ai_prime&) = delete;
134 };
135 } // namespace airy_ai_zero_detail
136
137 namespace airy_bi_zero_detail
138 {
139 template<class T, class Policy>
140 BOOST_MATH_GPU_ENABLED T initial_guess(const int m, const Policy& pol)
141 {
142 T guess;
143
144 switch(m)
145 {
146 case 0:
147 guess = T(0);
148 break;
149 case 1:
150 guess = T(-1.17371322270912792492);
151 break;
152 case 2:
153 guess = T(-3.27109330283635271568);
154 break;
155 case 3:
156 guess = T(-4.83073784166201593267);
157 break;
158 case 4:
159 guess = T(-6.16985212831025125983);
160 break;
161 case 5:
162 guess = T(-7.37676207936776371360);
163 break;
164 case 6:
165 guess = T(-8.49194884650938801345);
166 break;
167 case 7:
168 guess = T(-9.53819437934623888663);
169 break;
170 case 8:
171 guess = T(-10.5299135067053579244);
172 break;
173 case 9:
174 guess = T(-11.4769535512787794379);
175 break;
176 case 10:
177 guess = T(-12.3864171385827387456);
178 break;
179 default:
180 const T t(((boost::math::constants::pi<T>() * 3) * ((T(m) * 4) - 3)) / 8);
181 guess = -boost::math::detail::airy_zero::equation_as_10_4_105(t, pol);
182 break;
183 }
184
185 return guess;
186 }
187
188 template<class T, class Policy>
189 class function_object_bi_and_bi_prime
190 {
191 public:
192 BOOST_MATH_GPU_ENABLED explicit function_object_bi_and_bi_prime(const Policy& pol) : my_pol(pol) { }
193
194 #ifdef BOOST_MATH_ENABLE_CUDA
195 # pragma nv_diag_suppress 20012
196 #endif
197
198 BOOST_MATH_GPU_ENABLED function_object_bi_and_bi_prime(const function_object_bi_and_bi_prime&) = default;
199
200 #ifdef BOOST_MATH_ENABLE_CUDA
201 # pragma nv_diag_default 20012
202 #endif
203
204 BOOST_MATH_GPU_ENABLED boost::math::tuple<T, T> operator()(const T& x) const
205 {
206 // Return a tuple containing both Bi(x) and Bi'(x).
207 return boost::math::make_tuple(
208 boost::math::detail::airy_bi_imp (x, my_pol),
209 boost::math::detail::airy_bi_prime_imp(x, my_pol));
210 }
211
212 private:
213 const Policy& my_pol;
214 const function_object_bi_and_bi_prime& operator=(const function_object_bi_and_bi_prime&) = delete;
215 };
216 } // namespace airy_bi_zero_detail
217 } // namespace airy_zero
218 } // namespace detail
219 } // namespace math
220 } // namespaces boost
221
222 #endif // BOOST_MATH_AIRY_AI_BI_ZERO_2013_01_20_HPP_