Computing the Principal Branch of log-Gamma

by

D.E.G. Hare Symbolic Computation Group Department of Computer Science University of Waterloo Waterloo, Canada Revised: August 11, 1994

Abstract

The log-Gamma function is an important special function of mathematics, and its principal branch is required in many applications. We develop here the mathematics required to evaluate the principal branch to arbitrary precision, including a new bound for the error in Stirling’s asymptotic series. We conclude with a discussion of the implementation of the principal branch of the log-Gamma function in the Maple symbolic algebra system, starting with version Maple V Release 3.

AMS Subject Classification (1991): Primary: 65D20; Secondary: 33B15, 68Q40 Keywords: log-Gamma, Gamma, Maple This research was supported in part by The Natural Sciences and Engineering Research Council of Canada and by the Information Technology Research Centre of Ontario, and was carried out, in part, while the author was a visitor at the University of New South Wales, Sydney, Australia.

D.E.G. Hare Computing the Principal Branch of lnΓ

1. Introduction

The familiar formula of Stirling, which provides a series asymptotic to Γ(z), as z → ∞ in |arg z| < π suffers from a lack of an expression for the general term. This deficiency is readily overcome by considering instead the log-Gamma function:

Definition 1.1 The log-Gamma function is defined by lnΓ(x) = ln(Γ(x)) for real x > 0 and by analytic continuation into the complex plane.

Before presenting the promised asymptotic expansion for this function we must define its principal branch.

The presence of the logarithm in Definition 1.1 means that lnΓ will have a branch point at each point z where Γ(z) is either 0 or infinite. Γ(z) is never 0, but Γ has a simple pole at each of the negative integers and 0. Hence lnΓ has a branch point at each of these points. Therefore, in order to specify a branch of lnΓ it is necessary to assign a branch cut extending from each such point to infinity (a curve whose complement in the complex plane is simply connected).

Definition 1.2 The Principal Branch of the log-Gamma function is defined by taking the principal branch of the logarithm in Definition 1.1, and by taking as the branch cut from each non-positive integer the part of the negative real axis extending from that point to negative infinity. Furthermore, the principal branch of log-Gamma is defined on the negative real axis (less the negative integers) in such a way as to make it continuous in the direction of increasing complex argument.

Note that this definition of the principal branch of lnΓ, and in particular the assignment of values for lnΓ(z) for z on the branch cut, is consistent with the following identities:

lnΓ(z) = − ln z − γz − ∑_{n=1}^{∞} ln(1 + z/n) − z/n  [3, ex. 7.7.4]
lnΓ(z) = \frac{d}{ds}ζ(s, z)|_{s=0} + 1/2 ln(2π)  [5, 1.11(10)]

D.E.G. Hare Computing the Principal Branch of lnΓ where γ is Euler’s constant and ζ(s, z) is the Hurwitz ζ function ([5, §1.10]). The first of these identities is taken in [9, §12.31] to be the definition of the principal branch of the log-Gamma function.

For the remainder of this paper, the name lnΓ will always refer to the principal branch of log-Gamma. Similarly, ln will refer to the principal branch of the logarithm function, and, consistently with this, the argument function, z ↦ arg z, will be taken to be valued in (−π, π].

Since the exponential function is entire and lnΓ and Γ are analytic on their domains (which are the same, as noted above), and since the identity exp(lnΓ(z)) = exp(ln(Γ(z))) = Γ(z) holds for real z > 0, it follows by the Identity Theorem [3, IV.3.8] that this identity holds for all z in the domain of lnΓ, and hence that the various branches of the log-Gamma function, evaluated at any given point z, must differ by integer multiples of 2πi. Alternatively, this can be seen by exponentiating the first of the identities above and observing that the result is the Euler product for Γ(z) [1, 6.1.3].

We will see, in Corollary 3.2 below, that if x < 0 then

lnΓ(x) = ln(Γ(x)) + 2πi⌈x/2 − 1⌉

