# Volume of a $l_2$ ball of radius $r$

What is the volume of a ball $$B \subset \mathbb{R}^n$$, where $$B = \{ \theta : ||\theta||_2 \leq r\}$$ where $$|| \cdot ||_2$$ is the $$l_2$$-norm?

The $$l_2$$-norm is given by $$||x||_2 := \left( \sum_{i=1}^d |x_i|^2 \right)^{1/2}$$.

The volume of an $$l_2$$ ball in $$\mathbb{R}^n$$ is given by

$$V_n(R)={\pi^{n\over2}\over\Gamma\left({n\over2}+1\right)}R^n$$

We can actually derive this formula using some intuition and the properties of Beta function. Before jumping into $$\mathbb{R}^n$$ case, let's look at the cases for $$\mathbb{R}$$, $$\mathbb{R}^2$$, and $$\mathbb{R}^3$$. Since $$V_2(R)$$ gives us the area of a circle with radius of $$R$$, we know that

$$V_2(R)=\int_{-R}^R 2\sqrt{R^2-x^2}\mathrm{d}x=\pi R^2$$

$$V_3(R)=\int_{-R}^R \pi\left(\sqrt{R^2-x^2}\right)^2\mathrm{d}x={4\over3}\pi R^3$$

For consistency, we define $$V_1(R)=2R$$, and we can discover that we are always integrating $$V_{n-1}(R)$$ to obtain $$V_n(R)$$. As a result, we can find a one-dimensional recursive formula for $$V_n$$:

$$V_n(R)=\int_{-R}^RV_{n-1}\left(\sqrt{R^2-x^2}\right)\mathrm{d}x$$

We know that the volume of an $$n$$-ball with radius $$R$$ is always proportional to $$R^n$$, so we can transform the above identity into the following:

$$V_n(R)=V_{n-1}(1)\int_{-R}^R(R^2-x^2)^{n-1\over 2}\mathrm{d}x$$

Now, it is time to introduce substitution: $$x=uR$$, $$\mathrm{d}x=R\mathrm{d}u$$.

\begin{aligned} V_n(R)&=V_{n-1}(1)\int_{-1}^1(R^2-u^2R^2)^{n-1\over2}R\mathrm{d}u \\ &=V_{n-1}(1)R^n\int_{-1}^1(1-u^2)^{n-1\over2}\mathrm{d}u \\ &=2V_{n-1}(1)R^n\int_0^1(1-u^2)^{n-1\over2}\mathrm{d}u \end{aligned}

In order to utilize Beta function, we perform another substitution where $$t=u^2\Rightarrow u=\sqrt{t}$$ and $$\mathrm{d}u={t^{-1/2}\over2}\mathrm{d}t$$.

\begin{aligned} V_n(R)&=2V_{n-1}(1)\int_0^1{t^{-1/2}\over2}(1-t)^{n-1\over2}\mathrm{d}t \\ &=V_{n-1}(1)\int_0^1t^{{1\over2}-1}(1-t)^{{n+1\over2}-1}\mathrm{d}t \end{aligned}

Now, we introduce Beta function $$B(x,y)=\int_0^1t^{x-1}(1-t)^{y-1}\mathrm{d}t$$.

$$V_n(R)=R^nV_{n-1}(1)R^nB\left({1\over2},{n+1\over2}\right)$$

If we define the "volume coefficient" $$M_k\equiv V_k(1)$$, we obtain the following relation for $$M_n$$ and $$M_{n-1}$$ by setting $$R=1$$ in the above equation:

$$M_n=B\left({1\over2},{n+1\over2}\right)M_{n-1}$$

Using another definition for beta function $$B(x,y)={\Gamma(x)\Gamma(y)\over\Gamma(x+y)}$$, we can express $$M_n$$ in terms of Gamma functions:

$$M_n={\Gamma(1/2)\Gamma\left({n-1\over2}+1\right)\over\Gamma\left({n\over2}+1\right)}M_{n-1}$$

It can be shown that $$\Gamma(1/2)=\sqrt\pi$$, so

$$M_n=\sqrt\pi\cdot{\Gamma\left({n-1\over2}+1\right)\over\Gamma\left({n\over2}+1\right)}M_{n-1}$$

Now, we can try to apply the recursive formula for multiple times and obtain a closed form for $$M_n$$ due to massive cancellation.

\begin{aligned} M_n &=\sqrt\pi\cdot{\Gamma\left({n-1\over2}+1\right)\over\Gamma\left({n\over2}+1\right)}\cdot\sqrt\pi\cdot{\Gamma\left({n-2\over2}+1\right)\over\Gamma\left({n-1\over2}+1\right)}\cdot\sqrt\pi\cdot{\Gamma\left({n-3\over2}+1\right)\over\Gamma\left({n-2\over2}+1\right)}\cdots \sqrt\pi\cdot{\Gamma\left({3-2\over2}+1\right)\over\Gamma\left({3-1\over2}+1\right)}M_2 \\ &={\pi^{n-2\over2}M_2\over\Gamma\left({n\over2}+1\right)} \end{aligned}

Given $$M_2=V_2(1)=\pi$$, we obtain

$$M_n={\pi^{n/2}\over\Gamma\left({n\over2}+1\right)}$$

Using the definition $$V_n(R)=V_n(1)R^n=M_nR^n$$, we can get the volume formula of a ball in $$\mathbb{R}^n$$ with $$l_2$$ metric:

$$V_n(R)={\pi^{n\over2}\over\Gamma\left({n\over2}+1\right)}R^n$$