Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:36:15

0001 //  Copyright (c) 2015 John Maddock
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 
0007 #ifndef BOOST_MATH_ELLINT_JZ_HPP
0008 #define BOOST_MATH_ELLINT_JZ_HPP
0009 
0010 #ifdef _MSC_VER
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/math/tools/config.hpp>
0015 #include <boost/math/tools/promotion.hpp>
0016 #include <boost/math/special_functions/math_fwd.hpp>
0017 #include <boost/math/special_functions/ellint_1.hpp>
0018 #include <boost/math/special_functions/ellint_rj.hpp>
0019 #include <boost/math/special_functions/sign.hpp>
0020 #include <boost/math/constants/constants.hpp>
0021 #include <boost/math/policies/error_handling.hpp>
0022 #include <boost/math/tools/workaround.hpp>
0023 
0024 // Elliptic integral the Jacobi Zeta function.
0025 
0026 namespace boost { namespace math { 
0027    
0028 namespace detail{
0029 
0030 // Elliptic integral - Jacobi Zeta
0031 template <typename T, typename Policy>
0032 BOOST_MATH_GPU_ENABLED T jacobi_zeta_imp(T phi, T k, const Policy& pol, T kp)
0033 {
0034     BOOST_MATH_STD_USING
0035     using namespace boost::math::tools;
0036     using namespace boost::math::constants;
0037 
0038     bool invert = false;
0039     if(phi < 0)
0040     {
0041        phi = fabs(phi);
0042        invert = true;
0043     }
0044 
0045     T result;
0046     T sinp = sin(phi);
0047     T cosp = cos(phi);
0048     T c2 = cosp * cosp;
0049     T one_minus_ks2 = kp + c2 - kp * c2;
0050     T k2 = k * k;
0051     if(k == 1)
0052        result = sinp * (boost::math::sign)(cosp);  // We get here by simplifying JacobiZeta[w, 1] in Mathematica, and the fact that 0 <= phi.
0053     else
0054     {
0055        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));
0056     }
0057     return invert ? T(-result) : result;
0058 }
0059 template <typename T, typename Policy>
0060 BOOST_MATH_GPU_ENABLED inline T jacobi_zeta_imp(T phi, T k, const Policy& pol)
0061 {
0062    return jacobi_zeta_imp(phi, k, pol, T(1 - k * k));
0063 }
0064 } // detail
0065 
0066 template <class T1, class T2, class Policy>
0067 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi, const Policy& pol)
0068 {
0069    typedef typename tools::promote_args<T1, T2>::type result_type;
0070    typedef typename policies::evaluation<result_type, Policy>::type value_type;
0071    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%)");
0072 }
0073 
0074 template <class T1, class T2>
0075 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi)
0076 {
0077    return boost::math::jacobi_zeta(k, phi, policies::policy<>());
0078 }
0079 
0080 }} // namespaces
0081 
0082 #endif // BOOST_MATH_ELLINT_D_HPP
0083