heuman_lambda.hpp 3.4 KB

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