skip to content
Aymen Hafeez

The volume of an n-ball and the gamma function

/ 6 min read

Grant Sanderson recently gave an amazing talk about the volumes of higher dimensional spheres in which here mentioned that a similar results to that which he showed in the talk can be derived using the gamma function. Since we’ve already looked at the gamma function, it’s relation the zeta function, and its relation to the prime numbers, what if we could by extension relate the volume of a unit nn-ball to the prime numbers? In this post we’ll first concentrate on seeing how the volume of a unit nn-ball relates to the gamma function, and we’ll take this further in future posts.

A unit nn-ball is defined as the set of all points in nn-dimensions whose distance from the origin is 1.

We know that a line segment of radius 11 has length 22 (think of this as a 11-D sphere), a disk (i.e. a circle) of radius 11 has an area of π\pi, and a sphere of radius 11 has a volume of 43π\frac{4}{3}\pi. So the volume of a unit ball in nn dimensions is obviously

Vn=πn/2Γ(n2+1) V_n = \frac{\pi^{n/2}}{\Gamma \left(\frac{n}{2} + 1 \right)}

right? But in all seriousness, getting to this expression is actually surprisingly intuitive once we know the starting point, which is looking at the famous Gaussian integral:

ex2dx=π \int_{-\infty}^{\infty} e^{-x^2} \text{d} x = \sqrt{\pi}

Moving up to nn dimensions we can define:

x2=x12+x22++xn2 |x^2| = x_1^2 + x_2^2 + \cdots + x^2_n

We then consider the integral the integral over nn dimensional space:

Rnex2dV \int_{\mathbb{R}^n} e^{-|x^2|} \text{d} V

Since

ex2=e(x12+x22++xn2)=ex12ex22exn2 e^{-|x^2|} = e^{-(x^2_1 + x^2_2 + \cdots + x^2_n)} = e^{-x^2_1}e^{-x^2_2} \cdots e^{-x^2_n}

the integral splits into a product of one-variable functions. This means the whole nn-dimensional integral factors is

Rnex2dV=(ex2dx)n \int_{\mathbb{R}^n} e^{-|x^2|} \text{d} V = \left( \int_{-\infty}^{\infty} e^{-x^2} \text{d} x \right)^n

Then using Gaussian result in 11D we get:

Rnex2dV=(π)n=πn/2 \int_{\mathbb{R}^n} e^{-|x^2|} \text{d} V = (\sqrt{\pi})^n = \pi^{n/2}

The next step is the consider this same integral but integrating with respect to the distance from the origin rather than xx. We, therefore, convert the integral from the cartesian coordinates, (x1,x2,,xn)(x_1, x_2, \cdots, x_n), to polar coordinates, (r,θ)(r, \theta). In polar coordinates the function ex2e|^{-x^2}| depends on the distance r=xr = |x|, not direction, so points at the same distance from the origin all contribute the same value.

In 33D the volume of a thin shell of radius rr and thickness dr\text{d}r is approximated as

surface area of a sphere of radius r×dr \text{surface area of a sphere of radius } r \times \text{d}r

This can be extended to nn dimensions. If Sn1S_{n-1} is the surface are of the unit sphere in nn dimensions, then the surface area of a sphere with radius rr is

dVn=Sn1rn1 \text{d}V_n = S_{n-1}r^{n-1}

So a thin shell of radius rr and thickness dr\text{d}r has volume

Sn1rn1dr S_{n-1}r^{n-1}\text{d}r

Applying this the volume integral we defined above:

Rnex2dV=0er2Sn1rn1dr=Sn10er2rn1dr \int_{\mathbb{R}^n} e^{-|x^2|} \text{d} V = \int_{0}^{\infty} e^{-r^2}S_{n-1}r^{n-1} \text{d} r = S_{n-1} \int_{0}^{\infty} e^{-r^2}r^{n-1} \text{d} r

Recall that the Gamma function is defined as

Γ(s)=ots1etdt         for s>0 \Gamma(s) = \int_{o}^{\infty} t^{s-1}e^{-t} \text{d}t \ \ \ \ \ \ \ \ \ \text{for } s > 0

This isn’t far off the radial integral we showed above. If we make the substitution t=r2t = r^2, then

dtdr=2r          dr=dt2rr=t1/2,     rn1=(t1/2)n1=t(n1)/2 \frac{\text{d}t}{\text{d}r} = 2r \ \ \ \ \ \Rightarrow \ \ \ \ \ dr = \frac{\text{d}t}{2r} \\ r = t^{1/2}, \ \ \ \ \ r^{n-1} = (t^{1/2})^{n-1} = t^{(n-1)/2}

Substituting everything back into the integral we get

Sn10er2rn1dr=Sn10ett(n1)/2dt2t1/2 S_{n-1} \int_{0}^{\infty} e^{-r^2}r^{n-1} \text{d} r = S_{n-1} \int_{0}^{\infty} e^{-t}t^{(n-1)/2} \frac{\text{d}t}{2t^{1/2}}

We can simplify this by combining the powers of tt:

t(n1)/2t1/2=t(n2)/2=t(n/2)1 t^{(n-1)/2} \cdot t^{-1/2} = t^{(n-2)/2} = t^{(n/2) - 1}

With this the radial integral becomes

Sn10er2rn1dr=Sn120ett(n/2)1dt S_{n-1} \int_{0}^{\infty} e^{-r^2}r^{n-1} \text{d} r = \frac{S_{n-1}}{2} \int_{0}^{\infty} e^{-t} t^{(n/2) - 1} \text{d} t