showing that lnΓ(x) ≠ ln(Γ(x)) for most such x.

For general complex z, this inequivalence follows from the observation that Γ maps lines with constant real part to curves which wind around the origin. If we use polar coordinates for the moment, writing Γ(z) = r(z)e^{θ(z)}, where θ(z) is continuous, with θ(x) = 0 for x a positive real number (i.e., we do not restrict the range of θ to (−π, π]), then from Stirling’s formula [1, 6.1.37], we have, for large ℑ(z), θ(z) ≈ (ℜ(z) − 1/2) arg z + ℑ(z)(ln |z| − 1). This latter expression is clearly unbounded (particularly in the case when ℜ(z) is constant), and so is not generally valued in (−π, π], which it would have to be for lnΓ(z) to equal ln(Γ(z)) (note that r(z) is an exponential for large |z|, again by Stirling’s formula, and so is positive).

Returning now to the discussion with which we opened this section, the asymptotic series for lnΓ, usually known as Stirling’s series, is [1, 6.1.40]

lnΓ(z) ∼ (z − 1/2) ln z − z + \frac{1}{2} ln(2π) + ∑_{n=1}^{∞} \frac{B_{2n}}{2n(2n − 1)z^{2n−1}}  (1.1)

D.E.G. Hare Computing the Principal Branch of lnΓ as z → ∞ in |arg z| < π − δ, where δ > 0 and B_{k} is the k^{th} Bernoulli number [1, ch. 23].

For the purpose of computing Γ(z) by this method, the remarks following Definition 1.2 show that it doesn’t matter which branch of lnΓ(z) is computed at any given value of z. However, lnΓ is a classical function of interest in its own right, and there are many and varied situations in which the principal branch of lnΓ must be evaluated. To cite just two examples, this is used in the standard methods for locating the zeros of the Riemann ζ function (see, for example, [4, §6.5]), and also in [7], where evaluation of the principal branch of lnΓ on the imaginary axis is required.

Abramowitz and Stegun have tabulated the principal branch of lnΓ for some values [1, Table 6.7] (it is clear again, from this table, that lnΓ(z) ≠ ln(Γ(z)) in general). That tabulation is brief and sparse, of course, and there are intricacies involved in attempting to extend the table, particularly into the half plane ℜ(z) < 0 or to higher precision. Furthermore, while many papers include a statement to the effect that the results obtained therein require the principal branch of lnΓ, to the best of this author’s knowledge the details of the mathematics of this function have not before been published.

2. Computation of lnΓ(z) Using the Asymptotic Series

The choice of algorithms for computing approximations to lnΓ(z) for general complex z is fairly limited. The coefficients in the series expansions at integer points of either lnΓ(z) or Γ(z) involve the Riemann ζ function (see, for example, [1, 6.1.33]), making such series attractive only for values of z very close to the expansion point. Rational or polynomial approximations are quite good for limited precision computations and for values of z which are not too large. The identities cited at the end of §1 are both quite poor for numerical purposes.

For values of z which are far from the origin, the asymptotic expansion (1.1) is quite attractive, as the coefficients are given by explicit formulae and hence an algorithm based on (1.1) is scalable to arbitrary precision (at least for sufficiently large values of z). Of course, (1.1) is a divergent series, which limits the accuracy obtainable at a particular point z. Fortunately, there is a recurrence relation which can be used to shift any given z D.E.G. Hare Computing the Principal Branch of lnΓ into the region where (1.1) can be applied. Starting from Γ(z + 1) = zΓ(z) [1, 6.1.15], we take logarithms (using the principal branch of the logarithm, as usual), to get

Proposition 2.1 (Recurrence relation for lnΓ) If z is any complex number in the domain of lnΓ, then lnΓ(z + 1) = ln(z) + lnΓ(z).

The point of this proposition is that no correction term involving a multiple of 2πi is required to stay on the principal branch.

Proof That the result is true for real z > 0 follows from the definition of the principal branch of lnΓ and the fact that z > 0 implies Γ(z) > 0.

