42 #ifndef _GLIBCXX_TR1_HYPERGEOMETRIC_TCC
43 #define _GLIBCXX_TR1_HYPERGEOMETRIC_TCC 1
76 template<
typename _Tp>
84 const unsigned int __max_iter = 100000;
86 for (__i = 0; __i < __max_iter; ++__i)
88 __term *= (__a + _Tp(__i)) * __x
89 / ((__c + _Tp(__i)) * _Tp(1 + __i));
96 if (__i == __max_iter)
97 std::__throw_runtime_error(__N(
"Series failed to converge "
98 "in __conf_hyperg_series."));
113 template<
typename _Tp>
118 const int __nmax = 20000;
120 const _Tp __x = -__xin;
121 const _Tp __x3 = __x * __x * __x;
122 const _Tp __t0 = __a / __c;
123 const _Tp __t1 = (__a + _Tp(1)) / (_Tp(2) * __c);
124 const _Tp __t2 = (__a + _Tp(2)) / (_Tp(2) * (__c + _Tp(1)));
129 _Tp __Bnm2 = _Tp(1) + __t1 * __x;
130 _Tp __Bnm1 = _Tp(1) + __t2 * __x * (_Tp(1) + __t1 / _Tp(3) * __x);
133 _Tp __Anm2 = __Bnm2 - __t0 * __x;
134 _Tp __Anm1 = __Bnm1 - __t0 * (_Tp(1) + __t2 * __x) * __x
135 + __t0 * __t1 * (__c / (__c + _Tp(1))) * __x * __x;
140 _Tp __npam1 = _Tp(__n - 1) + __a;
141 _Tp __npcm1 = _Tp(__n - 1) + __c;
142 _Tp __npam2 = _Tp(__n - 2) + __a;
143 _Tp __npcm2 = _Tp(__n - 2) + __c;
144 _Tp __tnm1 = _Tp(2 * __n - 1);
145 _Tp __tnm3 = _Tp(2 * __n - 3);
146 _Tp __tnm5 = _Tp(2 * __n - 5);
147 _Tp __F1 = (_Tp(__n - 2) - __a) / (_Tp(2) * __tnm3 * __npcm1);
148 _Tp __F2 = (_Tp(__n) + __a) * __npam1
149 / (_Tp(4) * __tnm1 * __tnm3 * __npcm2 * __npcm1);
150 _Tp __F3 = -__npam2 * __npam1 * (_Tp(__n - 2) - __a)
151 / (_Tp(8) * __tnm3 * __tnm3 * __tnm5
152 * (_Tp(__n - 3) + __c) * __npcm2 * __npcm1);
153 _Tp __E = -__npam1 * (_Tp(__n - 1) - __c)
154 / (_Tp(2) * __tnm3 * __npcm2 * __npcm1);
156 _Tp __An = (_Tp(1) + __F1 * __x) * __Anm1
157 + (__E + __F2 * __x) * __x * __Anm2 + __F3 * __x3 * __Anm3;
158 _Tp __Bn = (_Tp(1) + __F1 * __x) * __Bnm1
159 + (__E + __F2 * __x) * __x * __Bnm2 + __F3 * __x3 * __Bnm3;
160 _Tp __r = __An / __Bn;
162 __prec =
std::abs((__F - __r) / __F);
165 if (__prec < __eps || __n > __nmax)
179 else if (
std::abs(__An) < _Tp(1) / __big
202 std::__throw_runtime_error(__N(
"Iteration failed to converge "
203 "in __conf_hyperg_luke."));
220 template<
typename _Tp>
224 #if _GLIBCXX_USE_C99_MATH_TR1
225 const _Tp __c_nint = std::tr1::nearbyint(__c);
227 const _Tp __c_nint =
static_cast<int>(__c + _Tp(0.5L));
229 if (__isnan(__a) || __isnan(__c) || __isnan(__x))
231 else if (__c_nint == __c && __c_nint <= 0)
233 else if (__a == _Tp(0))
237 else if (__x < _Tp(0))
264 template<
typename _Tp>
267 const _Tp __c,
const _Tp __x)
273 const unsigned int __max_iter = 100000;
275 for (__i = 0; __i < __max_iter; ++__i)
277 __term *= (__a + _Tp(__i)) * (__b + _Tp(__i)) * __x
278 / ((__c + _Tp(__i)) * _Tp(1 + __i));
285 if (__i == __max_iter)
286 std::__throw_runtime_error(__N(
"Series failed to converge "
287 "in __hyperg_series."));
298 template<
typename _Tp>
304 const int __nmax = 20000;
306 const _Tp __x = -__xin;
307 const _Tp __x3 = __x * __x * __x;
308 const _Tp __t0 = __a * __b / __c;
309 const _Tp __t1 = (__a + _Tp(1)) * (__b + _Tp(1)) / (_Tp(2) * __c);
310 const _Tp __t2 = (__a + _Tp(2)) * (__b + _Tp(2))
311 / (_Tp(2) * (__c + _Tp(1)));
316 _Tp __Bnm2 = _Tp(1) + __t1 * __x;
317 _Tp __Bnm1 = _Tp(1) + __t2 * __x * (_Tp(1) + __t1 / _Tp(3) * __x);
320 _Tp __Anm2 = __Bnm2 - __t0 * __x;
321 _Tp __Anm1 = __Bnm1 - __t0 * (_Tp(1) + __t2 * __x) * __x
322 + __t0 * __t1 * (__c / (__c + _Tp(1))) * __x * __x;
327 const _Tp __npam1 = _Tp(__n - 1) + __a;
328 const _Tp __npbm1 = _Tp(__n - 1) + __b;
329 const _Tp __npcm1 = _Tp(__n - 1) + __c;
330 const _Tp __npam2 = _Tp(__n - 2) + __a;
331 const _Tp __npbm2 = _Tp(__n - 2) + __b;
332 const _Tp __npcm2 = _Tp(__n - 2) + __c;
333 const _Tp __tnm1 = _Tp(2 * __n - 1);
334 const _Tp __tnm3 = _Tp(2 * __n - 3);
335 const _Tp __tnm5 = _Tp(2 * __n - 5);
336 const _Tp __n2 = __n * __n;
337 const _Tp __F1 = (_Tp(3) * __n2 + (__a + __b - _Tp(6)) * __n
338 + _Tp(2) - __a * __b - _Tp(2) * (__a + __b))
339 / (_Tp(2) * __tnm3 * __npcm1);
340 const _Tp __F2 = -(_Tp(3) * __n2 - (__a + __b + _Tp(6)) * __n
341 + _Tp(2) - __a * __b) * __npam1 * __npbm1
342 / (_Tp(4) * __tnm1 * __tnm3 * __npcm2 * __npcm1);
343 const _Tp __F3 = (__npam2 * __npam1 * __npbm2 * __npbm1
344 * (_Tp(__n - 2) - __a) * (_Tp(__n - 2) - __b))
345 / (_Tp(8) * __tnm3 * __tnm3 * __tnm5
346 * (_Tp(__n - 3) + __c) * __npcm2 * __npcm1);
347 const _Tp __E = -__npam1 * __npbm1 * (_Tp(__n - 1) - __c)
348 / (_Tp(2) * __tnm3 * __npcm2 * __npcm1);
350 _Tp __An = (_Tp(1) + __F1 * __x) * __Anm1
351 + (__E + __F2 * __x) * __x * __Anm2 + __F3 * __x3 * __Anm3;
352 _Tp __Bn = (_Tp(1) + __F1 * __x) * __Bnm1
353 + (__E + __F2 * __x) * __x * __Bnm2 + __F3 * __x3 * __Bnm3;
354 const _Tp __r = __An / __Bn;
356 const _Tp __prec =
std::abs((__F - __r) / __F);
359 if (__prec < __eps || __n > __nmax)
373 else if (
std::abs(__An) < _Tp(1) / __big
396 std::__throw_runtime_error(__N(
"Iteration failed to converge "
397 "in __hyperg_luke."));
432 template<
typename _Tp>
437 const _Tp __d = __c - __a - __b;
438 const int __intd = std::floor(__d + _Tp(0.5L));
440 const _Tp __toler = _Tp(1000) * __eps;
442 const bool __d_integer = (
std::abs(__d - __intd) < __toler);
446 const _Tp __ln_omx =
std::log(_Tp(1) - __x);
474 _Tp __lng_ad, __lng_ad1, __lng_bd1;
493 _Tp __ln_pre1 = __lng_ad + __lng_c + __d2 * __ln_omx
494 - __lng_ad1 - __lng_bd1;
498 for (
int __i = 1; __i < __ad; ++__i)
500 const int __j = __i - 1;
501 __term *= (__a + __d2 + __j) * (__b + __d2 + __j)
502 / (_Tp(1) + __d2 + __j) / __i * (_Tp(1) - __x);
506 if (__ln_pre1 > __log_max)
507 std::__throw_runtime_error(__N(
"Overflow of gamma functions "
508 "in __hyperg_luke."));
510 __F1 =
std::exp(__ln_pre1) * __sum1;
522 _Tp __lng_ad2, __lng_bd2;
537 const int __maxiter = 2000;
539 const _Tp __psi_1pd =
__psi(_Tp(1) + __ad);
540 const _Tp __psi_apd1 =
__psi(__a + __d1);
541 const _Tp __psi_bpd1 =
__psi(__b + __d1);
543 _Tp __psi_term = __psi_1 + __psi_1pd - __psi_apd1
544 - __psi_bpd1 - __ln_omx;
546 _Tp __sum2 = __psi_term;
547 _Tp __ln_pre2 = __lng_c + __d1 * __ln_omx
548 - __lng_ad2 - __lng_bd2;
552 for (__j = 1; __j < __maxiter; ++__j)
555 const _Tp __term1 = _Tp(1) / _Tp(__j)
556 + _Tp(1) / (__ad + __j);
557 const _Tp __term2 = _Tp(1) / (__a + __d1 + _Tp(__j - 1))
558 + _Tp(1) / (__b + __d1 + _Tp(__j - 1));
559 __psi_term += __term1 - __term2;
560 __fact *= (__a + __d1 + _Tp(__j - 1))
561 * (__b + __d1 + _Tp(__j - 1))
562 / ((__ad + __j) * __j) * (_Tp(1) - __x);
563 const _Tp __delta = __fact * __psi_term;
568 if (__j == __maxiter)
569 std::__throw_runtime_error(__N(
"Sum F2 failed to converge "
570 "in __hyperg_reflect"));
572 if (__sum2 == _Tp(0))
575 __F2 =
std::exp(__ln_pre2) * __sum2;
584 const _Tp __sgn_2 = (__intd % 2 == 1 ? -_Tp(1) : _Tp(1));
585 const _Tp __F = __F1 + __sgn_2 * __F2;
596 _Tp __sgn_g1ca = _Tp(0), __ln_g1ca = _Tp(0);
597 _Tp __sgn_g1cb = _Tp(0), __ln_g1cb = _Tp(0);
611 _Tp __sgn_g2a = _Tp(0), __ln_g2a = _Tp(0);
612 _Tp __sgn_g2b = _Tp(0), __ln_g2b = _Tp(0);
632 const _Tp __sgn1 = __sgn_gc * __sgn_gd * __sgn_g1ca * __sgn_g1cb;
633 const _Tp __sgn2 = __sgn_gc * __sgn_gmd * __sgn_g2a * __sgn_g2b;
638 _Tp __ln_pre1 = __ln_gc + __ln_gd - __ln_g1ca - __ln_g1cb;
639 _Tp __ln_pre2 = __ln_gc + __ln_gmd - __ln_g2a - __ln_g2b
641 if (__ln_pre1 < __log_max && __ln_pre2 < __log_max)
650 std::__throw_runtime_error(__N(
"Overflow of gamma functions "
651 "in __hyperg_reflect"));
654 else if (__ok1 && !__ok2)
656 _Tp __ln_pre1 = __ln_gc + __ln_gd - __ln_g1ca - __ln_g1cb;
657 if (__ln_pre1 < __log_max)
665 std::__throw_runtime_error(__N(
"Overflow of gamma functions "
666 "in __hyperg_reflect"));
669 else if (!__ok1 && __ok2)
671 _Tp __ln_pre2 = __ln_gc + __ln_gmd - __ln_g2a - __ln_g2b
673 if (__ln_pre2 < __log_max)
681 std::__throw_runtime_error(__N(
"Overflow of gamma functions "
682 "in __hyperg_reflect"));
689 std::__throw_runtime_error(__N(
"Underflow of gamma functions "
690 "in __hyperg_reflect"));
698 const _Tp __F = __pre1 * __F1 + __pre2 * __F2;
722 template<
typename _Tp>
724 __hyperg(
const _Tp __a,
const _Tp __b,
const _Tp __c,
const _Tp __x)
726 #if _GLIBCXX_USE_C99_MATH_TR1
727 const _Tp __a_nint = std::tr1::nearbyint(__a);
728 const _Tp __b_nint = std::tr1::nearbyint(__b);
729 const _Tp __c_nint = std::tr1::nearbyint(__c);
731 const _Tp __a_nint =
static_cast<int>(__a + _Tp(0.5L));
732 const _Tp __b_nint =
static_cast<int>(__b + _Tp(0.5L));
733 const _Tp __c_nint =
static_cast<int>(__c + _Tp(0.5L));
737 std::__throw_domain_error(__N(
"Argument outside unit circle "
739 else if (__isnan(__a) || __isnan(__b)
740 || __isnan(__c) || __isnan(__x))
742 else if (__c_nint == __c && __c_nint <= _Tp(0))
745 return std::pow(_Tp(1) - __x, __c - __a - __b);
746 else if (__a >= _Tp(0) && __b >= _Tp(0) && __c >= _Tp(0)
747 && __x >= _Tp(0) && __x < _Tp(0.995L))
752 if (__a < _Tp(0) &&
std::abs(__a - __a_nint) < __toler)
754 else if (__b < _Tp(0) &&
std::abs(__b - __b_nint) < __toler)
756 else if (__x < -_Tp(0.25L))
758 else if (__x < _Tp(0.5L))
774 #endif // _GLIBCXX_TR1_HYPERGEOMETRIC_TCC
_Tp __conf_hyperg_series(const _Tp __a, const _Tp __c, const _Tp __x)
This routine returns the confluent hypergeometric function by series expansion.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
_Tp __hyperg_luke(const _Tp __a, const _Tp __b, const _Tp __c, const _Tp __xin)
Return the hypogeometric function by an iterative procedure described in Luke, Algorithms for the Co...
static _Tp __gamma_e()
Constant Euler's constant .
Properties of fundamental types.
_Tp __psi(const _Tp __x)
Return the digamma function. The digamma or function is defined by For negative argument the reflec...
_Tp __log_gamma(const _Tp __x)
Return . This will return values even for . To recover the sign of for any argument use __log_gamma_...
complex< _Tp > pow(const complex< _Tp > &, const _Tp &)
Return x to the y'th power.
_Tp __hyperg_reflect(const _Tp __a, const _Tp __b, const _Tp __c, const _Tp __x)
Return the hypogeometric function by the reflection formulae in Abramowitz & Stegun formula 15...
_Tp __log_gamma_sign(const _Tp __x)
Return the sign of . At nonpositive integers zero is returned.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
_Tp __hyperg_series(const _Tp __a, const _Tp __b, const _Tp __c, const _Tp __x)
Return the hypogeometric function by series expansion.
_Tp __conf_hyperg_luke(const _Tp __a, const _Tp __c, const _Tp __xin)
Return the hypogeometric function by an iterative procedure described in Luke, Algorithms for the Co...
_Tp __conf_hyperg(const _Tp __a, const _Tp __c, const _Tp __x)
Return the confluent hypogeometric function .
_Tp __hyperg(const _Tp __a, const _Tp __b, const _Tp __c, const _Tp __x)
Return the hypogeometric function .
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.