which we can note is exactly the Gamma function for s=n2s = \frac{n}{2}:

Sn10er2rn1dr=Sn12Γ(n2) S_{n-1} \int_{0}^{\infty} e^{-r^2}r^{n-1} \text{d} r = \frac{S_{n-1}}{2}\Gamma \left(\frac{n}{2}\right)

Remember that we had the Gaussian integral in cartesian coordinates as

Rnex2dV=Sn10er2rn1dr=πn/2 \int_{\mathbb{R}^n} e^{-|x^2|} \text{d} V = S_{n-1} \int_{0}^{\infty} e^{-r^2}r^{n-1} \text{d} r = \pi^{n/2}

And from the spherical shell calculation we have

Rnex2dV=Sn12Γ(n2) \int_{\mathbb{R}^n} e^{-|x^2|} \text{d} V = \frac{S_{n-1}}{2} \Gamma \left(\frac{n}{2}\right)

And so, equating the two gives us

πn/2=Sn12Γ(n2) \pi^{n/2} = \frac{S_{n-1}}{2} \Gamma \left(\frac{n}{2}\right)

Rearranging for Sn1S_{n-1}:

Sn1=2πn/2Γ(n/2) S_{n-1} = \frac{2\pi^{n/2}}{\Gamma(n/2)}

which gives us an formula for the surface area of a unit sphere in nn dimensions. This itself is a very nice expression, but it can relatively simply be used to find an expression for volume.

Remember we said that for thin shell of radius rr and thickness dr\text{d}r has volume

dVn=Sn1rn1dr \text{d}V_n = S_{n-1}r^{n-1}\text{d}r

So for a unit ball, we can integrate both sides from 00 to 11 to get the volume:

Vn=Sn101rn1dr=Sn1nV_n = S_{n-1} \int_{0}^{1} r^{n-1} \text{d} r = \frac{S_{n-1}}{n}

Substituting in the expression we had for Sn1S_{n-1}:

Vn=1n2πn/2Γ(n/2) V_n = \frac{1}{n} \cdot \frac{2\pi^{n/2}}{\Gamma(n/2)}

Recall the identity for the Gamma function:

Γ(z+1)=zΓ(z) \Gamma(z + 1) = z\Gamma(z)

Since we have Γ(n/2)\Gamma(n/2), z=n2z = \frac{n}{2}, and so,

Γ(n2+1)=n2Γ(n2) \Gamma\left(\frac{n}{2} + 1\right) = \frac{n}{2} \Gamma \left(\frac{n}{2}\right) \\

Notice that in out volume expression we a factor of 2nΓ(n/2)\frac{2}{n\Gamma(n/2)}. Taking the reciprocal of both sides of the above formula:

1Γ(n/2+1)=2nΓ(n/2) \frac{1}{\Gamma(n/2 + 1)} = \frac{2}{n\Gamma(n/2)}

And so, substituting this back into the volume expression we get:

Vn=πn/2Γ(n2+1) \boxed {V_n = \frac{\pi^{n/2}}{\Gamma \left( \frac{n}{2} + 1 \right)}}

which is the general formula for a unit nn-ball. One of the definitions of the Gamma function is

Γ(z)=(z1)! \Gamma (z) = (z-1)!

And so, the volume formula can also be written as

Vn=πn/2(n/2)! V_n = \frac{\pi^{n/2}}{(n/2)!}

which is pretty amazing. Just to confirm that this formula works, consider an nn--ball in 11, 22 and 33, dimensions (i.e. a line segment, a circle and a sphere with radius 11). In 1D:

V1=π1/2Γ(3/2)Γ(3/2)=12Γ(12)=12πV1=ππ/2 V_1 = \frac{\pi^{1/2}}{\Gamma(3/2)} \\ \Gamma(3/2) = \frac{1}{2}\Gamma\left(\frac{1}{2}\right) = \frac{1}{2}\sqrt{\pi} \\ \Rightarrow V_1 = \frac{\sqrt{\pi}}{\sqrt{\pi} / 2}

In 2D:

V2=πΓ(2) V_2 = \frac{\pi}{\Gamma(2)}

Since Γ(2)=(21)!=1\Gamma(2) = (2 - 1)! = 1:

V2=π V_2 = \pi

In 3D:

V3=π3/2Γ(5/2) V_3 = \frac{\pi^{3/2}}{\Gamma(5/2)}

Using the same pattern for Γ(3/2)\Gamma(3/2):

Γ(5/2)=32Γ(3/2)=3212π=34πV3=π3/23π/4=4π3 \Gamma(5/2) = \frac{3}{2}\Gamma(3/2) = \frac{3}{2} \cdot \frac{1}{2}\sqrt{\pi} = \frac{3}{4}\sqrt{\pi} \\ \Rightarrow V_3 = \frac{\pi^{3/2}}{3\sqrt{\pi}/4} = \frac{4\pi}{3}

Now if we also consider a 44 dimensional nn-ball:

V4=π2Γ(3)=π22!=π22 V_4 = \frac{\pi^2}{\Gamma(3)} = \frac{\pi^2}{2!} = \frac{\pi^2}{2}

Recall that the value of ζ(s)=π26\zeta(s) = \frac{\pi^2}{6}. And so we have:

V4=3ζ(2) V_4 = 3\zeta(2)

A wild zeta function appears. In a future post we’ll look more closely at how the Riemann zeta function relates to the the volume of an nn-ball, and by extension the prime numbers.