Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 08:19:47

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/special_functions/math_fwd.hpp>
0015 #include <boost/math/special_functions/ellint_1.hpp>
0016 #include <boost/math/special_functions/ellint_rj.hpp>
0017 #include <boost/math/special_functions/sign.hpp>
0018 #include <boost/math/constants/constants.hpp>
0019 #include <boost/math/policies/error_handling.hpp>
0020 #include <boost/math/tools/workaround.hpp>
0021 
0022 // Elliptic integral the Jacobi Zeta function.
0023 
0024 namespace boost { namespace math { 
0025    
0026 namespace detail{
0027 
0028 // Elliptic integral - Jacobi Zeta
0029 template <typename T, typename Policy>
0030 T jacobi_zeta_imp(T phi, T k, const Policy& pol, T kp)
0031 {
0032     BOOST_MATH_STD_USING
0033     using namespace boost::math::tools;
0034     using namespace boost::math::constants;
0035 
0036     bool invert = false;
0037     if(phi < 0)
0038     {
0039        phi = fabs(phi);
0040        invert = true;
0041     }
0042 
0043     T result;
0044     T sinp = sin(phi);
0045     T cosp = cos(phi);
0046     T c2 = cosp * cosp;
0047     T one_minus_ks2 = kp + c2 - kp * c2;
0048     T k2 = k * k;
0049     if(k == 1)
0050        result = sinp * (boost::math::sign)(cosp);  // We get here by simplifying JacobiZeta[w, 1] in Mathematica, and the fact that 0 <= phi.
0051     else
0052     {
0053        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));
0054     }
0055     return invert ? T(-result) : result;
0056 }
0057 template <typename T, typename Policy>
0058 inline T jacobi_zeta_imp(T phi, T k, const Policy& pol)
0059 {
0060    return jacobi_zeta_imp(phi, k, pol, T(1 - k * k));
0061 }
0062 } // detail
0063 
0064 template <class T1, class T2, class Policy>
0065 inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi, const Policy& pol)
0066 {
0067    typedef typename tools::promote_args<T1, T2>::type result_type;
0068    typedef typename policies::evaluation<result_type, Policy>::type value_type;
0069    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%)");
0070 }
0071 
0072 template <class T1, class T2>
0073 inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi)
0074 {
0075    return boost::math::jacobi_zeta(k, phi, policies::policy<>());
0076 }
0077 
0078 }} // namespaces
0079 
0080 #endif // BOOST_MATH_ELLINT_D_HPP
0081