Numerical Methods for the Computation of the Confluent and Gauss Hypergeometric Functions
Total Page:16
File Type:pdf, Size:1020Kb
Numer Algor DOI 10.1007/s11075-016-0173-0 ORIGINAL PAPER Numerical methods for the computation of the confluent and Gauss hypergeometric functions John W. Pearson1 · Sheehan Olver2 · Mason A. Porter3 Received: 27 August 2015 / Accepted: 29 June 2016 © Springer Science+Business Media New York 2016 Abstract The two most commonly used hypergeometric functions are the conflu- ent hypergeometric function and the Gauss hypergeometric function. We review the available techniques for accurate, fast, and reliable computation of these two hyper- geometric functions in different parameter and variable regimes. The methods that we investigate include Taylor and asymptotic series computations, Gauss–Jacobi quadra- ture, numerical solution of differential equations, recurrence relations, and others. We discuss the results of numerical experiments used to determine the best methods, in practice, for each parameter and variable regime considered. We provide “roadmaps” with our recommendation for which methods should be used in each situation. Keywords Computation of special functions · Confluent hypergeometric function · Gauss hypergeometric function This work was supported by the Numerical Algorithms Group (NAG) and the Engineering and Physical Sciences Research Council (EPSRC). John W. Pearson [email protected] Sheehan Olver [email protected] Mason A. Porter [email protected] 1 School of Mathematics, Statistics and Actuarial Science, University of Kent, Cornwallis Building (East), Canterbury, Kent, CT2 7NF, UK 2 School of Mathematics and Statistics, The University of Sydney, NSW 2006, Sydney, Australia 3 Oxford Centre for Industrial and Applied Mathematics, Mathematical Institute, University of Oxford, Andrew Wiles Building, Radcliffe Observatory Quarter, Woodstock Road, Oxford, OX2 6GG, UK Numer Algor Mathematics Subject Classification (2010) Primary: 33C05 · 33C15 · Secondary: 41A58 · 41A60 1 Introduction The aim of this review paper is to summarize methods for computing the two most commonly used hypergeometric functions: the confluent hypergeometric function M(a; b, z) and the Gauss hypergeometric function F(a, b; c; z). (We also consider the associated functions 1F1(a; b; z) and 2F1(a, b; c; z).) We overview methods that have been developed for computing M and F, and we discuss how to choose appropri- ate methods for different parameter and variable regimes. We thereby obtain reliable and fast computation for a large range of the parameters (a and b for M;anda, b,and c for F) and the variable z. Because accurate error bounds are seldomly available, we test a large variety of approaches, which we require to be stable, accurate, fast, and robust within the parameter and variable regions for which they have been selected. This is especially important when working with finite-precision arithmetic. The computation of confluent hypergeometric functions and Gauss hypergeomet- ric functions is important in a wide variety of applications [87]. For instance, these functions arise in areas such as photon scattering from atoms [27], networks [79, 100], Coulomb wave functions [8, 21, 67], binary stars [81], mathematical finance [10], non-Newtonian fluids [109], and more. Except for specific situations, computing hypergeometric functions is difficult in practice. A plethora of methods exist for computing each hypergeometric function; these include Taylor series, asymptotic expansions, continued fractions, recurrence relationships, hyperasymptotic expansions, and more. However, each method is only reliable and efficient for limited parameter and variable regimes. Consequently, one must be prepared to use different members of this suite of possibilities in different regimes of parameter and variable values. We have also developed MATLAB code for computing the functions M and F using a range of methods; our code is publicly available [116]. 2 Background on hypergeometric functions The confluent hypergeometric function is defined by [110, Eq. (13.2.3)] ∞ j (a)j z M(a; b; z) = , (2.1) (b + j) j! j=0 where the Pochhammer symbol (μ)j is (μ)0 = 1 ,(μ)j = μ(μ + 1) ×···×(μ + j − 1), j = 1, 2,... The function M is entire (i.e., it is analytic throughout the complex plane C)inthe parameters a and b and the variable z. Therefore, the sum (2.1) always converges. Numer Algor When b is not a non-positive integer, we define ∞ j (a)j z 1F1(a; b; z) = (b)M(a; b; z) = , (b)j j! j=0 which is also commonly denoted by M(a; b; z) and is itself often called the confluent hypergeometric function. Because 1F1(a; b; z) is not defined if b is equal to a non- positive integer and there are numerical issues in its computation if b is close to a non-positive integer, it is preferable to compute M when possible. The Gauss hypergeometric function is defined within the unit disk |z| < 1by [110, Eq. (15.2.2)] ∞ j (a)j (b)j z F(a, b; c; z) = (2.2) (c + j) j! j=0 and defined outside the unit disk by analytic continuation, with a principal branch cut along [1, ∞).On[1, ∞), it is defined to be continuous from below. That is, F(a, b; c; z) = lim→0 F(a, b; c; z −||i).Whenc is not a non-positive integer, we define ⎛ ⎞ ∞ j ⎝ (a)j (b)j z ⎠ 2F1(a, b; c; z) = (c)F(a, b; c; z) = for |z| < 1 . (2.3) (c)j j! j=0 The function 2F1(a, b; c; z) is commonly denoted by F(a,b; c; z) and is also fre- quently called the Gauss hypergeometric function. Analogous to the case for the confluent hypergeometric function, it is better numerically to compute F than to compute 2F1. The confluent hypergeometric function 1F1(a; b; z) satisfies the ordinary differ- ential equation [90] d2f df z + (b − z) − af = 0 , (2.4) dz2 dz and the Gauss hypergeometric function 2F1(a, b; c; z) satisfies [91] d2f df z(1 − z) +[c − (a + b + 1)z] − abf = 0 . (2.5) dz2 dz The confluent and Gauss hypergeometric functions are examples of special func- tions, whose theory and computation are prominent in the scientific literature [3, 6, 40, 53, 57, 58, 62, 73, 95, 97, 108]. A large number of common mathematical func- tions (including ez, (1−z)−a,andsin−1 z [3, 57]) and many special functions (such as the modified Bessel function, the incomplete gamma and error functions, Chebyshev and Legendre polynomials, and other families of orthogonal polynomials [3, 5, 60, 85]) can be expressed in terms of confluent or Gauss hypergeometric functions. In Figs. 1 and 2, we show plots of hypergeometric functions. These provide exam- ples of the possible shapes of such functions in the real and complex planes, though of course there are a wide range of possible representations of them. As we indicated above, the computation of hypergeometric functions arises in a wide variety of applications. This underscores the importance of determining which Numer Algor 100 4 3 50 2 (a;b;z) (a,b;c;z) 1 1 F 0 F 1 1 2 0 −50 −5 0 5 −1 −0.5 0 0.5 1 z z Fig. 1 (Color online) (Left) Plots of 1F1(a; b; z), generated using MATLAB [111], for real z ∈[−5, 5] with parameter values (a, b) = (0.1, 0.2) in dark blue (dotted), (a, b) = (−3.8, 1.5) in red (dashed), and (a, b) = (−3, −2.5) in green (solid). (Right) Plots of 2F1 for real z ∈[−1, 1] with parameter val- ues (a,b,c) = (0.1, 0.2, 0.4) in black (dotted), (a,b,c) = (−3.6, −0.7, −2.5) in purple (dashed), and (a,b,c)= (−5, 1.5, 6.2) in sky blue (solid) computational techniques are accurate and efficient for different parameter and vari- able regimes. It is also important to supply information on how to test the reliability of a routine, provide test cases that a routine might have difficulty computing (see Appendix A), and indicate how to evaluate other special functions required for the computation of hypergeometric functions (see Appendix C). As illustrated in Ref. [80], the inbuilt routines to compute hypergeometric functions in commercial soft- ware packages such as MATLAB R2015a [111] and Mathematica 8 [112] are not without limitations, so one should not rely on them in many parameter and vari- able regimes. We have implemented our routines for MATLAB R2015a, which uses double-precision arithmetic, and we have made it freely available online [116]. Of course, it is easier to obtain accurate results when computing these functions in higher-precision arithmetic, as is done when the inbuilt hypergeometric function commands in MATLAB and MATHEMATICA are called. Our code can be modified to run in higher precision. 100 60 40 50 (a;b;z)| (a,b;c;z)| 1 20 1 F F 1 | 2 0 | 0 5 5 5 5 0 0 0 0 Im(z) −5 −5 Re(z) Im(z) −5 −5 Re(z) 2 Fig. 2 (Color online) (Left)Plotof|1F1(a; b; z)| for(Re(z), Im(z)) ∈[−5, 5] with parameter val- 2 ues (a, b) = (−3 − 2i, 2.5).(Right)Plotof|2F1| for Re(z), Im(z) ∈[−5, 5] with parameter values (a,b,c)= (1 + 2i, −1.5, 0.5 − i) Numer Algor 3 Computation of the confluent hypergeometric function M In this section, we discuss the methods that perform the best in practice for accu- rately and efficiently evaluating the confluent hypergeometric function. The range of methods that we discuss includes series computation methods (Sections 3.2, 3.3, and 3.4), quadrature methods (Section 3.5), recurrence relations (Section 3.6), and other methods (Section 3.7). In Section 3.8, we summarize the computational strate- gies and provide recommendations for the most effective approaches for a variety of parameter regimes.