Skip to content

Gamma ​

The gamma function Γ(z)\Gamma(z), extending the factorial to real and complex arguments; with two arguments, the upper incomplete gamma function.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaGamma functionMathWorldGammaFunctionWikidataQ190573Encyclopedia of MathematicsGamma-functionnLabGamma functionBritannicascience/gamma-functionDLMF5.2.E1FungrimGamma✓Fungrim entryWolfram LanguageGamma!
Gamma(z)the gamma function Γ(z)\Gamma(z).
SageMathgamma(z)SymPygamma(z)mpmathgamma(z)Juliaenumeratio_ball(gamma, z)Rustgamma(z)
Gamma(s, z)the upper incomplete gamma function Γ(s,z)=∫z∞ts−1e−t dt\Gamma(s, z) = \int_z^\infty t^{s-1} e^{-t}\,dt.
SageMathgamma_inc(s, z)SymPyuppergamma(s, z)mpmathgammainc(s, z)Juliaenumeratio_ball(gamma, s, z)Rustupper_gamma(s, z)
Gamma(s, z0, z1)the generalized incomplete gamma Γ(s,z0)−Γ(s,z1)=∫z0z1ts−1e−t dt\Gamma(s, z_0) - \Gamma(s, z_1) = \int_{z_0}^{z_1} t^{s-1} e^{-t}\,dt; at z0=0z_0 = 0 the LOWER incomplete gamma γ(s,z1)\gamma(s, z_1).
mpmathgammainc(s, z0, z1)Juliaenumeratio_ball((a, z0, z1) -> gamma(a, z0) - gamma(a, z1), s, z0, z1)
Typed signatures
TypePackageApplies
(complex | infinity, (complex | infinity)?) -> numbercompute-enginealways
(complex | infinity, (complex | infinity)?, (complex | infinity)?) -> numberanalyticreplaces compute-enginealways

Domain: Special functions

Details

The gamma function Γ(z)=∫0∞tz−1e−t dt\Gamma(z) = \int_0^\infty t^{z-1} e^{-t}\,dt for Re⁡(z)>0\operatorname{Re}(z) > 0 (DLMF 5.2.1), continued analytically elsewhere, is the standard extension of the factorial to real and complex arguments. The two- and three-argument forms below split that same integral at a finite endpoint rather than ∞\infty.

  • Extends the factorial: Γ(n)=(n−1)!\Gamma(n) = (n-1)! for positive integers n, so Factorial is Γ(n+1)\Gamma(n+1).
  • Functional equation: Γ(z+1)=z Γ(z)\Gamma(z+1) = z\,\Gamma(z).
  • Reflection formula: Γ(z) Γ(1−z)=πsin⁡(πz)\Gamma(z)\,\Gamma(1-z) = \dfrac{\pi}{\sin(\pi z)}, linking Γ\Gamma at z and 1−z1-z.
  • Poles at the nonpositive integers 0,−1,−2,…0, -1, -2, \ldots, where Γ\Gamma diverges to ComplexInfinity.
  • Γ(1/2)=π\Gamma(1/2) = \sqrt{\pi}, the constant behind the normal distribution's normalizing factor. See Erf.
  • compute-engine's plain evaluation would otherwise leave Gamma at exact integer or rational arguments unevaluated (@enumeratio/analytic overrides it, reducing every integer and half-integer exactly); a floating-point argument, or N(), still reduces to a decimal.
  • The three-argument form (@enumeratio/analytic) is Wolfram's generalized incomplete gamma, the integral between two limits: Γ(s,z0,z1)=Γ(s,z0)−Γ(s,z1)\Gamma(s, z_0, z_1) = \Gamma(s, z_0) - \Gamma(s, z_1). It is the only spelling here for the LOWER incomplete gamma γ(s,z)=Γ(s,0,z)\gamma(s, z) = \Gamma(s, 0, z), which is what the Gamma-distribution CDF and the χ2\chi^2 CDF are built from. See GammaRegularized for the normalized version.
  • Γ(1,z)=e−z\Gamma(1, z) = e^{-z}, also supplied by @enumeratio/analytic -- exact and valid for symbolic zz, which is what makes Γ(1,0,z)\Gamma(1, 0, z) collapse to 1−e−z1 - e^{-z} as Wolfram's does.
  • Differs from Wolfram: Gamma(1/2,x)Gamma(1/2, x) reduces to π erfc(x)\sqrt\pi\,\mathrm{erfc}(\sqrt x) on evaluation; Wolfram keeps Gamma[1/2, x] until FunctionExpand. Both agree as identities.

Plot

ComplexPlot
real slice

Examples

13 more kept as data, checked against the oracles
Basic #

A pole of Gamma

live ↗
InΓ(0)Γ(0)Out∞~\tilde∞

