The Lanczos Approximation for the -Function with Complex Coefficients
Abstract
We examined the properties of the coefficients of the Lanczos (1964) approximation of the -function with complex value of the free parameter together with the convergence properties of the approximation when using these coefficients. We report that for fixed real parts of the free parameter that using complex coefficients both increases the computational cost of the Lanczos approximation while drecreasing the accuracy. We conclude that in practical applications of numerical evaluation of the -function only coefficients generated with real values of the free parameter should be used..
1 Introduction
The -function, defined by
(1) |
was introduced by Euler as a solution to the “interpolation” problem of defining the factorial function for non-integer values. Equation (1) has the desired property that . The uniqueness of this definition was proved by Bohr and Mollerup (1922) and a second proof attributed to H. Wielandt is discussed by Remmert (1996) and included in the textbook by Freitag and Busam (2005),
In the form of Equation (1) it is defined in the complex plane for and can be extended to the left half-plane, among other several other methods, through the use of the Euler reflection formula
(2) |
The -function has found wide application in pure and applied mathematics, statistics and the physical sciences. Exact values for the -function can be found for positive integer (zero and the negative integers are simple poles) and for half integer values of . Apart from those values, the -function must be evaluated using numerical methods. To this end a number of approximations and asymptotic series have been developed. The earliest being Stirling’s approximation; for integer
A large number of proofs of Stirling’s approximation and closely related formulas are available, see, for example, Aissen (1954), Feller (1967), Spira (1971), Namias (1986), Marsaglia and Marsaglia (1990), Deeba and Rodriguez (1991), Schuster (2001), Michel (2002), Dutkay et al. (2013), Lou (2014), and Neuschel (2014).
There are also a number of series expansions available such as Stirling’s asymptotic series
There are some proofs which only require elementary methods such as that of Mermin (1984), Namias (1986), Diaconis and Freedman (1986), Patin (1989) and Marsaglia and Marsaglia (1990).
In addition there are series methods due to Spira (1971), Spouge (1994), and Schmelzer and Trefethen (2007). Among these other series Lanczos (1964) derived an expansion for the numerical evaluation of the -function which was popularized to some extent by its inclusion in Press et al. (1997) and which was studied in some detail by Pugh (2004). The expansion has two notable features; it is convergent rather than an asymptotic expansion and it has a free parameter (denoted by by Lanczos (1964) but by by Pugh (2004), we will use in this paper) which affects the rate of convergence of the approximation. While it is known that the free parameter can be complex, to the best of this author’s knowledge the convergence properties of a complex expansion have not been studied. Godfrey (2001) studied the convergence properties of the expansion for real values of and implemented his best choice of coefficients in Matlab (MATLAB, 2019) using 15 terms and giving an approximation that was accurate to 15 significant digits along the real axis and 13 significant digits elsewhere.
The Lanczos expansion,, which is for rather than , can be written
(3) |
where the are the coefficients and is the free parameter.
The key to obtaining the is to note that the -function has known values at the integers and that for positive integers the expansion (3) terminates, allowing the to be determined recursively. Pugh (2004) investigated several methods of obtaining the and reported the recursive methods worked well in practice.
In (3) if then and the series terminates after the first term. Thus
Solving for we obtain | ||||
(4) |
Having obtained we then set so that and (3) now terminates after the second term allowing us to find . By successively setting we can calculate as many of the as required.
On a practical matter of finding the it is useful to set
(5) | ||||
Then | ||||
(6) | ||||
(7) | ||||
The general () recursion formula is | ||||
(8) |
The final equation is Pugh (2004) Equation (6.4).
Having found some values they are substituted into the expansion (3) and desired approximations of can be obtained, values with can be obtained by combining the Lanczos approximation with the Euler reflection formula, Equation (2).
In the remainder of this paper Section (2) investigates some of the properties of the Lanczos coefficients with complex values of the free parameter, Section (3) reports on the numerical performance of series with complex coefficients, Section (4) presents our conclusions while Appendix (A) presents some supplementary materials.
2 Properties of the Complex
The formulas (4) through (8) allow us to calculate the expansion coefficients with complex . All numerical values and graphics presented here were obtained with custom written Matlab (MATLAB, 2019) code. The code was verified using published values of the for real in Lanczos (1964) and Pugh (2004) and then, without any further alteration of the code, was allowed to be complex and the required coefficients calculated.
Figures (1) through (5) present five different views of the coefficient for with . While we explored values of with different real parts (), the behaviour of the coefficients were similar in all cases, the main change being their magnitudes.
In the recursive calculation of the only integer values of are used so we denote these by . The free parameter enters at two points. In the numerator of the , Equation (5), with , has the term . Writing the real part of the exponent is while the imaginary part is . Holding the real part constant and allowing to change makes the coefficients “spin” in the complex plane, examples can be seen in Figures (1), (4) and (5).

