2 ///////////////////////////////////////////////////////////////////////////////
3 // Copyright 2014 Anton Bikineev
4 // Copyright 2014 Christopher Kormanyos
5 // Copyright 2014 John Maddock
6 // Copyright 2014 Paul Bristow
7 // Distributed under the Boost
8 // Software License, Version 1.0. (See accompanying file
9 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_MATH_HYPERGEOMETRIC_PADE_HPP
12 #define BOOST_MATH_HYPERGEOMETRIC_PADE_HPP
14 namespace boost{ namespace math{ namespace detail{
16 // Luke: C ---------- SUBROUTINE R1F1P(CP, Z, A, B, N) ----------
17 // Luke: C ----- PADE APPROXIMATION OF 1F1( 1 ; CP ; -Z ) -------
18 template <class T, class Policy>
19 inline T hypergeometric_1F1_pade(const T& cp, const T& zp, const Policy& )
23 static const T one = T(1);
25 // Luke: C ------------- INITIALIZATION -------------
34 T b1 = one + (z / ct1);
37 const unsigned max_iterations = boost::math::policies::get_max_series_iterations<Policy>();
39 T b2 = T(0), a2 = T(0);
40 T result = T(0), prev_result;
42 for (unsigned k = 1; k < max_iterations; ++k)
44 // Luke: C ----- CALCULATION OF THE MULTIPLIERS -----
45 // Luke: C ----------- FOR THE RECURSION ------------
46 const T ct2 = ct1 * ct1;
47 const T g1 = one + ((cp1 / (ct2 + ct1 + ct1)) * z);
48 const T g2 = ((xi1 / (ct2 - one)) * ((xi1 + cp1) / ct2)) * zz;
50 // Luke: C ------- THE RECURRENCE RELATIONS ---------
51 // Luke: C ------------ ARE AS FOLLOWS --------------
52 b2 = (g1 * b1) + (g2 * b0);
53 a2 = (g1 * a1) + (g2 * a0);
58 // condition for interruption
59 if ((fabs(result) * boost::math::tools::epsilon<T>()) > fabs(result - prev_result))
72 // Luke: C -------- SUBROUTINE R2F1P(BP, CP, Z, A, B, N) --------
73 // Luke: C ---- PADE APPROXIMATION OF 2F1( 1 , BP; CP ; -Z ) ----
74 template <class T, class Policy>
75 inline T hypergeometric_2F1_pade(const T& bp, const T& cp, const T& zp, const Policy& pol)
79 static const T one = T(1);
81 // Luke: C ---------- INITIALIZATION -----------
88 const T b1c1 = (cp - one) * (bp - one);
90 T b1 = one + ((z / (cp + one)) * (bp + one));
91 T a1 = b1 - ((bp / cp) * z);
93 const unsigned max_iterations = boost::math::policies::get_max_series_iterations<Policy>();
95 T b2 = T(0), a2 = T(0);
96 T result = T(0), prev_result = a1 / b1;
98 for (unsigned k = 1; k < max_iterations; ++k)
100 // Luke: C ----- CALCULATION OF THE MULTIPLIERS -----
101 // Luke: C ----------- FOR THE RECURSION ------------
102 const T ct2 = ct1 + xi1;
103 const T ct3 = ct2 * ct2;
104 const T g2 = (((((ct1 / ct3) * (bp - ct1)) / (ct3 - one)) * xi1) * (bp + xi1)) * zz;
106 const T g1 = one + (((((xi1 + xi1) * ct1) + b1c1) / (ct3 + ct2 + ct2)) * z);
108 // Luke: C ------- THE RECURRENCE RELATIONS ---------
109 // Luke: C ------------ ARE AS FOLLOWS --------------
110 b2 = (g1 * b1) + (g2 * b0);
111 a2 = (g1 * a1) + (g2 * a0);
113 prev_result = result;
116 // condition for interruption
117 if ((fabs(result) * boost::math::tools::epsilon<T>()) > fabs(result - prev_result))
131 #endif // BOOST_MATH_HYPERGEOMETRIC_PADE_HPP