Understanding the gamma, beta and error function calculator — concept and principle
The gamma function Γ(x) extends the factorial to non-integer numbers, the beta function B(x, y) is built from it, and the error function erf(x) measures areas under the bell curve. This calculator evaluates Γ(x), ln Γ(x), B(x, y), erf(x) and erfc(x) = 1 − erf(x). These special functions appear in probability and statistics (gamma, beta, chi-square and normal distributions), physics (diffusion, heat flow) and combinatorics.
How it is calculated
- Gamma: Γ(x) = ∫₀^∞ tˣ⁻¹ e⁻ᵗ dt for x > 0, with Γ(n) = (n − 1)! for positive integers n. The calculator uses the Lanczos approximation, accurate to about 15 significant digits.
- Log-gamma: ln Γ(x), useful because Γ grows too fast to store for large x.
- Beta: B(x, y) = Γ(x)Γ(y) ÷ Γ(x + y), computed as exp(ln Γ(x) + ln Γ(y) − ln Γ(x + y)).
- Error function: erf(x) = (2/√π) ∫₀ˣ e⁻ᵗ² dt, by its Taylor series for |x| < 2; erfc(x) = 1 − erf(x) comes directly from a continued fraction for |x| ≥ 2, so tiny tail values stay accurate.
The principle
Integrating by parts gives Γ(x + 1) = x·Γ(x), the same recursion as n! = n·(n − 1)!, and Γ(1) = 1, so Γ reproduces the factorials and fills in the values between them smoothly. A key half-integer value is Γ(1/2) = √π, which comes from the Gaussian integral. The error function is the area under e⁻ᵗ² scaled so that erf(∞) = 1; it is directly linked to the normal distribution: P(|Z| ≤ z) = erf(z/√2) for a standard normal Z.
Worked example
- Default inputs: x = 4.5, y = 2.
- Gamma: Γ(4.5) = 3.5 × 2.5 × 1.5 × 0.5 × Γ(0.5) = 6.5625 × √π = 11.6317284.
- Log-gamma: ln 11.6317284 = 2.453736571.
- Beta: B(4.5, 2) = Γ(4.5)Γ(2) ÷ Γ(6.5). Since Γ(6.5) = 5.5 × 4.5 × Γ(4.5) and Γ(2) = 1, B = 1 ÷ 24.75 = 0.0404040404.
- Error function: erf(4.5) = 0.9999999998, and erfc(4.5) = 1.96616e-10.
| x | Γ(x) |
|---|---|
| 1.12 | 0.9417426998 |
| 2.25 | 1.133003096 |
| 3.38 | 2.902858374 |
| 4.5 | 11.6317284 |
| 5.62 | 64.11928889 |
| 6.75 | 453.0107661 |
| 9 | 40,320 |
How to read the result
For x > 0, Γ(x) has a minimum of about 0.8856 near x ≈ 1.4616 and grows faster than any exponential afterwards. erf(x) rises from 0 at x = 0 to about 0.8427 at x = 1 and 0.9953 at x = 2; above about 4 it is 1 to many decimal places, which is why erfc is reported separately.
Common mistakes
- Mixing up Γ(n) and n!: Γ(5) = 4! = 24, not 5!.
- Entering x = 0 or a negative integer, where Γ has poles and is undefined.
- Using erf(z) instead of erf(z/√2) for normal probabilities.
Frequently asked questions
What is 0.5 factorial?
(0.5)! = Γ(1.5) = √π/2 ≈ 0.8862.
Where is the beta function used?
It normalises the beta distribution, which models probabilities and proportions, and it appears in Bayesian statistics.
Is erf the same as the normal CDF?
They are related: Φ(z) = [1 + erf(z/√2)] ÷ 2.
Sources: NIST Digital Library of Mathematical Functions, Chapter 5 Gamma Function and Chapter 7 Error Functions (dlmf.nist.gov) · Lanczos, C. (1964), A precision approximation of the gamma function, SIAM Journal on Numerical Analysis, Ser. B, 1, 86–96 · Press, W. H., et al., Numerical Recipes, 3rd ed., §6.1 and §6.2