The other place enters the calculation of the is in the denominator of . This is what causes the “tappering off” seen in Figure (1) through (3) and the gradual descent of the path of the on the Riemann sphere, see Figure (5). If
We can rewrite this in polar form | ||||
where | ||||
If is fixed increasing increases causing the tapper. Asympotitically the real and imaginary parts of decay as .

Figures (2) and (3) suggest that there are points for fixed ( in the Figures) for which the will be purely real or purely imaginary. We can derive conditions under which these cases occur and show that there are an infinite number of such coefficients.

Using Equation (4), if is purely imaginary then it has the form . Thus
First, splitting into its real and imaginary parts we have | ||||
Next, we proceed to split this into its real and imaginary parts | ||||
Thus we have
From this we neglect the sign of the leading fraction because it is always positive. This leaves us with two conditions for the to be purely imaginary. The first is that real part must be negative, that is
or | ||||
(9) | ||||
Secondly, we require that the imaginary part is zero | ||||
From this second condition we require | ||||
(10) | ||||
For the to be purely real the condition on the imaginary part (Equation 10) is unchanged and in place of Equation (9) we require | ||||
or | ||||
(11) |



Pragmatically, to find the values of for which the are purely real or imaginary requires solving Equation (10) numerically and then checking the conditions in Equations (9) and (11).
2.1 The Magnitudes of the
Numerical work by Pugh (2004) showed that the magnitudes of the Lanczos coefficients decreased rapidly for increasing , motivating us to examine this property in the complex case. Figure (6) presents the magnitudes of the first 11 Lanczos coefficients for with . It is clear from this Figure that the coefficients with purely real are turning points (maximum, minimum or local minimum) in the trajectory of the through complex space. We observed this phenomena for all real values of we examined, .

Further, as increases the magnitude of the coefficients converge. This is illustrated in Figure (7) in which we present the location in the complex plane of the first ten Lanczos coefficients with i. Their numerical values are presented in Table (1). We used these in one set of numerical evaluations discussed in Section (3) below. Both Lanczos (1964) and Pugh (2004) noted that for real the signs of the Lanczos coefficients alternate with for even and for odd. Although we did not do extensive numerical computations to large values of , in the work we did do, we never found two successive in the same quadrant.
Coefficient | Numerical Value |
---|---|
0.32272800 - 0.31511539i | |
-0.33566576 + 0.30053412i | |
0.37045027 - 0.25375121i | |
-0.41388748 + 0.16751781i | |
0.44150035 - 0.03647994i | |
-0.41823596 - 0.13196358i | |
0.30817352 + 0.30446707i | |
-0.09837046 - 0.41551337i | |
-0.16793546 + 0.38494230i | |
0.37447472 - 0.172296311i |
3 Numerical Evaluation
It is obvious that using a Lanczos approximation with complex increases the computational cost of calculating the -function when the same number of coefficients are used. Thus to use complex coefficients requires a compelling case that there are significant advantages in the convergence rate and/or accuracy of the approximation compared to real coefficients. In this section we examine whether such a case can be made.
In all cases we used 10 coefficients in the approximation. Figures (8) through (11) present the results, we discuss how the data in each Figure was generated and comment on its significance.