A floating-point argument evaluates directly to a high-precision decimal

live ↗
InΓ(2.5)Γ(2.5)Out1.329 340 388 179 137 020 471.329\,340\,388\,179\,137\,020\,47

Threads over a list, so poles evaluate concretely even inside one

live ↗
InΓ([0,−1])Γ(\bigl\lbrack0, -1\bigr\rbrack)Out[∞~,∞~]\bigl\lbrack\tilde∞, \tilde∞\bigr\rbrack

Three arguments: the integral between two limits. With z0=0z_0 = 0 this is the lower incomplete gamma γ(5/2,3/2)\gamma(5/2, 3/2)

live ↗
InΓ(2.5,0,1.5)Γ(2.5, 0, 1.5)Out0.398 820 945 392 343 90.398\,820\,945\,392\,343\,9

∫3/23t3/2e−t dt=Γ(5/2,3/2)−Γ(5/2,3)\int_{3/2}^{3} t^{3/2} e^{-t}\,dt = \Gamma(5/2, 3/2) - \Gamma(5/2, 3)

live ↗
InΓ(2.5,1.5,3)Γ(2.5, 1.5, 3)Out0.523 450 266 915 488 60.523\,450\,266\,915\,488\,6

A machine-precision argument: Γ(4.5)=11.6317…\Gamma(4.5) = 11.6317\ldots

live ↗
InΓ(4.5)Γ(4.5)Out11.631 728 396 567 448 929 111.631\,728\,396\,567\,448\,929\,1

Γ(5)=4!=24\Gamma(5) = 4! = 24

live ↗
InΓ(5)Γ(5)Out2424
Scope #

Threads over a list and reduces each integer argument to the concrete factorial, overriding compute-engine's plain policy of leaving exact Gamma arguments symbolic

live ↗
InΓ([1,2,3,4,5])Γ(\bigl\lbrack1, 2, 3, 4, 5\bigr\rbrack)Out[1,1,2,6,24]\bigl\lbrack1, 1, 2, 6, 24\bigr\rbrack

Γ(5/2)=34π\Gamma(5/2) = \frac{3}{4}\sqrt{\pi}, via the half-integer recurrence

live ↗
InΓ(52)Γ(\frac{5}{2})Out3π4\frac{3\sqrt{π}}{4}

Complex arguments evaluate directly

live ↗
InΓ(2.3+i)Γ(2.3+i)Out0.719 140 936 537 281 1+0.540 614 467 909 848 7i0.719\,140\,936\,537\,281\,1+0.540\,614\,467\,909\,848\,7i

Half-integers have closed forms: Γ(7/2)=158π\Gamma(7/2) = \frac{15}{8}\sqrt{\pi}

live ↗
InΓ(72)Γ(\frac{7}{2})Out15π8\frac{15\sqrt{π}}{8}

...including negative half-integers: Γ(−3/2)=43π\Gamma(-3/2) = \frac{4}{3}\sqrt{\pi}

live ↗
InΓ(−32)Γ(-\frac{3}{2})Out4π3\frac{4\sqrt{π}}{3}

Γ(∞)=∞\Gamma(\infty) = \infty

live ↗
InΓ(∞)Γ(∞)Out∞∞

Values far past the double range: Γ(200.5)≈5.57×10373\Gamma(200.5) \approx 5.57 \times 10^{373}

live ↗
InΓ(200.5)Γ(200.5)Out5.573 168 944 801 379 133 64⋅103735.573\,168\,944\,801\,379\,133\,64\cdot10^{373}

Two arguments: the upper incomplete gamma Γ(5/2,3/2)\Gamma(5/2, 3/2)

live ↗
InΓ(2.5,1.5)Γ(2.5, 1.5)Out0.930 519 442 786 793 10.930\,519\,442\,786\,793\,1

An integer order reduces to a closed form: Γ(2,x)=(1+x)e−x\Gamma(2, x) = (1 + x)e^{-x}

live ↗
InΓ(2,x)Γ(2, x)Out(x+1)e−x(x+1)e^{-x}

Γ(2,1)=2/e\Gamma(2, 1) = 2/e, the same closed form at an exact argument

live ↗
InΓ(2,1)Γ(2, 1)Out2e\frac{2}{e}

Listable: threads elementwise over a matrix, and each entry reduces (Γ(2,0)=1\Gamma(2, 0) = 1)

live ↗
InΓ(2,[[72,0],[0,132]])Γ(2, \bigl\lbrack\bigl\lbrack\frac{7}{2}, 0\bigr\rbrack, \bigl\lbrack0, \frac{13}{2}\bigr\rbrack\bigr\rbrack)Out[[92e7/2,1],[1,152e13/2]]\bigl\lbrack\bigl\lbrack\frac{9}{2e^{7/2}}, 1\bigr\rbrack, \bigl\lbrack1, \frac{15}{2e^{13/2}}\bigr\rbrack\bigr\rbrack