The function z ↦ lnΓ(z + 1) − ln z − lnΓ(z) is analytic on C \ (−∞, 0], and is 0 on the positive real axis. Thus, by the Identity Theorem [3, IV.3.8], the proposition is true for z ∈ C \ (−∞, 0].

Since the functions ln and lnΓ are continuous from above onto the negative real axis (less the negative integers), the result holds as well for z < 0, z not an integer. (This latter case can also be seen directly as a consequence of Corollary 3.3 below.)

Proposition 2.2 (Multiple shift recurrence relation for lnΓ) Let n be a positive integer, let z ∈ C \ (−∞, 0] with ℑ(z) ≥ 0, let either

p(z, n) = z(z + 1)(z + 2)(…)(z + n − 1) ,  z_{(n)} = z + n ,  s = 1

or

p(z, n) = (z − 1)(z − 2)(…)(z − n) ,  z_{(n)} = z − n ,  s = −1

and let k(z, n) be the number of times the imaginary parts of the accumulating products forming p(z, n) (z, z(z + 1), etc, or (z − 1), (z − 1)(z − 2), etc) change sign from positive (or 0) to negative. Then

lnΓ(z_{(n)}) = lnΓ(z) + s(ln(p(z, n)) + 2k(z, n)πi) .

The case ℑ(z) < 0 can be handled by observing that since Γ is conjugate symmetric and ln is conjugate symmetric off the negative real axis, lnΓ(z) = \overline{lnΓ(\overline{z})} if z is not a negative real number.

D.E.G. Hare Computing the Principal Branch of lnΓ Proof Consider first the case p(z, n) = z(z + 1)(…)(z + n − 1), z_{(n)} = z + n and s = 1. Applying Proposition 2.1 iteratively, we obtain

lnΓ(z_{(n)}) = lnΓ(z + n)
= ln(z + n − 1) + lnΓ(z + n − 1)
= ln(z + n − 1) + ln(z + n − 2) + lnΓ(z + n − 2)
= …
= ln(z + n − 1) + ln(z + n − 2) + … + ln(z + 1) + ln(z) + lnΓ(z)
= ln(p(z, n)) + 2mπi + lnΓ(z)

where m is an integer depending on z and n. It now follows easily from the multiplication rule for the principal branch of the logarithm, namely,