We generated 13 sets of 10 coefficients using the recursive method described above by setting where . In Figures (8) and (9) the imaginary part of is presented on the axis label . We generated 22 values of for which exact values could be calculated. These were obtained for integer values from the factorial property, namely and for half integer values from the functional equation
coupled with the value .
Figure (8) presents the absolute value of the error while Figure (9) presents the relative error, that is the absoluate error is divided by the exact value. In both cases it is clear that the Lanczos coefficients generated by real performed better. The absolute error is never large (less than 3 for but largest error occurs for coefficients generated with .

The relative error presented in Figure (9) is more informative. The vertical axis is truncated at an error of in order to better see the relative error at the half-integer values.. It clear that in all cases the relative error is indistiquishable from zero for integer values up to for all values of. This is because they were used to generate the coefficients. However, the half integer values of show increasing relative errors as the imaginary part increases from to . Somewhat similar, once we progress beyond the integer values of which we used to generate the coefficients, i.e. , the relative error builds rapidly with increasing imaginary part of . At least on the scale used in the Figure the relative error for the coefficients are indistinquiable from zero for real .


For Figures (10) and (11), using the same coefficients as above, we considered the performance of the approxmation for complex values of . We set for . To find comparison values we used the Godfrey (2001) implementation discussed above. For both the absolute and relative error cases, the Lanczos approximation performance deteriorated as the imaginary part of increased and as the imaginary part of increased together.
Figure (6) suggests that as the imagary part of increases all coefficients converge to the same magnitude. For the coefficients displayed in Figure (7), i.e. for , we tested its performance against the Godfrey (2001) implementation. We do not present detailed results here, suffice to say that as the imaginary part of increased the relative error increased very rapidly.
4 Conclusions
We explored the possibility that complex values of the free parameter in the Lanczos (1964) approximation for the -function could improve the rate of convergence of the approximation. However, we must conclude that there is no advantage to using complex values of , in fact, it appears uniformly detrimental. The real values of for the values we explored uniformly gave the lowest relative error when compared with exact values of the -function at integer and half integer values. Further, Lanczos coefficients generated by real values of also uniformly gave the lowest relative error for complex values of the in .
Unless there are purely mathematical reasons for further studying the properties of complex Lanczos coefficients they appears to be a dead end in applied numerical analysis.
References
- Aissen (1954) Aissen, M. I. (1954). Some Remarks on Stirling’s Formula. The American Mathematical Monthly 61(10), 687–691.
- Bohr and Mollerup (1922) Bohr, H. and J. Mollerup (1922). Laereborg i Matematisk Analyse, Volume III. J. Gjellerup, Kopenhagen.
- Deeba and Rodriguez (1991) Deeba, E. Y. and D. M. Rodriguez (1991). Stirling’s Series and Bernoulli Numbers. The American Mathematical Monthly 98(5), 423–326.
- Diaconis and Freedman (1986) Diaconis, P. and D. Freedman (1986). An Elementary Proof of Stirling’s Formula. The American Mathematical Monthly 93(2), 123–125.
- Dutkay et al. (2013) Dutkay, D. E., C. P. Niculescu, and F. Popovici (2013). Stirling’s Formula and its Extension for the Gamma Function. The American Mathematical Monthly 120(8), 737–740.
- Feller (1967) Feller, W. (1967). A Direct Proof of Stirling’s Formula. The American Mathematical Monthly 74(10), 1223–1225.
- Freitag and Busam (2005) Freitag, E. and R. Busam (2005). Complex Analysis. Springer.
- Godfrey (2001) Godfrey, P. (2001). A Note on the Computation of the Convergent Lanczos Complex Gamma Approximations. http://my.fit.edu/ gabdo/paulbio.html.
- Lanczos (1964) Lanczos, C. (1964). A Precision Approximation of the Gamma Function. Journal of the Society for Industrial and Applied Mathematics: Series B, Numerical Analysis 1, 86–96.
- Lou (2014) Lou, H. (2014). A Short Proof of Stirling’s Formula. The American Mathematical Monthly 121(2), 154–157.
- Marsaglia and Marsaglia (1990) Marsaglia, G. and J. C. W. Marsaglia (1990). A New Derivation of Stirling’s Approximation to n! The American Mathematical Monthly 97(9), 826–829.
- MATLAB (2019) MATLAB (2019). version 9.6.0.1072779 (R2019a). Natick, Massachusetts: The MathWorks Inc.
- Mermin (1984) Mermin, N. D. (1984). Stirling’s formula! American Journal of Physics 52(4), 362–365.
- Michel (2002) Michel, R. (2002). On Stirling’s Formula. The American Mathematical Monthly 109(4), 388–390.
- Namias (1986) Namias, V. (1986). A Simple Derivation of Stirling’s Asymptotic Series! The American Mathematical Monthly 93(1), 25–29.
- Neuschel (2014) Neuschel, T. (2014). A New Proof of Stirling’s Formula. The American Mathematical Monthly 121(4), 350–352.
- Patin (1989) Patin, J. M. (1989). A Very Short Proof of Stirling’s Formula. The American Mathematical Monthly 96(1), 41–42.
- Press et al. (1997) Press, W. H., S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery (1997). Numerical Recipes. Cambridge University Press.
- Pugh (2004) Pugh, G. R. (2004). An Analysis of the Lanczos Gamma Approximation. Ph.D. Thesis, The University of British Columbia.
- Remmert (1996) Remmert, R. (1996). Wielandt’s Theorem About the -Function. The American Mathematical Monthly 103(3), 214–220.
- Schmelzer and Trefethen (2007) Schmelzer, T. and L. N. Trefethen (2007). Computing the Gamma Function Using Contour Integrals and Rational Approximations. SIAM Journal on Numerical Analysis 45(2), 558–571.
- Schuster (2001) Schuster, W. (2001). Improving Stirling’s Formula. Archiv der Mathematik 77, 170–176.
- Spira (1971) Spira, R. (1971). Calculation of the Gamma Function by Stirling’s Formula. Mathematics of Computation 25(114), 317–322.
- Spouge (1994) Spouge, J. L. (1994). Computation of the Gamma, Digamma and Trigamma Functions. SIAM Journal on Numerical Analysis 31(3), 931–944.
Appendix A Plots of Coefficients 0 through 10
A.1 Real and Imaginary Parts of the Coefficients











A.2 Coefficients on the Riemann Sphere










A.3 Magntitudes of the Coefficients




