TL;DR
The factorial is defined only for whole numbers, and it is the product . The gamma function fills in the gaps: it is defined for every real and complex except zero and the negative whole numbers, and it equals at every positive whole number . It is defined as an integral, so it can be computed, differentiated and used in probability formulas.
Where you'll see it: in the normalising constants of the gamma, beta, Student-t and chi-squared distributions, in volumes of high-dimensional balls, and in the log-gamma function that software uses to avoid overflow.
Intuition
Counting products, then smoothing them
The factorial counts orderings. There are ways to line up three distinct objects, and ways to line up five. The factorial grows by a fixed multiplicative step: each new integer multiplies the running product by one more factor. The question is what "multiply by " should mean when is or .
The gamma function answers with a smooth curve through the factorial values. It is built so that the factorial's own rule still holds: going up by one multiplies the value by the new input. That single rule, , together with and a requirement that the curve be well behaved (the Bohr-Mollerup theorem makes this precise using log-convexity), pins the function down. Its values grow as fast as the factorial, and between the integers it bends smoothly.
- Γ(x)
The math
For real , the gamma function is the integral
Here is a dummy variable, is the exponential function, and is an ordinary power. The integral converges for every . It extends to other values by the recurrence in the next subsection.
The recurrence
Take the integral for and integrate by parts (see Integration by Parts) with and , so and :
The boundary term vanishes at both ends for : at because , and at infinity because the exponential wins. So
The factorial link
Start with . Applying the recurrence repeatedly gives , , and in general
The shift by one is a historical convention: the integral's exponent is , so matches rather than .
Half-integer values
Set in the integral and substitute , so :
The last step uses the Gaussian integral (half of , the integral behind the Gaussian (Normal) Distribution). Combining this with the recurrence gives every half-integer, for example .
Negative values
Rearrange the recurrence to . For between and this extends the function, and the pole at each non-positive whole number comes from the division by zero. Those are the points where is undefined.
Worked examples
- Start from the definition: .
- Apply the recurrence with : .
- With : .
- With : .
- Check: . Matches.
Interpretation: the gamma function at is the factorial at , and the recurrence reproduces the factorial exactly at whole numbers.
The volume of a unit ball in dimensions is . Take , the ordinary ball.
- Compute the gamma value: .
- Compute the power: .
- Divide: .
- Compare with the known formula . Matches.
Interpretation: the gamma function gives the ball volume formula for every dimension, including the half-integer cases that the factorial cannot reach.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Integer argument, small | Factorial is exact and simple | Use directly |
| Large argument, such as | overflows the floating-point range | Use the log-gamma function, lgamma in most libraries |
| Argument near zero or a negative whole number | Value is huge or undefined | Check the domain before calling; use the reflection formula for negative values |
| Very large with asymptotics needed | Exact evaluation is wasteful | Stirling's approximation, |
Most numerical bugs with the gamma function are overflow bugs. A product of two gamma values can be fine on paper and produce infinity in code. Work in logs whenever the arguments are large.
History
Leonhard Euler introduced the function in the 1720s and 1730s while looking for a way to interpolate the factorial, and he worked it out in a letter to Christian Goldbach. Euler's integral form is the one used above. Adrien-Marie Legendre gave the capital Γ notation in the early 1800s, and the name "gamma function" stuck. The function caught on because it solved a real problem: it made the factorial usable in analysis, where non-integer and complex arguments are routine. Today it appears in almost every branch of applied mathematics, especially probability, where it sets the normalising constants of many distributions.
Check yourself
QuestionRecall: what is , and what does it equal in factorial terms?Show answer
. The gamma function at equals the factorial at .
QuestionComputation: use the recurrence and to find .Show answer
and . So .
QuestionWhy: why does the gamma function have poles at zero and the negative integers?Show answer
The recurrence divides by . At the division is by zero, and at each negative whole number the same thing happens once the chain of divisions reaches zero. The integral definition only works for , so the poles are where the extension has to blow up.
QuestionApplied: a program computes directly and returns infinity. What is the fix?Show answer
The true value of is far beyond the largest floating-point number, so the intermediate result overflows. Compute with a log-gamma routine instead, and combine it with other logs (for example, add and subtract logs in a likelihood) so the final answer is exponentiated only if it is small enough to represent.