FLINT3.7.0-dev

The gamma function of a complex ball

Synopsis#include <flint/acb_hypgeom.h>
void acb_hypgeom_gamma(acb_t res, const acb_t x, slong prec)source

Sets res to the gamma function Γ(x)\Gamma(x). The result is indeterminate if xx 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.

void acb_hypgeom_rgamma(acb_t res, const acb_t x, slong prec)source

Sets res to the reciprocal gamma function 1/Γ(x)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/Γ(z)∣≤RR+1/2eπR/2|1/\Gamma(z)| \le R^{R + 1/2} e^{\pi R/2} for ∣z∣≤R|z| \le R instead. acb_rgamma calls this function.

void acb_hypgeom_lgamma(acb_t res, const acb_t x, slong prec)source

Sets res to the principal branch of the log-gamma function log⁡Γ(x)\log \Gamma(x), which is analytic except on the branch cut (−∞,0](-\infty, 0] and differs from log⁡(Γ(x))\log(\Gamma(x)) by a multiple of 2πi2\pi i.

Positive real input is passed to arb_hypgeom_lgamma. Near the real axis at moderate precision, the function computes log⁡(1/Γ(u))\log(1/\Gamma(u)) with the Taylor series for uu with real part in [1/2,3/2][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⁡Γ\log\Gamma directly, with argument reduction by the log-rising factorial and, for negative real parts, the reflection formula log⁡Γ(z)=log⁡π−log⁡sin⁡(πz)−log⁡Γ(1−z)\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 Γ(z)\Gamma(z), 1/Γ(z)1/\Gamma(z) and the principal branch of log⁡Γ(z)\log \Gamma(z) for a complex ball zz. 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.

AlgorithmThe gamma functionRigorous evaluation of Γ, 1/Γ and log Γ in ball arithmetic — the Stirling series with Olver's error bound and argument reduction, rising factorials by rectangular and binary splitting, a tabulated Taylor series of 1/Γ for low and medium precision, fast formulas for rational arguments, and the principal branch of log Γ.

The principal branch of log-gamma#

The function computed by acb_hypgeom_lgamma is not log⁡(Γ(z))\log(\Gamma(z)) with the principal logarithm. It is the analytic continuation of log⁡Γ(x)\log\Gamma(x) from the positive real axis to C∖(−∞,0]\mathbb{C} \setminus (-\infty, 0], which is the convention of most computer algebra systems and of the DLMF [NIST2012, §5.4]: it satisfies log⁡Γ(z+1)=log⁡Γ(z)+log⁡z\log\Gamma(z+1) = \log\Gamma(z) + \log z exactly (not only modulo 2πi2\pi i), and its imaginary part grows like Im⁡(z)log⁡∣z∣\operatorname{Im}(z) \log |z| instead of staying in (−π,π](-\pi, \pi]. The two functions differ by 2πik(z)2\pi i k(z), where the integer k(z)k(z) changes along curves where Im⁡log⁡Γ(z)\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 Γ(z)\Gamma(z):

  • The Stirling series gives log⁡Γ(z)\log\Gamma(z) directly for zz of large modulus in the right half-plane. Its argument reduction log⁡Γ(z)=log⁡Γ(z+r)−log⁡ (z)r\log\Gamma(z) = \log\Gamma(z+r) - \log\,(z)_r needs the log-rising factorial log⁡ (z)r=∑k<rlog⁡(z+k)\log\,(z)_r = \sum_{k<r} \log(z+k) with the correct multiple of 2πi2\pi i, which acb_hypgeom_log_rising_ui computes with Hare's algorithm [Hare1997].
  • The reflection formula for the left half-plane becomes log⁡Γ(z)=log⁡π−log⁡sin⁡(πz)−log⁡Γ(1−z)\log\Gamma(z) = \log\pi - \log\sin(\pi z) - \log\Gamma(1-z), where log⁡sin⁡(πz)\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/Γ(1+u)1/\Gamma(1+u) is used for uu with real part in about [−1/2,1/2][-1/2, 1/2]; the branch of log⁡\log applied to it is fixed with a table of the lines where Im⁡log⁡Γ\operatorname{Im}\log\Gamma crosses (k+12)π(k + \tfrac12)\pi.

Example#

At z=−10.25+0.5iz = -10.25 + 0.5i the principal branch of log⁡Γ\log\Gamma and the principal logarithm of Γ\Gamma differ by −10πi-10\pi i:

Exampleacb_hypgeom_lgamma_branch.cchecked by make checkdoc
#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;
}
Output
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

Γ(z)\Gamma(z) is small here because zz is close to the negative real axis between two poles; 1/Γ(z)1/\Gamma(z), which is entire, is large.

References#

Cite this page

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-11-02).