Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:06

0001 ///////////////////////////////////////////////////////////////////////////////
0002 //  Copyright 2014 Anton Bikineev
0003 //  Copyright 2014 Christopher Kormanyos
0004 //  Copyright 2014 John Maddock
0005 //  Copyright 2014 Paul Bristow
0006 //  Distributed under the Boost
0007 //  Software License, Version 1.0. (See accompanying file
0008 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 #ifndef BOOST_MATH_HYPERGEOMETRIC_RATIONAL_HPP
0011 #define BOOST_MATH_HYPERGEOMETRIC_RATIONAL_HPP
0012 
0013   #include <array>
0014 
0015   namespace boost{ namespace math{ namespace detail{
0016 
0017   // Luke: C ------- SUBROUTINE R1F1P(AP, CP, Z, A, B, N) ---------
0018   // Luke: C --- RATIONAL APPROXIMATION OF 1F1( AP ; CP ; -Z ) ----
0019   template <class T, class Policy>
0020   inline T hypergeometric_1F1_rational(const T& ap, const T& cp, const T& zp, const Policy& )
0021   {
0022     BOOST_MATH_STD_USING
0023 
0024     static const T zero = T(0), one = T(1), two = T(2), three = T(3);
0025 
0026     // Luke: C ------------- INITIALIZATION -------------
0027     const T z = -zp;
0028     const T z2 = z / two;
0029 
0030     T ct1 = ap * (z / cp);
0031     T ct2 = z2 / (one + cp);
0032     T xn3 = zero;
0033     T xn2 = one;
0034     T xn1 = two;
0035     T xn0 = three;
0036 
0037     T b1 = one;
0038     T a1 = one;
0039     T b2 = one + ((one + ap) * (z2 / cp));
0040     T a2 = b2 - ct1;
0041     T b3 = one + ((two + b2) * (((two + ap) / three) * ct2));
0042     T a3 = b3 - ((one + ct2) * ct1);
0043     ct1 = three;
0044 
0045     const unsigned max_iterations = boost::math::policies::get_max_series_iterations<Policy>();
0046 
0047     T a4 = T(0), b4 = T(0);
0048     T result = T(0), prev_result = a3 / b3;
0049 
0050     for (unsigned k = 2; k < max_iterations; ++k)
0051     {
0052       // Luke: C ----- CALCULATION OF THE MULTIPLIERS -----
0053       // Luke: C ----------- FOR THE RECURSION ------------
0054       ct2 = (z2 / ct1) / (cp + xn1);
0055       const T g1 = one + (ct2 * (xn2 - ap));
0056       ct2 *= ((ap + xn1) / (cp + xn2));
0057       const T g2 = ct2 * ((cp - xn1) + (((ap + xn0) / (ct1 + two)) * z2));
0058       const T g3 = ((ct2 * z2) * (((z2 / ct1) / (ct1 - two)) * ((ap + xn2)) / (cp + xn3))) * (ap - xn2);
0059 
0060       // Luke: C ------- THE RECURRENCE RELATIONS ---------
0061       // Luke: C ------------ ARE AS FOLLOWS --------------
0062       b4 = (g1 * b3) + (g2 * b2) + (g3 * b1);
0063       a4 = (g1 * a3) + (g2 * a2) + (g3 * a1);
0064 
0065       prev_result = result;
0066       result = a4 / b4;
0067 
0068       // condition for interruption
0069       if ((fabs(result) * boost::math::tools::epsilon<T>()) > fabs(result - prev_result) / fabs(result))
0070         break;
0071 
0072       b1 = b2; b2 = b3; b3 = b4;
0073       a1 = a2; a2 = a3; a3 = a4;
0074 
0075       xn3 = xn2; 
0076       xn2 = xn1; 
0077       xn1 = xn0; 
0078       xn0 += 1;
0079       ct1 += two;
0080     }
0081 
0082     return result;
0083   }
0084 
0085   // Luke: C ----- SUBROUTINE R2F1P(AB, BP, CP, Z, A, B, N) -------
0086   // Luke: C -- RATIONAL APPROXIMATION OF 2F1( AB , BP; CP ; -Z ) -
0087   template <class T, class Policy>
0088   inline T hypergeometric_2F1_rational(const T& ap, const T& bp, const T& cp, const T& zp, const unsigned n, const Policy& )
0089   {
0090     BOOST_MATH_STD_USING
0091 
0092     static const T one = T(1), two = T(2), three = T(3), four = T(4),
0093                    six = T(6), half_7 = T(3.5), half_3 = T(1.5), forth_3 = T(0.75);
0094 
0095     // Luke: C ------------- INITIALIZATION -------------
0096     const T z = -zp;
0097     const T z2 = z / two;
0098 
0099     T sabz = (ap + bp) * z;
0100     const T ab = ap * bp;
0101     const T abz = ab * z;
0102     const T abz1 = z + (abz + sabz);
0103     const T abz2 = abz1 + (sabz + (three * z));
0104     const T cp1 = cp + one;
0105     const T ct1 = cp1 + cp1;
0106 
0107     T b1 = one;
0108     T a1 = one;
0109     T b2 = one + (abz1 / (cp + cp));
0110     T a2 = b2 - (abz / cp);
0111     T b3 = one + ((abz2 / ct1) * (one + (abz1 / ((-six) + (three * ct1)))));
0112     T a3 = b3 - ((abz / cp) * (one + ((abz2 - abz1) / ct1)));
0113     sabz /= four;
0114 
0115     const T abz1_div_4 = abz1 / four;
0116     const T cp1_inc = cp1 + one;
0117     const T cp1_mul_cp1_inc = cp1 * cp1_inc;
0118 
0119     std::array<T, 9u> d = {{
0120       ((half_7 - ab) * z2) - sabz,
0121       abz1_div_4,
0122       abz1_div_4 - (two * sabz),
0123       cp1_inc,
0124       cp1_mul_cp1_inc,
0125       cp * cp1_mul_cp1_inc,
0126       half_3,
0127       forth_3,
0128       forth_3 * z
0129     }};
0130 
0131     T xi = three;
0132     T a4 = T(0), b4 = T(0);
0133     for (unsigned k = 2; k < n; ++k)
0134     {
0135       // Luke: C ----- CALCULATION OF THE MULTIPLIERS -----
0136       // Luke: C ----------- FOR THE RECURSION ------------
0137       T g3 = (d[2] / d[7]) * (d[1] / d[5]);
0138       d[1] += d[8] + sabz;
0139       d[2] += d[8] - sabz;
0140       g3 *= d[1] / d[6];
0141       T g1 = one + (((d[1] + d[0]) / d[6]) / d[3]);
0142       T g2 = (d[1] / d[4]) / d[6];
0143       d[7] += two * d[6];
0144       ++d[6];
0145       g2 *= cp1 - (xi + ((d[2] + d[0]) / d[6]));
0146 
0147       // Luke: C ------- THE RECURRENCE RELATIONS ---------
0148       // Luke: C ------------ ARE AS FOLLOWS --------------
0149       b4 = (g1 * b3) + (g2 * b2) + (g3 * b1);
0150       a4 = (g1 * a3) + (g2 * a2) + (g3 * a1);
0151       b1 = b2; b2 = b3; b3 = b4;
0152       a1 = a2; a2 = a3; a3 = a4;
0153 
0154       d[8] += z2;
0155       d[0] += two * d[8];
0156       d[5] += three * d[4];
0157       d[4] += two * d[3];
0158       ++d[3];
0159       ++xi;
0160     }
0161 
0162     return a4 / b4;
0163   }
0164 
0165   } } } // namespaces
0166 
0167 #endif // BOOST_MATH_HYPERGEOMETRIC_RATIONAL_HPP