The gamma function of a complex ball
#include <flint/acb_hypgeom.h>Sets res to the gamma function \Gamma(x). The result is indeterminate if x contains a pole.
Real input is passed to arb_hypgeom_gamma. Otherwise the function uses the tabulated Taylor series of acb_hypgeom_gamma_taylor near the real axis at low and moderate precision and the Stirling series of acb_hypgeom_gamma_stirling elsewhere. See The gamma function of a complex ball. acb_gamma calls this function.
Sets res to the reciprocal gamma function 1/\Gamma(x), which is entire.
Uses the same methods as acb_hypgeom_gamma. If the Stirling series gives no finite enclosure (a wide ball), it returns the bound |1/\Gamma(z)| \le R^{R + 1/2} e^{\pi R/2} for |z| \le R instead. acb_rgamma calls this function.
Sets res to the principal branch of the log-gamma function \log \Gamma(x), which is analytic except on the branch cut (-\infty, 0] and differs from \log(\Gamma(x)) by a multiple of 2\pi i.
Positive real input is passed to arb_hypgeom_lgamma. Near the real axis at moderate precision, the function computes \log(1/\Gamma(u)) with the Taylor series for u with real part in [1/2, 3/2] (where the branch is determined by tabulated bounds for the imaginary part), and corrects the shift and the reflection with acb_hypgeom_log_rising_ui and acb_log_sin_pi. Elsewhere it uses the Stirling series, which gives \log\Gamma directly, with argument reduction by the log-rising factorial and, for negative real parts, the reflection formula \log\Gamma(z) = \log\pi - \log\sin(\pi z) - \log\Gamma(1-z) with the branch of acb_log_sin_pi. See The logarithm of the gamma function. acb_lgamma calls this function.
acb_hypgeom_gamma, acb_hypgeom_rgamma and acb_hypgeom_lgamma compute \Gamma(z), 1/\Gamma(z) and the principal branch of \log \Gamma(z) for a complex ball z. They are the implementations behind acb_gamma, acb_rgamma and acb_lgamma. Real arguments are passed to the real functions (see The gamma function of a real ball); otherwise the functions use a tabulated Taylor series near the real axis and the Stirling series elsewhere, as described in The gamma function.
The principal branch of log-gamma#
The function computed by acb_hypgeom_lgamma is not \log(\Gamma(z)) with the principal logarithm. It is the analytic continuation of \log\Gamma(x) from the positive real axis to \mathbb{C} \setminus (-\infty, 0], which is the convention of most computer algebra systems and of the DLMF [NIST2012, §5.4]: it satisfies \log\Gamma(z+1) = \log\Gamma(z) + \log z exactly (not only modulo 2\pi i), and its imaginary part grows like \operatorname{Im}(z) \log |z| instead of staying in (-\pi, \pi]. The two functions differ by 2\pi i k(z), where the integer k(z) changes along curves where \operatorname{Im}\log\Gamma(z) is an odd multiple of \pi. On the branch cut, the value is the limit from the upper half-plane.
Computing this branch requires more than a logarithm of \Gamma(z):
- The Stirling series gives \log\Gamma(z) directly for z of large modulus in the right half-plane. Its argument reduction \log\Gamma(z) = \log\Gamma(z+r) - \log\,(z)_r needs the log-rising factorial \log\,(z)_r = \sum_{k<r} \log(z+k) with the correct multiple of 2\pi i, which
acb_hypgeom_log_rising_uicomputes with Hare's algorithm [Hare1997]. - The reflection formula for the left half-plane becomes \log\Gamma(z) = \log\pi - \log\sin(\pi z) - \log\Gamma(1-z), where \log\sin(\pi z) must be the analytic branch computed by
acb_log_sin_pi. - Near the real axis at moderate precision, the Taylor series of 1/\Gamma(1+u) is used for u with real part in about [-1/2, 1/2]; the branch of \log applied to it is fixed with a table of the lines where \operatorname{Im}\log\Gamma crosses (k + \tfrac12)\pi.
Example#
At z = -10.25 + 0.5i the principal branch of \log\Gamma and the principal logarithm of \Gamma differ by -10\pi i:
#include <flint/acb.h>
#include <flint/acb_hypgeom.h>
int main(void)
{
acb_t z, y, t;
acb_init(z);
acb_init(y);
acb_init(t);
acb_set_d_d(z, -10.25, 0.5);
acb_hypgeom_gamma(y, z, 64);
flint_printf("gamma(z) = "); acb_printn(y, 15, 0); flint_printf("\n");
acb_hypgeom_lgamma(y, z, 64);
flint_printf("lgamma(z) = "); acb_printn(y, 15, 0); flint_printf("\n");
acb_hypgeom_gamma(t, z, 64);
acb_log(t, t, 64);
flint_printf("log(gamma(z)) = "); acb_printn(t, 15, 0); flint_printf("\n");
/* the difference is 2 pi i k */
acb_sub(t, y, t, 64);
acb_const_pi(y, 64);
acb_mul_2exp_si(y, y, 1);
acb_div(t, t, y, 64);
flint_printf("difference / (2 pi) = "); acb_printn(t, 15, 0); flint_printf("\n");
acb_hypgeom_rgamma(y, z, 64);
flint_printf("rgamma(z) = "); acb_printn(y, 15, 0); flint_printf("\n");
acb_clear(z);
acb_clear(y);
acb_clear(t);
flint_cleanup();
return 0;
}gamma(z) = [7.08331784482241e-8 +/- 3.66e-23] + [-1.88626361829666e-7 +/- 2.32e-22]*I lgamma(z) = [-15.4175381117796 +/- 4.86e-15] + [-32.6274954179361 +/- 2.24e-14]*I log(gamma(z)) = [-15.4175381117796 +/- 4.86e-15] + [-1.21156888203815 +/- 4.69e-15]*I difference / (2 pi) = [+/- 2.62e-19] + [-5.00000000000000 +/- 1.09e-18]*I rgamma(z) = [1744778.02581992 +/- 4.92e-9] + [4646284.95319217 +/- 4.09e-9]*I
\Gamma(z) is small here because z is close to the negative real axis between two poles; 1/\Gamma(z), which is entire, is large.
References#
- [NIST2012] National Institute of Standards and Technology, Digital Library of Mathematical Functions (2012), https://dlmf.nist.gov/
- [Hare1997] D. E. G. Hare. Computing the principal branch of log-Gamma. Journal of Algorithms 25:2 (1997), 221–236. https://doi.org/10.1006/jagm.1997.0881
The FLINT team, “The gamma function of a complex ball (acb_hypgeom.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/acb_hypgeom/gamma.html (generated 2026-10-20).
@misc{flint-doc-acb-hypgeom-gamma,
author = {{The FLINT team}},
title = {{The gamma function of a complex ball (acb\_hypgeom.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/acb_hypgeom/gamma.html},
note = {Generated 2026-10-20}
}