Gamma Function Calculator — Γ(x)

Compute Γ(x) for any real number using the Lanczos approximation

Quick Examples

Any real number except 0, −1, −2, −3, ...

Γ( )

Special Values of Γ(x)

x Γ(x) Exact Form Notes
1/21.7724538509√πHalf-integer, Gaussian integral
110! = 1Γ(1) = 1 by definition
3/20.8862269255√π / 2½ · Γ(1/2)
211! = 1Γ(2) = 1
5/21.32934038823√π / 4Double factorial form
322! = 2Γ(3) = 2
463! = 6Γ(4) = 6
5244! = 24Γ(5) = 24
61205! = 120Γ(6) = 120
−1/2−3.5449077018−2√πNegative half-integer
−3/22.36327180124√π / 3Alternating sign pattern

What is the Gamma Function Γ(x)?

The Gamma function, denoted Γ(x) (capital Greek letter Gamma), is one of the most important special functions in mathematics. It was introduced by the Swiss mathematician Leonhard Euler in 1729 as a generalization of the factorial function to all real and complex numbers. While the factorial n! is defined only for non-negative integers, the Gamma function extends this concept smoothly across the entire real line (and beyond, into the complex plane), except at the non-positive integers 0, −1, −2, −3, ...

The formal definition is an improper integral known as the Euler integral of the second kind:

Γ(x) = ∫₀^∞ t^(x−1) · e^(−t) dt     (valid for x > 0)

This integral converges for all real numbers with positive real part. For negative non-integer values, Γ(x) is defined via analytic continuation using the recurrence relation.

The Factorial Connection: Γ(n) = (n−1)!

The most celebrated property of the Gamma function is its relationship to factorials. For any positive integer n:

Γ(n) = (n − 1)!    →    Γ(1)=1,   Γ(2)=1,   Γ(3)=2,   Γ(4)=6,   Γ(5)=24

This means the Gamma function is the unique meromorphic function that interpolates the factorials and satisfies the recurrence Γ(x+1) = x·Γ(x) with Γ(1) = 1. Numerically, you can think of Γ as a smooth curve that passes through the points (1, 1), (2, 1), (3, 2), (4, 6), (5, 24), (6, 120), ... — connecting the factorial dots.

Recurrence Relation: Γ(x+1) = x·Γ(x)

The fundamental recurrence relation is:

Γ(x + 1) = x · Γ(x)

This mirrors the factorial identity (n+1)! = (n+1)·n! and can be proven by integration by parts in the defining integral. It means that once you know Γ(x) in any interval of length 1, you can extend it to the entire positive real line. This recurrence also allows the function to be extended to negative non-integer values by rearranging to Γ(x) = Γ(x+1)/x.

Euler's Reflection Formula

Euler discovered a beautiful symmetry linking Γ(x) and Γ(1−x):

Γ(x) · Γ(1 − x) = π / sin(πx)

This remarkable formula connects the Gamma function to trigonometry. At x = 1/2, it gives Γ(1/2)² = π/sin(π/2) = π, confirming Γ(1/2) = √π. The reflection formula is also used algorithmically: to compute Γ(x) for x < 0.5, compute Γ(1−x) and apply the formula, reducing the problem to a region where numerical methods are most stable.

The Special Value Γ(1/2) = √π

The most famous special value of the Gamma function is Γ(1/2) = √π ≈ 1.7724538509. This result is derived from the Gaussian integral:

∫₋∞^∞ e^(−t²) dt = √π    ⟹    Γ(1/2) = √π

By substituting u = t² in the Gamma integral, we get Γ(1/2) = 2∫₀^∞ e^(−u²) du = √π. The half-integer values more generally satisfy Γ(n + 1/2) = (2n)!·√π / (4^n · n!), giving the sequence: Γ(1/2)=√π, Γ(3/2)=√π/2, Γ(5/2)=3√π/4, and so on.

Poles at Non-Positive Integers

The Gamma function has simple poles (vertical asymptotes) at x = 0, −1, −2, −3, ... At each of these points, |Γ(x)| → ∞. The function alternates sign between consecutive poles: it is positive on (0, +∞) and on (−2, −1), (−4, −3), ... and negative on (−1, 0), (−3, −2), ...

The residue at each pole x = −n (for n = 0, 1, 2, ...) is (−1)^n / n!. These poles are visible as sharp vertical lines on the Gamma function chart. This is why x = 0, −1, −2, −3, ... are excluded from the calculator's domain.

The Lanczos Approximation

For numerical computation, the Lanczos approximation (introduced by Cornelius Lanczos in 1964) is the most widely used algorithm. It approximates Γ(z) for z with positive real part as:

Γ(z+1) ≈ √(2π) · (z + g + 0.5)^(z+0.5) · e^(−(z+g+0.5)) · A_g(z)

where A_g(z) is a rational function whose coefficients depend on the parameter g. This calculator uses g = 7 with 9 Lanczos coefficients, providing about 15 digits of accuracy for all real inputs. For x < 0.5, Euler's reflection formula is applied first, then the approximation is used.

The Log-Gamma Function and Stirling's Approximation

For large values of x, Γ(x) grows extremely rapidly (faster than any exponential). The log-gamma function ln(Γ(x)) is therefore more useful numerically, as it grows only as x·ln(x). Stirling's approximation gives:

ln(Γ(x)) ≈ (x − 0.5)·ln(x) − x + 0.5·ln(2π) [for large x]

Log-gamma is used extensively in statistical computing: log-likelihoods, log-probabilities, and normalizing constants are computed in log-space to avoid overflow. This calculator always shows both Γ(x) and ln|Γ(x)|.

