Skip to content
Topos Uranos

The Gaussian integral, the gamma function and Stirling’s formula

Summary

The function e−x2e^{-x^2} has no elementary antiderivatives, and yet its integral over the whole line has an exact value: π\sqrt{\pi}. This lesson computes it without double integrals. The inequalities 1−x2≤e−x2≤11+x21 - x^2 \leq e^{-x^2} \leq \frac{1}{1 + x^2}, raised to the power nn, trap the integral of e−nx2e^{-n x^2} between two Wallis integrals, and the order of magnitude of those integrals, proved in the unit on the definite integral, gives the value. To pass from one improper integral to another, the change of variable from the lesson on conditional convergence is first extended to both endpoints. The gamma function, defined by Γ(x)=∫0∞tx−1e−t dt\Gamma(x) = \int_0^{\infty} t^{x - 1} e^{-t} \, \mathrm{d}t, converges exactly for x>0x > 0, satisfies Γ(x+1)=x Γ(x)\Gamma(x + 1) = x \, \Gamma(x) and extends the factorial to the positive reals: Γ(n+1)=n!\Gamma(n + 1) = n!; the Gaussian integral gives Γ(12)=π\Gamma\left(\frac{1}{2}\right) = \sqrt{\pi}. Finally, two bounds for the logarithm obtained with integrals show that the sequence n! ennnn\frac{n! \, e^n}{n^n \sqrt{n}} decreases toward a positive limit, and the formula for the values of the Wallis integrals identifies it: this is Stirling’s formula, n!∼2πn(ne)nn! \sim \sqrt{2\pi n} \left(\frac{n}{e}\right)^n, which makes the growth of the factorial precise, with an explicit bound for the error.

Learning objectives

  1. Extend the change of variable to integrals improper at both endpoints and use it, together with the Wallis integrals, to compute the Gaussian integral without double integrals.
  2. Define the gamma function, determine for which values its integral converges, and prove its functional equation and its values at the integers and at 12\frac{1}{2}.
  3. Prove Stirling’s formula with an explicit bound for the relative error.
  4. Compute improper integrals and limits of sequences by reducing them to the gamma function, to the Gaussian integral or to Stirling’s formula.

The Gaussian integral

The lesson on the fundamental theorem of calculus observed that ∫0xe−t2 dt\int_0^x e^{-t^2} \, \mathrm{d}t is an antiderivative of e−x2e^{-x^2} on the whole line, although none of its antiderivatives can be written with the elementary functions. Barrow’s rule therefore does not give the value of the integral over the whole line, which is an integral improper at both endpoints. To compute it, we shall compare it with other improper integrals by means of changes of variable. The lesson on conditional convergence of improper integrals proved the proposition on change of variable in an improper integral, for an improper right endpoint: if ff is continuous on [a,β)\ico{a}{\beta} and its integral converges, and φ\varphi is differentiable on [p,τ)\ico{p}{\tau}, with φ′\varphi' continuous, values in [a,β)\ico{a}{\beta} and φ(t)→β\varphi(t) \to \beta as t→τt \to \tau, then ∫pτf(φ(t)) φ′(t) dt=∫φ(p)βf(x) dx\int_p^{\tau} f(\varphi(t)) \, \varphi'(t) \, \mathrm{d}t = \int_{\varphi(p)}^{\beta} f(x) \, \mathrm{d}x. This lesson also uses it with both endpoints improper, and for increasing changes it suffices to split the integral and reflect the left half. We write t→τt \to \tau and t→pt \to p as in the definition of the improper integral in the lesson on improper integrals and convergence tests: t→∞t \to \infty or t→τ−t \to \tau^-, and t→−∞t \to -\infty or t→p+t \to p^+.

CorollaryIncreasing change of variable on an open interval

Let α<β\alpha < \beta, with α\alpha real or −∞-\infty and β\beta real or ∞\infty, and let ff be a continuous function on (α,β)\ioo{\alpha}{\beta}. Let p<τp < \tau, with pp real or −∞-\infty and τ\tau real or ∞\infty, and let φ\varphi be a strictly increasing function on (p,τ)\ioo{p}{\tau}, differentiable at every point, with φ′\varphi' continuous, with values in (α,β)\ioo{\alpha}{\beta}, and such that φ(t)\varphi(t) tends to α\alpha as t→pt \to p and to β\beta as t→τt \to \tau (to −∞-\infty or to ∞\infty if the endpoint is). If ∫αβf\int_{\alpha}^{\beta} f converges, then the integral on the left-hand side converges, and:

∫pτf(φ(t)) φ′(t) dt=∫αβf(x) dx\int_p^{\tau} f(\varphi(t)) \, \varphi'(t) \, \mathrm{d}t = \int_{\alpha}^{\beta} f(x) \, \mathrm{d}x

The right half is the proposition from the lesson on conditional convergence; the left half, the same proposition after reflecting both variables.

Proof

  1. ∫cτf(φ(t)) φ′(t) dt=∫dβf(x) dx\dato{der}{\int_c^{\tau} f(\varphi(t)) \, \varphi'(t) \, \mathrm{d}t = \int_d^{\beta} f(x) \, \mathrm{d}x}

    The integrand on the left-hand side, h(t)=f(φ(t)) φ′(t)h(t) = f(\varphi(t)) \, \varphi'(t), is continuous on (p,τ)\ioo{p}{\tau}, by the theorem on the composition of continuous functions, from the lesson on limit and continuity, and therefore integrable on every closed interval contained in (p,τ)\ioo{p}{\tau}. Let cc be a point of (p,τ)\ioo{p}{\tau} and d=φ(c)d = \varphi(c). By the proposition that the splitting point does not matter, from the lesson on improper integrals, ∫dβf\int_d^{\beta} f and ∫αdf\int_{\alpha}^{d} f converge. Since φ\varphi is increasing, its values on [c,τ)\ico{c}{\tau} lie in [d,β)\ico{d}{\beta}, and the proposition on change of variable in an improper integral, with a=da = d and the interval [c,τ)\ico{c}{\tau}, gives the right half.

  2. ∫αdf(x) dx=∫−c−ph(−t) dt=∫pcf(φ(t)) φ′(t) dt\dato{izq}{\int_{\alpha}^{d} f(x) \, \mathrm{d}x = \int_{-c}^{-p} h(-t) \, \mathrm{d}t = \int_p^c f(\varphi(t)) \, \varphi'(t) \, \mathrm{d}t}

    For the left half, let g(x)=f(−x)g(x) = f(-x) on [−d,−α)\ico{-d}{-\alpha} and ψ(t)=−φ(−t)\psi(t) = -\varphi(-t) on [−c,−p)\ico{-c}{-p}, where −α-\alpha and −p-p are ∞\infty if α\alpha or pp are −∞-\infty. The function ψ\psi is increasing and differentiable, with ψ′(t)=φ′(−t)\psi'(t) = \varphi'(-t) continuous, by the chain rule; its values lie in [−d,−α)\ico{-d}{-\alpha}, because those of φ\varphi on (p,c]\ioc{p}{c} lie in (α,d]\ioc{\alpha}{d}, and it tends to −α-\alpha as t→−pt \to -p, because φ(u)\varphi(u) tends to α\alpha as u→pu \to p and u=−tu = -t: if pp is real, by the proposition on translation and reflection, from the lesson on one-sided limits, and if p=−∞p = -\infty, because the condition u<Mu < M in the definition of the limit at −∞-\infty is the condition t>−Mt > -M; the change of sign of the values carries α\alpha to −α-\alpha, by the theorem on the limit of a linear combination, from the lesson on the algebra of limits, if α\alpha is real, and by the definition of infinite limits if it is not. By the lemma on the reflection of an improper integral, from the lesson on improper integrals, ∫−d−αg\int_{-d}^{-\alpha} g converges and equals ∫αdf\int_{\alpha}^{d} f, and the proposition on change of variable, with gg and ψ\psi, gives the first equality; since g(ψ(t)) ψ′(t)=h(−t)g(\psi(t)) \, \psi'(t) = h(-t), the same reflection lemma gives the second.

  3. ∫pτf(φ(t)) φ′(t) dt=∫αdf(x) dx+∫dβf(x) dx=∫αβf(x) dx\int_p^{\tau} f(\varphi(t)) \, \varphi'(t) \, \mathrm{d}t = \int_{\alpha}^{d} f(x) \, \mathrm{d}x + \int_d^{\beta} f(x) \, \mathrm{d}x = \resaltar{\int_{\alpha}^{\beta} f(x) \, \mathrm{d}x}

    Both halves converge, and by the definition of the improper integral on an open interval, with the splitting point cc, the integral on the left-hand side converges, and its value is the sum.

If ff is also continuous at a real endpoint, for example on [α,β)\ico{\alpha}{\beta}, the integral over (α,β)\ioo{\alpha}{\beta} is the same as over [α,β)\ico{\alpha}{\beta}: by the proposition on consistency with the Riemann integral, the half ∫αdf\int_{\alpha}^{d} f is the definite integral, and additivity adds the two halves. The same holds for the integrand on the left-hand side. If φ\varphi is decreasing, the reflection lemma reduces the change to an increasing one, as in the solved problem “A factorial hidden in a logarithm”.

LemmaBounds for the bell curve

For every real xx we have:

1−x2≤e−x2≤11+x21 - x^2 \leq e^{-x^2} \leq \frac{1}{1 + x^2}

and both equalities hold only at x=0x = 0. They are the fundamental inequality of the exponential at −x2-x^2 and at x2x^2.

Proof

  1. e−x2≥1−x2,ex2≥1+x2>0→e−x2≤11+x2e^{-x^2} \geq 1 - x^2, \qquad e^{x^2} \geq 1 + x^2 > 0 \rightarrow \resaltar{e^{-x^2} \leq \frac{1}{1 + x^2}}

    The corollary on the fundamental inequality for every real number, from the lesson on the number e, states that eu≥1+ue^u \geq 1 + u for every real uu, with equality only at u=0u = 0. With u=−x2u = -x^2 we obtain the first inequality, and with u=x2u = x^2, the second, after taking reciprocals of two positive numbers and writing e−x2=1ex2e^{-x^2} = \frac{1}{e^{x^2}} by the laws of real exponents, from the lesson on the exponential function.

  2. 1−x2=e−x2⇔x=0⇔e−x2=11+x21 - x^2 = e^{-x^2} \Leftrightarrow x = 0 \Leftrightarrow \resaltar{e^{-x^2} = \frac{1}{1 + x^2}}

    In both cases equality requires u=0u = 0, that is, x2=0x^2 = 0.

Integrated as they stand, the bounds say little: the integral of 1−x21 - x^2 over [−1,1]\icc{-1}{1} equals 43\frac{4}{3}, and that of 11+x2\frac{1}{1 + x^2} over the whole line, π\pi. Raised to the power nn, the three functions concentrate near 00, and the two bounds become Wallis integrals, from the lesson on techniques for definite integrals: Wn=∫0π2sin⁡nx dxW_n = \int_0^{\frac{\pi}{2}} \sin^n x \, \mathrm{d}x.

TheoremGaussian integral

The integral of e−x2e^{-x^2} over (−∞,∞)\ioo{-\infty}{\infty} converges, and:

∫−∞∞e−x2 dx=π,∫0∞e−x2 dx=π2\int_{-\infty}^{\infty} e^{-x^2} \, \mathrm{d}x = \sqrt{\pi}, \qquad \int_0^{\infty} e^{-x^2} \, \mathrm{d}x = \frac{\sqrt{\pi}}{2}

The integral of e−nx2e^{-n x^2} is the Gaussian integral divided by n\sqrt{n}, and it lies between two Wallis integrals multiplied by n\sqrt{n}, whose limits coincide. The figure shows the bell curve under 11+x2\frac{1}{1 + x^2}; the narrowed bell curve e−4x2e^{-4 x^2}; the region under (1−x2)4(1 - x^2)^4 inside the preceding one; the narrowed bell curve under 1(1+x2)4\frac{1}{(1 + x^2)^4}; and, in the variable u=n xu = \sqrt{n} \, x with n=10n = 10, the two bounds hugging the bell curve.

Proof

  1. I=∫0∞e−x2 dx≤π2,∫−∞0e−x2 dx=I→∫−∞∞e−x2 dx=2I\dato{I}{I = \int_0^{\infty} e^{-x^2} \, \mathrm{d}x \leq \frac{\pi}{2}}, \qquad \int_{-\infty}^{0} e^{-x^2} \, \mathrm{d}x = I \rightarrow \resaltar{\int_{-\infty}^{\infty} e^{-x^2} \, \mathrm{d}x = 2I}

    The function e−x2e^{-x^2} is continuous and positive on R\mathbb{R}. By the proposition on the antiderivatives of the exponentials and of the trigonometric functions, from the lesson on antiderivatives and the indefinite integral, arctan⁡x\arctan x is an antiderivative of 11+x2\frac{1}{1 + x^2}, and by Barrow’s rule for continuous functions, ∫0bdx1+x2=arctan⁡b\int_0^b \frac{\mathrm{d}x}{1 + x^2} = \arctan b, which tends to π2\frac{\pi}{2} by the corollary on monotonic functions at infinity, from the lesson on the limit at infinity. By the lemma on bounds for the bell curve and the comparison test, I=∫0∞e−x2 dxI = \int_0^{\infty} e^{-x^2} \, \mathrm{d}x converges. The reflection lemma, with b=0b = 0 and f(−x)=f(x)f(-x) = f(x), gives the left half, and the definition of the integral on an open interval, with the splitting point 00, the total.

  2. ∫0∞n e−nx2 dx=I→∫0∞e−nx2 dx=In\int_0^{\infty} \sqrt{n} \, e^{-n x^2} \, \mathrm{d}x = I \rightarrow \dato{esc}{\int_0^{\infty} e^{-n x^2} \, \mathrm{d}x = \frac{I}{\sqrt{n}}}

    Let nn be a natural number. The proposition on change of variable in an improper integral, from the lesson on conditional convergence, with f(u)=e−u2f(u) = e^{-u^2} on [0,∞)\ico{0}{\infty}, whose integral is II, and φ(x)=n x\varphi(x) = \sqrt{n} \, x on [0,∞)\ico{0}{\infty}, which has continuous derivative n\sqrt{n}, values in [0,∞)\ico{0}{\infty}, φ(0)=0\varphi(0) = 0 and limit ∞\infty as x→∞x \to \infty, gives the first equality, because (n x)2=nx2\left(\sqrt{n} \, x\right)^2 = n x^2. Linearity of improper integrals divides by n\sqrt{n}.

  3. W2n+1=∫01(1−x2)n dx≤∫01e−nx2 dx≤InW_{2n + 1} = \int_0^1 (1 - x^2)^n \, \mathrm{d}x \leq \int_0^1 e^{-n x^2} \, \mathrm{d}x \leq \resaltar{\frac{I}{\sqrt{n}}}

    For xx in [0,1]\icc{0}{1}, the lemma on the bounds gives 0≤1−x2≤e−x20 \leq 1 - x^2 \leq e^{-x^2}, and multiplying nn inequalities between nonnegative numbers, (1−x2)n≤e−nx2(1 - x^2)^n \leq e^{-n x^2}. By the theorem on monotonicity of the integral, from the lesson on properties of the definite integral, and the solved problem “A Wallis integral in disguise”, from the lesson on techniques for definite integrals, which computed the first integral, we obtain the first inequality; the second, because by the theorem on integrals of nonnegative functions the improper integral is the supremum of the integrals over [0,b]\icc{0}{b}.

  4. In=∫0∞e−nx2 dx≤∫0∞dx(1+x2)n=∫0π2cos⁡2n−2t dt=W2n−2\frac{I}{\sqrt{n}} = \int_0^{\infty} e^{-n x^2} \, \mathrm{d}x \leq \int_0^{\infty} \frac{\mathrm{d}x}{(1 + x^2)^n} = \int_0^{\frac{\pi}{2}} \cos^{2n - 2} t \, \mathrm{d}t = \resaltar{W_{2n - 2}}

    For x≥0x \geq 0, in the same way, e−nx2≤1(1+x2)ne^{-n x^2} \leq \frac{1}{(1 + x^2)^n}. The integral on the right is computed with the same proposition, with f(t)=cos⁡2n−2tf(t) = \cos^{2n - 2} t on [0,π2)\ico{0}{\frac{\pi}{2}}, continuous on [0,π2]\icc{0}{\frac{\pi}{2}}, whose improper integral is the definite one by the proposition on consistency, and φ(x)=arctan⁡x\varphi(x) = \arctan x on [0,∞)\ico{0}{\infty}, whose continuous derivative is 11+x2\frac{1}{1 + x^2}, by the proposition on the derivatives of the inverse trigonometric functions, from the lesson on the derivative of the inverse function, with values in [0,π2)\ico{0}{\frac{\pi}{2}}, arctan⁡0=0\arctan 0 = 0 and limit π2\frac{\pi}{2}. With t=arctan⁡xt = \arctan x, we have tan⁡t=x\tan t = x and cos⁡t>0\cos t > 0, and dividing the Pythagorean identity by cos⁡2t\cos^2 t, cos⁡2t=11+x2\cos^2 t = \frac{1}{1 + x^2}: the new integrand is 1(1+x2)n−1⋅11+x2\frac{1}{(1 + x^2)^{n - 1}} \cdot \frac{1}{1 + x^2}. The proposition on reflection about the midpoint, from the lesson on techniques for definite integrals, and the equality cos⁡(π2−t)=sin⁡t\cos\left(\frac{\pi}{2} - t\right) = \sin t carry the integral of the cosine to W2n−2W_{2n - 2}, and monotonicity of improper integrals gives the bound.

  5. n W2n−2=Wm2mπ⋅πn2m→π2→π2≤I≤π2→∫−∞∞e−x2 dx=2I=π\sqrt{n} \, W_{2n - 2} = W_m \sqrt{\frac{2m}{\pi}} \cdot \sqrt{\frac{\pi n}{2m}} \to \frac{\sqrt{\pi}}{2} \rightarrow \frac{\sqrt{\pi}}{2} \leq I \leq \frac{\sqrt{\pi}}{2} \rightarrow \resaltar{\int_{-\infty}^{\infty} e^{-x^2} \, \mathrm{d}x = 2I = \sqrt{\pi}}

    Multiplying by n\sqrt{n}, n W2n+1≤I≤n W2n−2\sqrt{n} \, W_{2n + 1} \leq I \leq \sqrt{n} \, W_{2n - 2} for every natural number nn. The solved problem “A Wallis integral in disguise” proved that the left-hand side tends to π2\frac{\sqrt{\pi}}{2}. For n≥2n \geq 2, with m=2n−2m = 2n - 2, the corollary on the order of magnitude of the Wallis integrals, from the lesson on techniques for definite integrals, and the theorem on the subsequences of a sequence with a limit, from the lesson on subsequences, give Wm2mπ→1W_m \sqrt{\frac{2m}{\pi}} \to 1; and πn2m=π4−4n\frac{\pi n}{2m} = \frac{\pi}{4 - \frac{4}{n}} tends to π4\frac{\pi}{4}, and its square root to π2\frac{\sqrt{\pi}}{2}, by the theorem stating that the limit theorems hold for sequences, from the lesson on sequences and their limit, with its clauses on algebra and on roots. By preservation of inequalities, from the same theorem, the constant II lies between the two limits.

In the variable u=n xu = \sqrt{n} \, x, the inequalities of the proof are (1−u2n)n≤e−u2≤(1+u2n)−n\left(1 - \frac{u^2}{n}\right)^n \leq e^{-u^2} \leq \left(1 + \frac{u^2}{n}\right)^{-n}, the first for 0≤u≤n0 \leq u \leq \sqrt{n} and the second for every u≥0u \geq 0, and as nn grows the two bounds hug the bell curve, as the last frame of the figure shows. The best-known proof squares the integral, writes it as a double integral over the plane and computes it in polar coordinates; it belongs to Calculus III, and nothing in this lesson depends on it. The value obtained can also be read on the scale of e−ax2e^{-a x^2}: for a>0a > 0, the same change of variable, with a\sqrt{a} in place of n\sqrt{n}, gives ∫−∞∞e−ax2 dx=πa\int_{-\infty}^{\infty} e^{-a x^2} \, \mathrm{d}x = \sqrt{\frac{\pi}{a}}.