We Introduce an Algorithm for the Evaluation of the Incomplete Gamma Function, P (M, X), for All M, X > 0
Total Page:16
File Type:pdf, Size:1020Kb
We introduce an algorithm for the evaluation of the Incomplete Gamma Function, P (m; x), for all m; x > 0. For small m, a classical recursive scheme is used to evaluate P (m; x), whereas a newly derived asymptotic expansion is used to evaluate P (m; x) in the large m regime. The number of operations required for evaluation is O(1) for all x and m. Nearly full double and extended precision accuracies are achieved in their respective environments. The performance of the scheme is illustrated via several numerical examples. An Algorithm for the Evaluation of the Incomplete Gamma Function P. Greengardz , V. Rokhlinz , Technical Report YALEU/DCS/TR-1534 June 20, 2017 This author's work was supported in part under ONR N00014-14-1-0797, AFOSR FA9550- 16-0175, NIH 1R01HG008383 This author's work was supported in part under ONR N00014-14-1-0797, NSF DMS- 1300120 z Dept. of Mathematics, Yale University, New Haven CT 06511 Approved for public release: distribution is unlimited. Keywords: Incomplete Gamma Function, Special Functions, Numerical Evaluation An Algorithm for the Evaluation of the Incomplete Gamma Function Philip Greengard, Vladimir Rokhlin June 20, 2017 Contents 1 Introduction 3 2 Preliminaries 3 2.1 Mathematical Apparatus . .5 2.2 P (m; x) for Small x ............................... 10 2.3 P (m; x) for large x ................................ 10 3 Evaluation of P (m; x) by Summation 13 4 Evaluation of P (m; x) by Asymptotic Expansion 14 5 Description of Algorithm 18 5.1 m ≤ 10; 000.................................... 18 5.2 m > 10; 000.................................... 19 5.2.1 Precomputing . 19 5.2.2 Evaluation . 20 6 Numerical Experiments 20 2 1 Introduction Properties and evaluation of special functions is one of the most developed areas of nu- merical analysis. For some (such as Bessel functions), the theory has been fairly complete for many decades; others (such as Prolate Spheroidal Wave Functions) are still an active area of research. In this respect, the Incomplete Gamma Function occupies an intermediate position. Its mathematical properies appear to be well understood, but the relevant numer- ical techniques leave much to be desired, at least in certain regimes. The purpose of this paper is to introduce a numerical scheme (or rather a class of numerical schemes) for the evaluation of the Incomplete Gamma Functions that produces (more or less) full double pre- cisoion accuracy whenever the calculations are performed in double precision, is sufficiently fast to be compatible with standard schemes for the evaluation of other special functions, and produces roughly extended precision accuracy when implemented in extended precision (though in this regime, the algorithm loses much of its efficiency). The algorithm is based on the combination of an identity concerning the Incomplete Gamma Function (see [1] for- mula 6.5.22), with an asymptotic expansion that appears to be new (see [4], [5], [2], [7] , [8] below); its performance is illustrated with several numerical examples, in both double and extended precision (see Section 6). The structure of this paper is as follows. In Section 2, we introduce notation and sum- marize a number of elementary mathematical results to be used throughout the remainder of the paper. Section 3 describes a technique for the evaluation of P (m; x) via direct sum- mation. Section 4 describes an asymptotic expansion for the evaluation of P (m; x). Section 5 contains a description of an algorithm to evaluate P (m; x) for all m; x > 0. Section 6 contains the results of numerical experiments with the algorithm for P (m; x) described in Section 5. 2 Preliminaries In accordance with standard practice, we will be denoting by γ(m; x) the Incomplete Gamma Function, Z x γ(m + 1; x) = tme−tdt: (1) 0 We will be denoting by γ(m; x) a scaled version of the Incomplete Gamma Function, Z x tme−t γ(m + 1; x) = m −m dt 0 m e Z x−m (2) = eφ(s)ds −m where (m + s)me−(m+s) eφ(s) = : (3) mme−m We will be denoting by P (m; x) (see [1]), the Incomplete Gamma Function scaled by the Complete Gamma Function. That is, γ(m; x) (m − 1)(m−1)e−(m−1) P (m; x) = = γ(m; x): (4) Γ(m) Γ(m) 3 We define fm to be the function on C defined by the formula, 2 fm(z) = exp m log(1 + z=m) − z + z =2m (5) and observe that φ(s) s2=2m e = fm(s)e : (6) Consistent with standard practice, we denote by Γ(m) the Complete Gamma Function, Z 1 Γ(m + 1) = tme−tdt: (7) 0 We will be denoting by Γ(m), the scaled version of Γ(m), Z 1 tme−t Γ(m + 1) = m −m dt: (8) 0 m e The following lemma, Stirling's Approximation, is a classical asymptotic expansion for the Gamma Function, Γ(m) (see (7)). It can be found in, [6], Formula 6.1.37, for example. Proofs for bounds on the error terms for Stirling's Appromxation that are provided in Lemma 2.1 can be found in, for example, [9]. Lemma 2.1. [Stirling's Approximation] For all m > 0, 1 1 139 Γ(m) ∼e−mmm−1=2(2π)1=2 1 + + − + ::: 12m 288m2 51840m3 1 (9) −m m−1=2 1=2 X =e m (2π) gk(m); k=0 where formulas for gk(m) can be found in [10]. Further, for K > 2, if K−1 ! −m m−1=2 1=2 X Γ(m) = e m (2π) gk(m) + RK (m) (10) k=0 then Γ(K) jR (m)j< : (11) K (K + 1)mK Additionally, 1 1 1 ln(Γ(m)) ∼ (m − 1=2) ln(m) − m + 1=2 ln(2π) + − + + ::: 12m 360m3 1260m5 1 (12) X = (m − 1=2) ln(m) − m + 1=2 ln(2π) + hk(m) k=0 where ln(x) is the natural logarithm, and formulas for hk(m) can be found in, for example, [1]. Further, suppose K−1 X ln(Γ(m)) = (m − 1=2) ln(m) − m + 1=2 ln(2π) + hk(m) + RK (m): (13) k=0 4 Then, jB j jR (m)|≤ 2K (14) K (2K − 1)m2K−1 th where Bn is n Bernoulli number (see [1]). In addition, jRK (m)j is smaller in magnitude than the first neglected term (see [9]). The following bound for Γ(m) will be used throughout the remainder of the paper. Observation 2.1. Straightforward application of Stirling's Approximation (see (9)) shows that for m > 1, Γ(m + 1) > mm+1=2e−m > 0: (15) It follows immediately from (15) that for m > 1, mme−m 0 < < m−1=2 (16) Γ(m + 1) The following lemma will help in the proof of Lemma 2.3. It is a well known inequality. A proof can be found in, for example, Section VII of [3]. Lemma 2.2. For all x; σ > 0, −σx −x2=2 1 Z 2 2 1 e e−t =2σ dt < : (17) 2 1=2 1=2 (2πσ ) −∞ x (2π) 2.1 Mathematical Apparatus In this subsection, the main analytical tools are Lemma 2.8 and Corollary 2.1. They will be used in Sections 2.2 and 2.3. All other apparatus will be used in support of Lemma 2.8 and Corollary 2.1 or in Sections 2.2, 2.3, 3, and 4. We use the following lemma in the proof of Lemma 2.9. Lemma 2.3. For all α; m > 0, m−αm1=2 −α2=2+1 Z 2 1 e m−1=2e−(t−m) =2m+1dt < : (18) 1=2 0 α (2π) Proof. Clearly, m−αm1=2 m−αm1=2 Z 2 Z 2 m−1=2e−(t−m) =2m+1dt = em−1=2 e−(t−m) =2mdt 0 0 m−αm1=2 Z 2 < em−1=2 e−(t−m) =2mdt (19) −∞ −αm1=2 Z 2 = em−1=2 e−t =2mdt: −∞ Applying Lemma 2.2 to (19), −αm1=2 Z 2 1 2 em−1=2 e−(t) =2mdt < e−α =2+1 (20) −∞ α (18) follows immediately from the combination of (19) and (20). 5 The following lemma will be used in the proof of Lemma 2.7. Lemma 2.4. Let fang be a non-negative, monotonically decreasing sequence in R. Then, 1 X n+1 (−1) an ≤ a1: (21) n=1 Proof. Clearly, since fang is monotonically decreasing, for all i 2 N, ai − ai+1 ≥ 0: (22) therefore, 1 1 X n+1 X (−1) an = (an − an+1) ≥ 0: (23) n=1 n=1 Combining (22) and (23) yields, 1 1 X n+1 X 0 ≤ (−1) an = a1 − (an − an+1) ≤ a1: (24) n=1 n=2 (21) follows from (24). Lemma 2.5 and Lemma 2.4 will be used in Section 5. Lemma 2.5. For all n 2 N and m > 0, Z 2 2 t2n+1e−t =2mdt = 2e−t =2m(−2mx2n+2− n+1 (25) X (2m)k+1(n + 1)(n):::(n − k + 2)x2(n+1−k)) k=1 Proof. By the change of variables x = t2, b b2 Z 2 Z t2n+1e−t =2mdt = 2 xn+1e−x=2mdx: (26) a a2 From Formula 2.432.2 in [6] we know n ! Z X xne−x=2mdx = e−x=2m −2mxn − (2m)k+1n(n − 1):::(n − k + 1)xn−k : (27) k=1 Combining (26) and (27) yields (25). Lemma 2.6. For all n 2 N and m > 0 0 1 Z n p n−1 n−i 2 Y π t X Y t2n+2e−t =2mdt = α (2m)1=2 erf p − β α − β ; (28) i 2 @ i n−jA n i=0 2m i=0 j=0 where αi = (2i + 1)m (29) 6 and 2i+1 −t2=2m βi = mt e (30) and in accordance with standard practice, x 2 Z 2 erf(x) = p e−t dt: (31) π 0 Proof.