Interval arithmetic: the image of [1.4,1.5][1.4, 1.5], whose lower end is Γ\Gamma's minimum at x0=1.4616…x_0 = 1.4616\ldots

live ↗
InΓ(Interval(1.4,1.5))Γ(\mathrm{Interval}(1.4, 1.5))OutInterval(0.885 603 194 410 888 7,0.887 263 817 503 075 3)\mathrm{Interval}(0.885\,603\,194\,410\,888\,7, 0.887\,263\,817\,503\,075\,3)

Uncertainty propagation: Γ(2.5±0.01)=1.3293±0.0093\Gamma(2.5 \pm 0.01) = 1.3293 \pm 0.0093

live ↗
InΓ(Around(2.5,0.01))Γ(\mathrm{Around}(2.5, 0.01))OutAround(1.329 340 388 179 137,0.009 347 345 216 260 856)\mathrm{Around}(1.329\,340\,388\,179\,137, 0.009\,347\,345\,216\,260\,856)

To 40 significant digits, every one correctly rounded

live ↗
InN(Γ(13),40)N(Γ(\frac{1}{3}), 40)Out2.678 938 534 707 747 633 655 692 940 974 677 644 1292.678\,938\,534\,707\,747\,633\,655\,692\,940\,974\,677\,644\,129

Γ(−∞)\Gamma(-\infty) is Indeterminate -- the poles at every non-positive integer accumulate along the negative real axis

live ↗
InΓ(−∞)Γ(-∞)OutIndeterminate⁡\operatorname{Indeterminate}

Known value · Wolfram Gamma[-Infinity]

Γ(∞~)\Gamma(\tilde\infty) is Indeterminate: no direction to take the limit along

live ↗
InΓ(∞~)Γ(\tilde∞)OutIndeterminate⁡\operatorname{Indeterminate}

lim⁡t→∞Γ(it)=0\lim_{t\to\infty}\Gamma(it) = 0: ∣Γ(iy)∣→0|\Gamma(iy)| \to 0 as y→∞y \to \infty

live ↗
Inlim⁡t→∞Γ(it)\lim_{t→∞}Γ(i t)Out00

Known value · DLMF 5.11.9; Wolfram Gamma[I Infinity]

Gamma of the directed infinity i∞i\infty stays unevaluated; the limit along it is in the Limit example above

live ↗
InΓ(DirectedInfinity(i))Γ(\mathrm{DirectedInfinity}(i))OutΓ(DirectedInfinity(i))Γ(\mathrm{DirectedInfinity}(i))

Known value · DLMF 5.11.9; Wolfram Gamma[I Infinity]

Threads over a list of infinities, each reducing to its own value

live ↗
InMap(Γ,[∞,−∞,∞~])\mathrm{Map}(Γ, \bigl\lbrack∞, -∞, \tilde∞\bigr\rbrack)Out[∞,Indeterminate⁡,Indeterminate⁡]\bigl\lbrack∞, \operatorname{Indeterminate}, \operatorname{Indeterminate}\bigr\rbrack
Applications #

The volume of a unit 4-ball is πn/2/Γ(n/2+1)\pi^{n/2}/\Gamma(n/2+1); at n=4n=4 that's π2/Γ(3)=π2/2\pi^2/\Gamma(3) = \pi^2/2

live ↗
Inπ2Γ(3)=π22\frac{π^2}{Γ(3)}=\frac{π^2}{2}OutTrue\mathrm{True}
Properties #

Extends the factorial: Γ(n+1)=n!\Gamma(n+1) = n!, so Γ(6)=5!\Gamma(6) = 5!

live ↗
InΓ(6)=5!Γ(6)=5!OutTrue\mathrm{True}

Functional equation Γ(z+1)=z Γ(z)\Gamma(z+1) = z\,\Gamma(z), here at z=5z = 5

live ↗
InΓ(6)=5Γ(5)Γ(6)=5Γ(5)OutTrue\mathrm{True}

Reflection formula Γ(z)Γ(1−z)=π/sin⁡(πz)\Gamma(z)\Gamma(1-z) = \pi/\sin(\pi z), here at z=1/3z = 1/3

live ↗
InΓ(13)Γ(23)=πsin⁡(π3)Γ(\frac{1}{3})Γ(\frac{2}{3})=\frac{π}{\sin(\frac{π}{3})}OutTrue\mathrm{True}

Γ(1/2)=π\Gamma(1/2) = \sqrt{\pi}

live ↗
InΓ(12)=πΓ(\frac{1}{2})=\sqrt{π}OutTrue\mathrm{True}

