hypergeometric_0F1_bessel.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2014 Anton Bikineev
  3. // Copyright 2014 Christopher Kormanyos
  4. // Copyright 2014 John Maddock
  5. // Copyright 2014 Paul Bristow
  6. // Distributed under the Boost
  7. // Software License, Version 1.0. (See accompanying file
  8. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_MATH_HYPERGEOMETRIC_0F1_BESSEL_HPP
  11. #define BOOST_MATH_HYPERGEOMETRIC_0F1_BESSEL_HPP
  12. #include <boost/math/special_functions/bessel.hpp>
  13. #include <boost/math/special_functions/gamma.hpp>
  14. namespace boost { namespace math { namespace detail {
  15. template <class T, class Policy>
  16. inline T hypergeometric_0F1_bessel(const T& b, const T& z, const Policy& pol)
  17. {
  18. BOOST_MATH_STD_USING
  19. const bool is_z_nonpositive = z <= 0;
  20. const T sqrt_z = is_z_nonpositive ? T(sqrt(-z)) : T(sqrt(z));
  21. const T bessel_mult = is_z_nonpositive ?
  22. boost::math::cyl_bessel_j(b - 1, 2 * sqrt_z, pol) :
  23. boost::math::cyl_bessel_i(b - 1, 2 * sqrt_z, pol) ;
  24. if (b > boost::math::max_factorial<T>::value)
  25. {
  26. const T lsqrt_z = log(sqrt_z);
  27. const T lsqrt_z_pow_b = (b - 1) * lsqrt_z;
  28. T lg = (boost::math::lgamma(b, pol) - lsqrt_z_pow_b);
  29. lg = exp(lg);
  30. return lg * bessel_mult;
  31. }
  32. else
  33. {
  34. const T sqrt_z_pow_b = pow(sqrt_z, b - 1);
  35. return (boost::math::tgamma(b, pol) / sqrt_z_pow_b) * bessel_mult;
  36. }
  37. }
  38. } } } // namespaces
  39. #endif // BOOST_MATH_HYPERGEOMETRIC_0F1_BESSEL_HPP