heuman_lambda.hpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (c) 2015 John Maddock
  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. #ifndef BOOST_MATH_ELLINT_HL_HPP
  6. #define BOOST_MATH_ELLINT_HL_HPP
  7. #ifdef _MSC_VER
  8. #pragma once
  9. #endif
  10. #include <boost/math/special_functions/math_fwd.hpp>
  11. #include <boost/math/special_functions/ellint_rj.hpp>
  12. #include <boost/math/special_functions/ellint_1.hpp>
  13. #include <boost/math/special_functions/jacobi_zeta.hpp>
  14. #include <boost/math/constants/constants.hpp>
  15. #include <boost/math/policies/error_handling.hpp>
  16. #include <boost/math/tools/workaround.hpp>
  17. // Elliptic integral the Jacobi Zeta function.
  18. namespace boost { namespace math {
  19. namespace detail{
  20. // Elliptic integral - Jacobi Zeta
  21. template <typename T, typename Policy>
  22. T heuman_lambda_imp(T phi, T k, const Policy& pol)
  23. {
  24. BOOST_MATH_STD_USING
  25. using namespace boost::math::tools;
  26. using namespace boost::math::constants;
  27. const char* function = "boost::math::heuman_lambda<%1%>(%1%, %1%)";
  28. if(fabs(k) > 1)
  29. return policies::raise_domain_error<T>(function, "We require |k| <= 1 but got k = %1%", k, pol);
  30. T result;
  31. T sinp = sin(phi);
  32. T cosp = cos(phi);
  33. T s2 = sinp * sinp;
  34. T k2 = k * k;
  35. T kp = 1 - k2;
  36. T delta = sqrt(1 - (kp * s2));
  37. if(fabs(phi) <= constants::half_pi<T>())
  38. {
  39. result = kp * sinp * cosp / (delta * constants::half_pi<T>());
  40. result *= ellint_rf_imp(T(0), kp, T(1), pol) + k2 * ellint_rj(T(0), kp, T(1), T(1 - k2 / (delta * delta)), pol) / (3 * delta * delta);
  41. }
  42. else
  43. {
  44. typedef std::integral_constant<int,
  45. std::is_floating_point<T>::value&& std::numeric_limits<T>::digits && (std::numeric_limits<T>::digits <= 54) ? 0 :
  46. std::is_floating_point<T>::value && std::numeric_limits<T>::digits && (std::numeric_limits<T>::digits <= 64) ? 1 : 2
  47. > precision_tag_type;
  48. T rkp = sqrt(kp);
  49. T ratio;
  50. if(rkp == 1)
  51. {
  52. return policies::raise_domain_error<T>(function, "When 1-k^2 == 1 then phi must be < Pi/2, but got phi = %1%", phi, pol);
  53. }
  54. else
  55. ratio = ellint_f_imp(phi, rkp, pol) / ellint_k_imp(rkp, pol, precision_tag_type());
  56. result = ratio + ellint_k_imp(k, pol, precision_tag_type()) * jacobi_zeta_imp(phi, rkp, pol) / constants::half_pi<T>();
  57. }
  58. return result;
  59. }
  60. } // detail
  61. template <class T1, class T2, class Policy>
  62. inline typename tools::promote_args<T1, T2>::type heuman_lambda(T1 k, T2 phi, const Policy& pol)
  63. {
  64. typedef typename tools::promote_args<T1, T2>::type result_type;
  65. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  66. return policies::checked_narrowing_cast<result_type, Policy>(detail::heuman_lambda_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::heuman_lambda<%1%>(%1%,%1%)");
  67. }
  68. template <class T1, class T2>
  69. inline typename tools::promote_args<T1, T2>::type heuman_lambda(T1 k, T2 phi)
  70. {
  71. return boost::math::heuman_lambda(k, phi, policies::policy<>());
  72. }
  73. }} // namespaces
  74. #endif // BOOST_MATH_ELLINT_D_HPP