ln(uv) = ln u + ln v + \{ \begin{matrix}0 & if −π < arg u + arg v ≤ π \\ −2πi & if arg u + arg v > π \\ 2πi & if arg u + arg v ≤ −π \end{matrix}

that m = k(z, n).

The remaining case is similar.

The correction term in Proposition 2.2, k(z, n), computes the difference between the sum of the logarithms of the factors of p(z, n) and ln(p(z, n)). The value of the proposition is that it provides an algorithm for determining this difference without having to compute the individual component logarithms (or, more precisely, their imaginary parts, which would require the computation of the corresponding arctangents).

Employing Proposition 2.2 in such a way as to increase either |z| or ℜ(z), one can translate z into the region where (1.1) can be used to compute to the required accuracy. We thus immediately have

Corollary 2.3 With the notation of Proposition 2.2,

lnΓ(z) ∼ (z_{(n)} − \frac{1}{2}) ln z_{(n)} − z_{(n)} + \frac{1}{2} ln(2π) + ∑_{m=1}^{∞} \frac{B_{2m}}{2m(2m − 1)z_{(n)}^{2m−1}} − s(ln p + 2k(z, n)πi)

as z_{(n)} → ∞ in |arg z_{(n)}| < π − δ, where δ > 0.

3. Computation of lnΓ(z) Using the Reflection Formula

The asymptotic series (1.1) does not approximate lnΓ on the negative real axis. This is easily seen by noting that since Γ(z) is real for z on the negative real axis (except for poles at each of the non-positive integers), ℑ(lnΓ(z)) must be a (constant) multiple of π on each interval (j − 1, j) for integer j. However, the series (1.1) clearly has no such property, since the imaginary part of (1.1) for z a negative real number is precisely (z − 1/2)π. (See Corollary 3.2.)

It is also the case that the approximating properties of (1.1) are quite poor for values of z near the negative real axis (see §4).

If ℜ(z) is not too negative, Proposition 2.2 can be used to shift z to the right (i.e., in the direction of increasing ℜ(z)), sufficiently far into the right half plane so that lnΓ(z) can be computed via Corollary 2.3. However, if ℜ(z) ≪ 0 this approach could be prohibitively expensive. In such cases, we can use the logarithmic form of the reflection formula for Γ [1, 6.1.17] to replace z with 1 − z, and then use Corollary 2.3 to evaluate lnΓ(1 − z).

Proposition 3.1 (Reflection formula for lnΓ) If z is a complex number with ℜ(z) < 0, then

lnΓ(z) = ln (\frac{π}{sin πz} ) − lnΓ(1 − z) + 2s(z)k(z)πi

where s(z) = 1 if ℑ(z) ≥ 0 and s(z) = −1 otherwise, and k(z) = ⌈ℜ(z)/2 − 3/4 − δ_{ℑ(z)}/4⌉, where δ_{x} is the Kronecker delta function.

Proof We consider the case ℑ(z) > 0 first.

Observe that k(z) actually depends only on ℜ(z), and not on ℑ(z). To see this, note that k(z) is constant on regions where none of z, 1 − z or sin(πz) cross the negative real axis, which is the branch cut for both ln and lnΓ. Letting z = x + iy, where x < 0 and y > 0, and writing sin(πz) in terms of its real and imaginary parts, we have

\frac{π}{sin(πz)} = π \frac{sin(πx) cosh(πy) − i cos(πx) sinh(πy)}{|sin(πz)|^{2}}  (3.1)

D.E.G. Hare Computing the Principal Branch of lnΓ from which it is clear that the sign of the imaginary part of π/ sin(πz) can change only with x = ℜ(z).

Next, note from equation (3.1) that π/ sin(πz) crosses the negative real axis exactly when ℜ(z) crosses a point of the form 2j − 1/2, for some integer j, as these are the points where cos(πx) = 0 and sin(πx) < 0. Thus, as ℜ(z) varies from across an interval of the form (2j − 1/2, 2j + 3/2], for some integer j, arg(π/ sin(πz)) varies across (−π, π]. Hence k(z) is constant on such intervals, and it suffices to determine the value of k(z) for some particular value of ℜ(z) in each such interval. (We are, of course, only interested in the intervals corresponding to non-positive integers j.)

We will present an overview of the argument first, filling in the details for completeness afterwards.

Let j be a negative integer and let z = 2j + 1/2 + yi, where y is chosen sufficiently large so that the net of the accumulated errors in the following approximations is less than 1/2. Then π/ sin(πz) is real and positive, and by (1.1) we have

\begin{aligned}ℑ(lnΓ(z)) & ≈ ℑ ((2j + yi) ln(2j + 1/2 + yi) − (2j + 1/2 + yi)) \\ & ≈ jπ + y ln y − y \end{aligned}

and

ℑ (ln (\frac{π}{sin(πz)}) − lnΓ(1 − z)) ≈ −ℑ ((−2j − yi) ln(1/2 − 2j − yi) − (1/2 − 2j − yi))
≈ −jπ + y ln y − y

from which it follows that k(z) = j = ⌈ℜ(z)/2 − 3/4⌉.

For preciseness, let ϵ > 0, and choose y > 0 sufficiently large that the following conditions hold (recall that ℑ(ln(π/ sin(πz))) = 0):

|ℑ(lnΓ(z) − ((z − 1/2) ln z − z))| < ϵ/6
|ℑ(lnΓ(1 − z) + ((1/2 − z) ln(1 − z) − (1 − z)))| < ϵ/6
0 < arg z − π/2 < ϵ/(6j)
0 < π/2 + arg(1 − z) < ϵ/(6j)

D.E.G. Hare Computing the Principal Branch of lnΓ

0 < y ln (\frac{|z|}{|1 − z|}) < ϵ/3

(The last of these is easily seen to be possible by an application of L’Hôpital’s Rule.) Then

ℑ(lnΓ(z)) = ℑ((z − 1/2) ln z − z) + δ_{1}
= 2j arg z + y ln |z| − y + δ_{1}
= jπ + 2jδ_{2} + y ln |z| − y + δ_{1}

where |δ_{1}| < ϵ/6 and |δ_{2}| < ϵ/(6j), while

ℑ(ln(π/ sin(πz)) − lnΓ(1 − z)) = −ℑ(lnΓ(1 − z))
= −ℑ((1/2 − z) ln(1 − z) − (1 − z)) + δ_{3}
= 2j arg(1 − z) + y ln |1 − z| − y + δ_{3}
= −jπ + 2jδ_{4} + y ln |1 − z| − y + δ_{3}

where |δ_{3}| < ϵ/6 and |δ_{4}| < ϵ/(6j), and so

|2k(z)π − 2jπ| = |2j(δ_{2} − δ_{4}) + y ln(|z|/|1 − z|) + δ_{1} − δ_{3}|
≤ 2j(|δ_{2}| + |δ_{4}|) + y ln(|z|/|1 − z|) + |δ_{1}| + |δ_{3}|
< ϵ

and so, since k(z) and j are both integers and ϵ > 0 was arbitrary, k(z) = j = ⌈ℜ(z)/2−3/4⌉. This finishes the proof for the case ℑ(z) > 0. For the case z = x < 0, (i.e., ℑ(z) = 0) we have

ℑ (ln (\frac{π}{sin(πx)})) = \{ \begin{matrix}0 & if 2j < x < 2j + 1 \\ π & if 2j + 1 < x < 2j + 2 \end{matrix}

where j is a negative integer. We also have

lim_{ϵ→0^{+}} ℑ (ln (\frac{π}{sin(π(x + ϵi))})) = \{ \begin{matrix}0 & if 2j < x < 2j + 1 \\ π & if 2j + 1 < x ≤ 2j + 3/2 \\ −π & if 2j + 3/2 < x < 2j + 2 \end{matrix}

D.E.G. Hare Computing the Principal Branch of lnΓ Thus, in order for lnΓ(x) to be continuous from above onto the negative real axis, the formula for k(x + ϵi) when ϵ > 0 can be used if 2j < x < 2j + 3/2, while on the interval 2j + 3/2 < x < 2j + 2 this value must be decreased by 1. It is a simple computation to verify that the formula k(x) = ⌈x/2 − 1⌉ satisfies these conditions.

Finally, the case ℑ(z) < 0 follows by an appeal to conjugate symmetry, since k(z) is real valued.

Corollary 3.2 If x < 0 then lnΓ(x) = ln(Γ(x)) + 2πi⌈x/2 − 1⌉.

Proof If x < 0 then 1 − x > 0, so Γ(1 − x) > 0, so lnΓ(1 − x) = ln(Γ(1 − x)) and ln(wΓ(1 − x)) = ln w + ln(Γ(1 − x)) for all w ∈ C \ {0}. Therefore

ln(π/ sin(πx)) = ln(Γ(x)Γ(1 − x))
= ln(Γ(x)) + ln(Γ(1 − x))
= ln(Γ(x)) + lnΓ(1 − x)

and

ln(π/ sin(πx)) = lnΓ(x) + lnΓ(1 − x) − 2k(x)πi

by Proposition 3.1. The last two lines above yield the result.

Corollary 3.3 If x < 0 and x is not an integer, then ℑ(lnΓ(x)) = ⌊x⌋πi.

Proof The reflection formula for Γ implies that sin(πx) and Γ(x) must have the same sign. Therefore, by Corollary 3.2,

ℑ(lnΓ(x)) = ℑ(ln(Γ(x))) + 2k(x)π = \{ \begin{matrix}2k(x)π & if ⌊x⌋ is even \\ (2k(x) + 1)π & if ⌊x⌋ is odd \end{matrix}

The result now follows from the observation that if ⌊x⌋ = 2m then ⌈x/2 − 1⌉ = m (since x is not an integer), while if ⌊x⌋ = 2m − 1 then ⌈x/2 − 1⌉ = m − 1.

Note that Corollary 3.3 implies that if x < 0 is real, then the computation of lnΓ(x) can be carried out completely in real arithmetic, as ℜ(lnΓ(x)) = ln(|Γ(x)|).

4. Error Bounds and Implementation in Maple V Release 3

The methods described in §§2 and 3 are very well suited to computation in a variable precision environment such as Maple [2]. In general, the precision of a computation, as requested by the user, determines whether or not an asymptotic method can be used to evaluate a particular function at a particular point. For the Γ and lnΓ functions, however, the recurrence relation (Proposition 2.2) and the reflection formula (Proposition 3.1) allow the asymptotic method to be used for all arguments in the domain of lnΓ. (The values of Γ(z) and lnΓ(z) at certain special arguments, z, such as moderately sized positive integers, can, of course be computed more efficiently by more direct means.)

There is a relatively simple bound on the error, R_{m}, resulting from truncating the asymptotic series (1.1) at the m^{th} term to obtain an approximation to lnΓ(z) for some z (z not a negative real number) [8, §8.4]:

|R_{m}| ≤ \frac{|B_{2m}| sec^{2m}(θ/2)}{2m(2m − 1)|z|^{2m−1}} ≡ R̃_{m}  (4.1)

where −π < θ = arg z < π. Approximating the (2m)^{th} Bernoulli number by 2(2m)!/(2π)^{2m} [1, 23.1.15], we have

R̃_{m} ≈ \frac{2}{(2π)^{2m}} \frac{(2m − 2)! sec^{2m}(θ/2)}{|z|^{2m−1}}  (4.2)

from which we see that the smallest error will occur roughly when m sec(θ/2) ≈ π|z|. Using Stirling’s formula [1, 6.1.37] we thus have

R̃_{m} ≈ \frac{2|z|}{(2π|z|)^{2m}} e^{−2m+1}(2m − 1)^{2m−1} sec^{2m}(θ/2)

≈ \frac{2|z|}{(2m)^{2m}} e^{−2m+1}(2m − 1)^{2m−1} sec^{2m}(θ/2)

≈ \frac{|z|e^{−2m}}{m}

In order to use (1.1) to approximate lnΓ(z) to d digits, then, we should have R̃_{m} < D.E.G. Hare Computing the Principal Branch of lnΓ 10^{−d}|lnΓ(z)|, and we can approximate |lnΓ(z)| ≈ |z ln z|, again by (1.1). Thus R̃_{m} ≈ |z|e^{−2m}/m < 10^{−d}|z ln z| implies m + ln m > 1/2(d ln 10 − ln |lnz|), or, upon discarding the second order logarithm terms, m > d/2 ln 10 ≈ 1.15d, and so we should have

|z| > m sec(θ/2)/π ≈ .37d sec(θ/2) .  (4.3)

For z in the right half plane (so ℜ(z) ≥ 0), this bound is reasonable, as the maximum value of sec(θ/2) is then \sqrt{2}, which leads to a uniform lower bound for |z| for the applicability of (1.1) of about .52d. For z in the left half plane, (4.3) suggests that the asymptotic formula (1.1) is less attractive, and, indeed, this observation led Olver to argue that (1.1) should never be used for ℜ(z) < 0 [8, §8.4]. This argument is flawed, however, as the inequality on which it depends, namely (4.1), is derived using estimates whose accuracy seriously degrades in the left half plane. Indeed, as the following proposition shows, the applicability of (1.1) in the left half plane does not depend on θ = arg z at all, but only on ℑ(z). Therefore, the asymptotic series method is almost equally useful in the left and right half planes.

Proposition 4.1 Let z ∈ C\R and let R_{m} be the error resulting from truncating (1.1) at the m^{th} term. Then

|R_{m}| ≤ \frac{π^{1/2}Γ(m − 1/2)|B_{2m}|}{Γ(m + 1)|ℑ(z)|^{2m−1}} .

Proof Let x = ℜ(z), y = ℑ(z), and without loss of generality, assume y > 0. Following the early stages of the development of (4.1) as given in [8, §8.4], we have (B_{2m}(t) is the (2m)^{th} Bernoulli polynomial)

|R_{m}| = |∫_{0}^{∞} \frac{B_{2m} − B_{2m}(t − ⌊t⌋)}{2m(t + z)^{2m}} dt|

≤ \frac{|B_{2m}|}{m} ∫_{0}^{∞} \frac{1}{|t + z|^{2m}} dt

= \frac{|B_{2m}|}{m} ∫_{0}^{∞} \frac{1}{((t + x)^{2} + y^{2})^{m}} dt

= \frac{|B_{2m}|}{m} ∫_{x}^{∞} \frac{1}{(t^{2} + y^{2})^{m}} dt

= \frac{|B_{2m}|}{my^{2m−1}} ∫_{tan^{−1}(x/y)}^{π/2} cos^{2m−2}(ϕ) dϕ

≤ \frac{|B_{2m}|}{my^{2m−1}} ∫_{−π/2}^{π/2} cos^{2m−2}(ϕ) dϕ

= \frac{|B_{2m}|}{my^{2m−1}} \frac{π^{1/2}Γ(m − 1/2)}{Γ(m)}

by Wallis’ formula [1, 6.1.49].

An analysis similar to that leading up to the bound (4.3) now gives us that for z = x+iy with y ≠ 0 the minimum term in the asymptotic series (1.1) occurs roughly when m = πy, at which point the requirement |R_{m}| ≤ 10^{−d}|lnΓ(z)| implies that 2πy > d ln 10+(lower order terms), or, roughly,

y > .37d .  (4.4)

Extensive numerical testing has shown that the error introduced by dropping the lower order terms in this bound is more than compensated by the error introduced in the first step of the proof of Proposition 4.1, and hence it is safe to use this as a firm bound.

Thus, Stirling’s series for lnΓ can be directly used to approximate lnΓ(z) to d digits of accuracy as long as either of the conditions |ℑ(z)| > .37d or ℜ(z) ≥ 0 and |z| > .52d is satisfied.

Based on the above error bounds and the results presented in the preceding sections, there are thus three possible algorithms available for the evaluation of lnΓ(z) to a given (but not fixed a priori) precision d:

1. The algorithm based on Corollary 2.3, with the recurrence formula applied, if necessary, in the direction of increasing |z|.

2. The algorithm based on Corollary 2.3, with the recurrence formula applied, if necessary, in the direction of increasing ℜ(z).

3. The algorithm based on the Proposition 3.1, as the first step, followed by

Algorithm (1). If ℜ(z) ≥ 0 then Algorithms (1) and (2) are the same, and Algorithm (3) is not relevant.

D.E.G. Hare Computing the Principal Branch of lnΓ

If ℜ(z) < 0 and |ℑ(z)| > .37d, then Algorithm (1) is clearly superior to Algorithm (2) and the latter stage of Algorithm (3) will have the same cost as Algorithm (1), and hence Algorithm (1) is to be preferred. These observations follow by noting that the convergence criterion for the asymptotic series method (1.1) is a function of |z|, and not of ℜ(z).

If ℜ(z) ≪ 0 and |ℑ(z)| ≤ .37d then Algorithm (3) is the obvious choice.

Finally, if ℜ(z) is not sufficiently negative so that (1.1) can be directly used on 1 − z, and if |ℑ(z)| ≤ .37d, then Algorithm (1) is not applicable, and it is by no means clear which of Algorithms (2) or (3) is superior. Some elementary observations are possible, namely that Algorithm (2) is to be preferred for z close to the imaginary axis, while Algorithm (3) is to be preferred for z close to the point where the asymptotic series (1.1) could be applied to 1 − z with little or no shifting of the argument required. Ultimately, however, the choice is not particularly important, as the shifting and/or reflecting of the argument represents a lower order of magnitude cost to the total computation than does the evaluation of the asymptotic expansion.

It should be noted that the inequalities (4.3) and (4.4) provide minimum conditions under which the asymptotic series (1.1) will converge. If we employ Proposition 2.2 (possibly preceded by an application of Proposition 3.1 if ℜ(z) < 0 and |ℑ(z)| < .37d) in such a way as to produce a z_{(n)} (in the notation of §2) which at least satisfies these conditions, then we can use the asymptotic expansion (1.1) to compute lnΓ(z_{(n)}) and hence use Corollary 2.3 to compute lnΓ(z). However, it is clear from the above analysis that if we use the recurrence relation to make |z_{(n)}| larger still, then fewer terms of (1.1) will be required to compute lnΓ(z_{(n)}) to a given precision d. As the coefficients in the series (1.1) involve Bernoulli numbers, which carry some cost of computation themselves, it is generally worthwhile to do this. At some point, of course, the cost of the recurrence relation itself will outweigh the savings realized.

Thus, the implementation of lnΓ in Maple V Release 3 is fundamentally as follows:

− If ℑ(z) < 0 then \overline{lnΓ(\overline{z})} is computed.

− If ℜ(z) ≥ 0, or ℜ(z) < 0 and ℑ(z) > .37d, then Algorithm (1) is used, with the recurrence relation applied until |z_{(n)}| ≥ d.

D.E.G. Hare Computing the Principal Branch of lnΓ

− If ℜ(z) < 0 and ℑ(z) < .37d, then Algorithm (3) is used. (In versions subsequent to Maple V Release 3, Algorithm (2) is used in this case if ℜ(z) ≥ −10.)

In Maple, the goal of the numerical evaluation of a basic function, such as lnΓ, at a point, is to produce a value which is accurate to the precision requested by the user, plus or minus at most .6 units in the last place (essentially, Maple strives to produce a value whose relative error is on the order of 10^{−d}, where d is the user-requested precision). In order to achieve this goal, Maple floating-point evaluation routines will normally increase the precision at which intermediate calculations are done. This means that the decision procedure described above is executed at the working precision in effect at that point in the code, which is usually a small amount higher than the precision of the end result.

The author wishes to thank Dr. David Jeffrey of the University of Western Ontario for valuable discussions.

References

[1] Abramowitz, M., and Stegun, I.A., Handbook of Mathematical Functions, Dover Publications, Inc., New York, 1965.

[2] Char, B.W., Geddes, K.O., Gonnet, G.H., Leong, B.L., Monagan, M.B., and Watt, S.M., The Maple V Language Reference Manual, Springer-Verlag, 1991.

[3] Conway, J.B., Functions of One Complex Variable, Springer-Verlag, 1973.

[4] Edwards, H.M., Riemann’s Zeta Function, Academic Press, 1974.

[5] Erdélyi, A., ed., Higher Transcendental Functions, Vol. 1, McGraw-Hill Book Company, Inc., 1953.

[6] Kahan, W., Branch cuts for complex elementary functions, in The State of the Art in Numerical Analysis, A. Iserles and M.J.D. Powell, eds., Clarendon Press, Oxford, 1987.

[7] Jakimovski, A., and Russell, D.C., Mercerian theorems involving Cesàro means of positive order, Monatsh. Math. 96 (1983), 119–131.

[8] Olver, F.W.J., Asymptotics and Special Functions, Academic Press, Inc., New York and London, 1974.

[9] Whittaker, E.T. and Watson, G.N., A Course of Modern Analysis, 4th ed., Cambridge University Press, 1927.