Relationship to the Beta Function

The Gamma function is intimately related to the Beta function B(a, b), which appears in probability and statistics:

B(a, b) = Γ(a) · Γ(b) / Γ(a + b)

This identity connects the two fundamental Euler integrals and is used to evaluate the normalizing constants for the Beta distribution, the Dirichlet distribution, and many others. The beta function can also be written as B(a,b) = ∫₀¹ t^(a−1)·(1−t)^(b−1) dt.

Applications of the Gamma Function

  • Statistics: Gamma distribution PDF, chi-squared distribution, Student's t-distribution, F-distribution all involve Γ(x). The incomplete gamma function defines their CDFs.
  • Combinatorics: Generalizing binomial coefficients to non-integer arguments: C(n,k) = Γ(n+1) / (Γ(k+1)·Γ(n−k+1)).
  • Quantum Physics: Feynman path integrals, dimensional regularization in quantum field theory, and calculations in statistical mechanics use the Gamma function.
  • String Theory: The Veneziano amplitude and dual resonance models are expressed in terms of the beta/gamma function.
  • Number Theory: The Riemann zeta function satisfies the functional equation ξ(s) = π^(−s/2)·Γ(s/2)·ζ(s), linking it to the Gamma function.
  • Engineering: Signal processing (fractional calculus), control theory, and fluid dynamics problems involving Bessel functions.
  • Computer Science: Log-gamma is used in computing log-probabilities for machine learning, natural language processing, and Bayesian inference.

The Digamma Function

The digamma function ψ(x) is the logarithmic derivative of the Gamma function: ψ(x) = d/dx[ln(Γ(x))] = Γ'(x)/Γ(x). It appears in problems involving harmonic numbers, polygamma functions, and regularization in quantum field theory. For positive integers n, ψ(n) = −γ + H(n−1), where γ ≈ 0.5772156649 is the Euler–Mascheroni constant and H(n) is the nth harmonic number.

Frequently Asked Questions

What is the Gamma function Γ(x)?
The Gamma function Γ(x) is a generalization of the factorial function to all real and complex numbers except non-positive integers. Defined by Γ(x) = ∫₀^∞ t^(x−1)·e^(−t) dt, it interpolates the factorials smoothly: Γ(n) = (n−1)! for positive integers. Introduced by Euler in 1729, it is one of the most important special functions in mathematics.
How is the Gamma function related to factorials?
For any positive integer n, Γ(n) = (n−1)!. So Γ(1)=0!=1, Γ(2)=1!=1, Γ(3)=2!=2, Γ(4)=3!=6, Γ(5)=4!=24, and so on. The recurrence Γ(x+1) = x·Γ(x) directly mirrors the factorial rule n! = n·(n−1)!. The Gamma function is the unique smooth extension of the factorial to all non-integer reals.
What is Γ(1/2)?
Γ(1/2) = √π ≈ 1.7724538509. This is proven using the Gaussian integral: ∫₋∞^∞ e^(−t²) dt = √π. Substituting u = t² in Γ(1/2) = ∫₀^∞ t^(−1/2)·e^(−t) dt yields 2∫₀^∞ e^(−u²) du = √π. More generally, Γ(n + 1/2) = (2n)!·√π / (4^n·n!) — so Γ(3/2) = √π/2, Γ(5/2) = 3√π/4, etc.
Why is the Gamma function undefined at 0, −1, −2, ...?
The Gamma function has simple poles (vertical asymptotes where |Γ(x)| → ∞) at all non-positive integers: 0, −1, −2, −3, ... This occurs because the recurrence Γ(x) = Γ(x+1)/x reaches division by zero at x=0, and applying it repeatedly reaches poles at all negative integers. The integral definition also diverges at x ≤ 0 integers because the integrand t^(x−1) is not integrable near t=0.
What is the recurrence relation of the Gamma function?
The fundamental recurrence is Γ(x+1) = x·Γ(x) for all x ≠ 0, −1, −2, ... This means knowing Γ on any interval of length 1 determines it everywhere. Starting from Γ(1) = 1: Γ(2)=1·Γ(1)=1, Γ(3)=2·Γ(2)=2, Γ(4)=3·Γ(3)=6, and so on. For negative values: Γ(−0.5) = Γ(0.5)/(−0.5) = √π/(−0.5) = −2√π ≈ −3.5449.
How is the Gamma function computed numerically?
The Lanczos approximation (1964) is the standard algorithm, yielding arbitrary precision with finite coefficients. For x ≥ 0.5: Γ(x) ≈ √(2π) · (x+g−0.5)^(x−0.5) · e^(−(x+g−0.5)) · A_g(x), where g is a tuning parameter and A_g(x) is a rational function. For x < 0.5, Euler's reflection formula Γ(x)·Γ(1−x) = π/sin(πx) maps the computation to x ≥ 0.5. This calculator uses g=7 with 9 coefficients, achieving ~15-digit precision.
Where is the Gamma function used in statistics?
The Gamma function underpins many statistical distributions: (1) Gamma distribution: PDF = x^(α−1)·e^(−x/β) / (β^α·Γ(α)); (2) Chi-squared: a special case of the gamma distribution with α=k/2, β=2; (3) Student's t-distribution: PDF involves Γ((ν+1)/2)/Γ(ν/2); (4) Beta distribution: normalizing constant 1/B(α,β) = Γ(α+β)/(Γ(α)·Γ(β)); (5) Negative binomial, Dirichlet, and many more. Log-gamma functions are used in computing log-likelihoods and log-probabilities.