Debian Codegraph @

third-party/boost-math/include/boost/math/special_functions/jacobi_zeta.hpp

raw
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 //
6
7 #ifndef BOOST_MATH_ELLINT_JZ_HPP
8 #define BOOST_MATH_ELLINT_JZ_HPP
9
10 #ifdef _MSC_VER
11 #pragma once
12 #endif
13
14 #include <boost/math/tools/config.hpp>
15 #include <boost/math/tools/promotion.hpp>
16 #include <boost/math/special_functions/math_fwd.hpp>
17 #include <boost/math/special_functions/ellint_1.hpp>
18 #include <boost/math/special_functions/ellint_rj.hpp>
19 #include <boost/math/special_functions/sign.hpp>
20 #include <boost/math/constants/constants.hpp>
21 #include <boost/math/policies/error_handling.hpp>
22 #include <boost/math/tools/workaround.hpp>
23
24 // Elliptic integral the Jacobi Zeta function.
25
26 namespace boost { namespace math {
27
28 namespace detail{
29
30 // Elliptic integral - Jacobi Zeta
31 template <typename T, typename Policy>
32 BOOST_MATH_GPU_ENABLED T jacobi_zeta_imp(T phi, T k, const Policy& pol, T kp)
33 {
34 BOOST_MATH_STD_USING
35 using namespace boost::math::tools;
36 using namespace boost::math::constants;
37
38 bool invert = false;
39 if(phi < 0)
40 {
41 phi = fabs(phi);
42 invert = true;
43 }
44
45 T result;
46 T sinp = sin(phi);
47 T cosp = cos(phi);
48 T c2 = cosp * cosp;
49 T one_minus_ks2 = kp + c2 - kp * c2;
50 T k2 = k * k;
51 if(k == 1)
52 result = sinp * (boost::math::sign)(cosp); // We get here by simplifying JacobiZeta[w, 1] in Mathematica, and the fact that 0 <= phi.
53 else
54 {
55 result = k2 * sinp * cosp * sqrt(one_minus_ks2) * ellint_rj_imp(T(0), kp, T(1), one_minus_ks2, pol) / (3 * ellint_k_imp(k, pol, kp));
56 }
57 return invert ? T(-result) : result;
58 }
59 template <typename T, typename Policy>
60 BOOST_MATH_GPU_ENABLED inline T jacobi_zeta_imp(T phi, T k, const Policy& pol)
61 {
62 return jacobi_zeta_imp(phi, k, pol, T(1 - k * k));
63 }
64 } // detail
65
66 template <class T1, class T2, class Policy>
67 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi, const Policy& pol)
68 {
69 typedef typename tools::promote_args<T1, T2>::type result_type;
70 typedef typename policies::evaluation<result_type, Policy>::type value_type;
71 return policies::checked_narrowing_cast<result_type, Policy>(detail::jacobi_zeta_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::jacobi_zeta<%1%>(%1%,%1%)");
72 }
73
74 template <class T1, class T2>
75 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi)
76 {
77 return boost::math::jacobi_zeta(k, phi, policies::policy<>());
78 }
79
80 }} // namespaces
81
82 #endif // BOOST_MATH_ELLINT_D_HPP
83