Introduction

This post is an extension of my Medium article: The Math Behind “The Curse of Dimensionality”. If you have any questions or feedback, feel free to leave a comment below or reach out on LinkedIn.

Here, I derive the formula for the volume of the n-ball using integral calculus and Wallis integrals.

An n-ball is a generalization of the ordinary “ball” to arbitrary dimensions. It is defined as the set of points in the n-dimensional Euclidean space that are at a fixed distance from a central point (we will condider 0, the origin). The n-ball has important applications, particulary in machine learning and data analysis.

The equation of an n-ball is given by:

x12+x22++xN2r2

where r is the radius of the ball.

Derivation of the volume formula

One of the most important properties of the n-ball is its volume. The volume of an n-ball of radius r is given by:

VN(r)=π(N+1)/2Γ((N+1)/2)rN+1

where Γ is the gamma function. In the rest of this post, we will derive this formula.

We define the unit (radius equal to 1) n-ball as the following space: Bn={x1,,xm;i=1nxi21}

We note Vn=Vn(1) the volume of this ball. And more generally Vn(R) the volume of the n-ball with radius R. From now on, we will use Vn to refer to the volume of the unit n-ball:

Vn=xBndx1dx2dxn

First, note that the volume of the n-ball of radius R is RnVn: simply use the change of variable yixi/R in the expression of Vn(R).

Now, let’s simplify Vn:

Vn=x12++xn21dx1dx2dxn=x121(x22++xn21x12dx2dxn)dx1=x121Vn1(1x12)dx1

We can now replace the expression of the volume of the n1 ball of radius 1x12 with the previous relation:

Vn=x121Vn1(1x12)dx1=Vn1x121(1x12)n1dx1=Vn111(1x2)n1dx

We use the change of variable x=cos(θ) (so dx=sin(θ)dθ) to simplify the integral:

Vn=Vn111(1x2)n1dx=Vn1π0sinn1(θ)sin(θ)dθ=Vn10πsinn(θ)dθ=2Vn10π/2sinn(θ)dθ=InVn1

We note In=20π/2sinn(θ)dθ.

Note that 0π/2sinn(θ)dθ is a famous integral in mathematics: it is called the Wallis integral and often denoted by Wn. It can be derived using integration by parts (I will prove this formula in the appendix). Depending on the parity of n, the integral can be expressed as:

W2p=π2(2p)!22p(p!)2 and W2p+1=22p(p!)2(2p+1)!

Using our recursive relation, we know that: Vn=InIn1I2V1 and V1=V1(1)=2 (the length of the segment [1,1]).

We are going to make use of a very useful property:

I2pI2p+1=4W2pW2p+1=π2(2p)!22p(p!)222p(p!)2(2p+1)!=2π2p+1=πp+1/2

We will also need the Gamma function. All you need to know is these 2 expressions:

Γ(n)=(n1)!

and

Γ(n+1/2)=(n1/2)××1/2×π1/2

Now, we can easily compute the volume Vn by grouping successive terms, depending again on the parity of n.

If n=2p: V2p=I2pI2p1I2V1=I2p(I2p1I2p2)(I3I2)×2=π×(2p)!22p(p!)2×πp1/2×πp3/2××π3/2×π1/2=(2p)!2p(p!)2×πp(2p1)(2p3)(1)=πp2p×(2p)!(p!)2×(2p)(2p2)(4)(2)(2p!)=πp2p×(2p)!(p!)2×2pp!(2p)!=πpp!=πn/2Γ(n2+1)

If n=2p+1, it is a bit less complicated:

V2p+1=I2p+1I2pI2p1I2V1=(I2p+1I2p)(I2p1I2p2)(I3I2)×2=πp+1/2×πp1/2×πp3/2××π3/2×11/2=πp+12(p+1/2)(p1/2)(1/2)π12=πp+12Γ(p+12+1)=πn/2Γ(n2+1)

So we obtained a single formula for the volume of the n-ball, regardless of the parity of n:

Vn=Vn(1)=πn/2Γ(n2+1)

And by extension, the volume of the n-ball of radius R is:

Vn(R)=RnVn(1)=Rnπn/2Γ(n2+1)

Note that there is a very easy way to derive the area of the surface of n-ball using this expression. We simply need to derive the volume of the n-ball of radius R with respect to R and we obtain the surface area of the n-ball of radius R:

ddRVn(R)=nRn1Vn(1)=nRn1πn/2Γ(n2+1)

Paricularly, the surface area of the n-ball of radius 1 is:

Sn=nπn/2Γ(n2+1)=2πn/2Γ(n2)




Appendix: Derivation of the Wallis integrals

The Wallis integrals are defined as:

Wn=0π/2sinn(θ)dθ

We will derive a recursive formula using integration by parts.

Wn=0π/2sinn(θ)dθ=0π/2sinn2(θ)(1cos2(θ))dθ=Wn20π/2sinn2(θ)cos2(θ)dθ=Wn2([sinn1(θ)n1cos(θ)]0π/21n10π/2sinn1(θ)sin(x)dθ)=Wn21n1Wn

We conclude that:

Wn=n1nWn2

We can now distinguish 2 cases depending on the parity of n:

  • If n=2p, we have:
W2p=2p12pW2p2=2p12p2p32p212W0=2p12p2p32p212π2=π2(2p)!22p(p!)2

We obtained the last equality by multiplying the denominator and the numerator by 2p(2p2)2 to make (2p)! appear. We then factorized each term of the denominator by 2.

  • Similarly, if n=2p+1, we have:
W2p+1=2p2p+1W2p1=2p2p+12p22p123W1=2p2p+12p22p12321=22p(p!)2(2p+1)!

We conclude that

W2p=π2(2p)!22p(p!)2

and

W2p+1=22p(p!)2(2p+1)!