File indexing completed on 2025-07-11 08:15:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_MATH_SF_DETAIL_BESSEL_JY_ASYM_HPP
0013 #define BOOST_MATH_SF_DETAIL_BESSEL_JY_ASYM_HPP
0014
0015 #ifdef _MSC_VER
0016 #pragma once
0017 #endif
0018
0019 #include <boost/math/special_functions/factorials.hpp>
0020
0021 namespace boost{ namespace math{ namespace detail{
0022
0023 template <class T>
0024 inline T asymptotic_bessel_amplitude(T v, T x)
0025 {
0026
0027
0028 BOOST_MATH_STD_USING
0029 T s = 1;
0030 T mu = 4 * v * v;
0031 T txq = 2 * x;
0032 txq *= txq;
0033
0034 s += (mu - 1) / (2 * txq);
0035 s += 3 * (mu - 1) * (mu - 9) / (txq * txq * 8);
0036 s += 15 * (mu - 1) * (mu - 9) * (mu - 25) / (txq * txq * txq * 8 * 6);
0037
0038 return sqrt(s * 2 / (constants::pi<T>() * x));
0039 }
0040
0041 template <class T>
0042 T asymptotic_bessel_phase_mx(T v, T x)
0043 {
0044
0045
0046
0047
0048
0049
0050 T mu = 4 * v * v;
0051 T denom = 4 * x;
0052 T denom_mult = denom * denom;
0053
0054 T s = 0;
0055 s += (mu - 1) / (2 * denom);
0056 denom *= denom_mult;
0057 s += (mu - 1) * (mu - 25) / (6 * denom);
0058 denom *= denom_mult;
0059 s += (mu - 1) * (mu * mu - 114 * mu + 1073) / (5 * denom);
0060 denom *= denom_mult;
0061 s += (mu - 1) * (5 * mu * mu * mu - 1535 * mu * mu + 54703 * mu - 375733) / (14 * denom);
0062 return s;
0063 }
0064
0065 template <class T, class Policy>
0066 inline T asymptotic_bessel_y_large_x_2(T v, T x, const Policy& pol)
0067 {
0068
0069 BOOST_MATH_STD_USING
0070
0071 T ampl = asymptotic_bessel_amplitude(v, x);
0072 if (0 == ampl)
0073 return ampl;
0074 T phase = asymptotic_bessel_phase_mx(v, x);
0075 BOOST_MATH_INSTRUMENT_VARIABLE(ampl);
0076 BOOST_MATH_INSTRUMENT_VARIABLE(phase);
0077
0078
0079
0080
0081
0082
0083 T cx = cos(x);
0084 T sx = sin(x);
0085 T ci = boost::math::cos_pi(v / 2 + 0.25f, pol);
0086 T si = boost::math::sin_pi(v / 2 + 0.25f, pol);
0087 T sin_phase = sin(phase) * (cx * ci + sx * si) + cos(phase) * (sx * ci - cx * si);
0088 BOOST_MATH_INSTRUMENT_CODE(sin(phase));
0089 BOOST_MATH_INSTRUMENT_CODE(cos(x));
0090 BOOST_MATH_INSTRUMENT_CODE(cos(phase));
0091 BOOST_MATH_INSTRUMENT_CODE(sin(x));
0092 return sin_phase * ampl;
0093 }
0094
0095 template <class T, class Policy>
0096 inline T asymptotic_bessel_j_large_x_2(T v, T x, const Policy& pol)
0097 {
0098
0099 BOOST_MATH_STD_USING
0100
0101 T ampl = asymptotic_bessel_amplitude(v, x);
0102 if (0 == ampl)
0103 return ampl;
0104 T phase = asymptotic_bessel_phase_mx(v, x);
0105 BOOST_MATH_INSTRUMENT_VARIABLE(ampl);
0106 BOOST_MATH_INSTRUMENT_VARIABLE(phase);
0107
0108
0109
0110
0111
0112
0113 BOOST_MATH_INSTRUMENT_CODE(cos(phase));
0114 BOOST_MATH_INSTRUMENT_CODE(cos(x));
0115 BOOST_MATH_INSTRUMENT_CODE(sin(phase));
0116 BOOST_MATH_INSTRUMENT_CODE(sin(x));
0117 T cx = cos(x);
0118 T sx = sin(x);
0119 T ci = boost::math::cos_pi(v / 2 + 0.25f, pol);
0120 T si = boost::math::sin_pi(v / 2 + 0.25f, pol);
0121 T sin_phase = cos(phase) * (cx * ci + sx * si) - sin(phase) * (sx * ci - cx * si);
0122 BOOST_MATH_INSTRUMENT_VARIABLE(sin_phase);
0123 return sin_phase * ampl;
0124 }
0125
0126 template <class T>
0127 inline bool asymptotic_bessel_large_x_limit(int v, const T& x)
0128 {
0129 BOOST_MATH_STD_USING
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 BOOST_MATH_ASSERT(v >= 0);
0141 return (v ? v : 1) < x * 0.004f;
0142 }
0143
0144 template <class T>
0145 inline bool asymptotic_bessel_large_x_limit(const T& v, const T& x)
0146 {
0147 BOOST_MATH_STD_USING
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 return (std::max)(T(fabs(v)), T(1)) < x * sqrt(tools::forth_root_epsilon<T>());
0159 }
0160
0161 template <class T, class Policy>
0162 void temme_asymptotic_y_small_x(T v, T x, T* Y, T* Y1, const Policy& pol)
0163 {
0164 T c = 1;
0165 T p = (v / boost::math::sin_pi(v, pol)) * pow(x / 2, -v) / boost::math::tgamma(1 - v, pol);
0166 T q = (v / boost::math::sin_pi(v, pol)) * pow(x / 2, v) / boost::math::tgamma(1 + v, pol);
0167 T f = (p - q) / v;
0168 T g_prefix = boost::math::sin_pi(v / 2, pol);
0169 g_prefix *= g_prefix * 2 / v;
0170 T g = f + g_prefix * q;
0171 T h = p;
0172 T c_mult = -x * x / 4;
0173
0174 T y(c * g), y1(c * h);
0175
0176 for(int k = 1; k < policies::get_max_series_iterations<Policy>(); ++k)
0177 {
0178 f = (k * f + p + q) / (k*k - v*v);
0179 p /= k - v;
0180 q /= k + v;
0181 c *= c_mult / k;
0182 T c1 = pow(-x * x / 4, T(k)) / factorial<T>(k, pol);
0183 g = f + g_prefix * q;
0184 h = -k * g + p;
0185 y += c * g;
0186 y1 += c * h;
0187 if(c * g / tools::epsilon<T>() < y)
0188 break;
0189 }
0190
0191 *Y = -y;
0192 *Y1 = (-2 / x) * y1;
0193 }
0194
0195 template <class T, class Policy>
0196 T asymptotic_bessel_i_large_x(T v, T x, const Policy& pol)
0197 {
0198 BOOST_MATH_STD_USING
0199 T s = 1;
0200 T mu = 4 * v * v;
0201 T ex = 8 * x;
0202 T num = mu - 1;
0203 T denom = ex;
0204
0205 s -= num / denom;
0206
0207 num *= mu - 9;
0208 denom *= ex * 2;
0209 s += num / denom;
0210
0211 num *= mu - 25;
0212 denom *= ex * 3;
0213 s -= num / denom;
0214
0215
0216 T e = exp(x/2);
0217
0218 s = e * (e * s / sqrt(2 * x * constants::pi<T>()));
0219
0220 return (boost::math::isfinite)(s) ?
0221 s : policies::raise_overflow_error<T>("boost::math::asymptotic_bessel_i_large_x<%1%>(%1%,%1%)", nullptr, pol);
0222 }
0223
0224 }}}
0225
0226 #endif
0227