Γ(1,z)=e−z\Gamma(1, z) = e^{-z}, exact and symbolic in zz

live ↗
InΓ(1,z)Γ(1, z)Oute−ze^{-z}

…so γ(1,z)=1−e−z\gamma(1, z) = 1 - e^{-z}: the exponential distribution's CDF, falling out of the general form

live ↗
InΓ(1,0,z)Γ(1, 0, z)Out1−e−z1-e^{-z}

Now that Γ(2,z)\Gamma(2, z) has a closed form, the three-argument difference reduces through it too: Γ(2,0,z)=1−(1+z)e−z\Gamma(2, 0, z) = 1 - (1+z)e^{-z}. Wolfram's bare Gamma[2, 0, z] stays unevaluated (only FunctionExpand reaches this); this engine reduces both

live ↗
InΓ(2,0,z)Γ(2, 0, z)Out1−(z+1)e−z1-(z+1)e^{-z}

Γ(a,0)=Γ(a)\Gamma(a, 0) = \Gamma(a): the incomplete gamma from zero is the complete one

live ↗
InΓ(a,0)Γ(a, 0)OutΓ(a)Γ(a)

Γ(0,z)=E1(z)\Gamma(0, z) = E_1(z), the exponential integral: E1(3/2)=0.10002…E_1(3/2) = 0.10002\ldots

live ↗
InΓ(0,1.5)Γ(0, 1.5)Out0.100 019 582 406 632 520.100\,019\,582\,406\,632\,52

Γ(1/2,x)=π erfc⁡(x)\Gamma(1/2, x) = \sqrt{\pi}\,\operatorname{erfc}(\sqrt{x}). See Erfc

live ↗
InΓ(12,x)Γ(\frac{1}{2}, x)Outerfc⁡(x)π\operatorname{erfc}(\sqrt{x})\sqrt{π}

Γ′(x)=Γ(x) ψ(x)\Gamma'(x) = \Gamma(x)\,\psi(x), so the logarithmic derivative is Digamma

live ↗
IndΓ(x)dxΓ(x)\frac{\frac{\mathrm{d}Γ(x)}{\mathrm{d}x}}{Γ(x)}OutDigamma(x)\mathrm{Digamma}(x)
live ↗
In1Γ(12)\frac{1}{Γ(\frac{1}{2})}Out1π\sqrt{\frac{1}{π}}

Known value · Wolfram MathematicalFunctionData, Gamma, Euler's infinite product

live ↗
InΓ(12)2Γ(\frac{1}{2})^2Outππ

Known value · Wolfram MathematicalFunctionData, Gamma, Euler's reflection formula

live ↗
InΓ(−12)Γ(12)Γ(-\frac{1}{2})Γ(\frac{1}{2})Out−2π-2π

Known value · Wolfram MathematicalFunctionData, Gamma, Reflection formula

live ↗
In∏k=01Γ(12(2k+12))\prod_{k=0}^1Γ(\frac{1}{2}(2k+\frac{1}{2}))OutΓ(14)Γ(54)Γ(\frac{1}{4})Γ(\frac{5}{4})

Known value · Wolfram MathematicalFunctionData, Gamma, Schobloch's reciprocity formula

Neat examples #

Squaring the reflection formula at z=1/2z=1/2 collapses it to Γ(1/2)2=π\Gamma(1/2)^2 = \pi

live ↗
InΓ(1/2)2=πΓ(1/2)^2=πOutTrue\mathrm{True}

∣Γ(i)∣2=π/sinh⁡π=0.27203…|\Gamma(i)|^2 = \pi/\sinh\pi = 0.27203\ldots

live ↗
InN(∣Γ(i)∣2)N(\vert Γ(i)\vert^2)Out0.272 029 054 982 132 823 5420.272\,029\,054\,982\,132\,823\,542
About
Examples57
Checked againstWolfram Language 52 agree4 differ1 unevaluatedSageMath 49 agree3 differSymPy 50 agree2 differmpmath 38 agree4 errorJulia 35 agree7 errorRust 19 agree2 unevaluated5 error
CrosswalkWikipediaMathWorldWikidataEncyclopedia of MathematicsnLabBritannicaDLMFFungrimFungrim entry ×101Wolfram LanguageSageMath ×2SymPy ×2mpmath ×3Julia ×3Rust ×2

Implementation

mappedwolframpackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts

Wolfram's generalized incomplete gamma is the difference of two upper incomplete gammas, written out; at z0 = 0 it is the lower incomplete gamma.

mappedmpmathpackages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts

The incomplete gamma from z0 to z1, the difference of two upper ones.

mappedsagepackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts

a, z > 0 only.

See also: Factorial, GammaLn, LogGamma, GammaRegularized, Digamma, Beta