# Let $X_1$ and $X_2$ be uniform on $n$-spheres. What is the distribution of $\| X_1+X_2\|$?

Suppose we have two independent random variables $$X_1$$ and $$X_2$$ distribution on $$n-1$$-sphere of radius $$r_1$$ and radius $$r_2$$, respectivly. Assume $$r_1>r_2$$.

Recall, that the $$n-1$$-sphere of radius $$r$$ is defined as \begin{align} S_{n-1}= \{ x \in \mathbb{R}^n : \|x\|=r \}. \end{align}

We have to find the distribution of \begin{align} U=X_1+X_2 \end{align}

We can see that $$U$$ will be distributed on an annulus \begin{align} A=\{ x: r_1-r_2 \le \| x\|\le r_1+r_2 \} \end{align}

It is not difficult to see that $$U$$ has a uniform spherical angle.
Therefore, the question is what is the distribution of the magnitude of $$U$$ that is $$\| U\|$$?

This question is an extension of the question previously asked here .

For the bounty: I would like to see the exact expression for the distribution of $$U$$.

Given $$U=X_1+X_2$$ in $$\mathbb{R}^n$$ where $$X_i$$ are random points on the $$n-1$$-spheres $$||X_i||=r_i$$, and $$R=||U||$$, we have $$R^2 = U^2 = X_1^2 + X_2^2 + 2X_1\cdot X_2 = r_1^2 + r_2^2 + 2r_1r_2\cos\Theta$$ where $$\Theta\in[0,\pi]$$ is the angle between $$X_1$$ and $$X_2$$. So, $$\Theta$$ is a random variable corresponding to the angle between two random points on the $$n-1$$-sphere.

Let's start tackling $$\Theta$$ and $$\cos\Theta$$ directly. Note first that these do not depend on the lengths $$||X_i||=r_i$$. Also, if we pick $$X_1$$ first, we can either rotate or choose a coordinate system so $$X_1=[1,0,\ldots,0]$$: ie, $$X_1$$ points along the first axis (aka $$x$$-axis in low dimensions). This is true because $$X_2$$ is uniformly distributed and independent of $$X_1$$. So, basically, the distribution of $$\Theta$$ (or $$\cos\Theta$$) is the same as the angle between a random point on the unit $$n-1$$-sphere and $$[1,0,\ldots,0]$$.

Now, let $$Z = [Z_1,\ldots,Z_n]$$ be a random point on the unit $$n-1$$-sphere: ie, so that $$Z_1^2+\cdots+Z_n^2=1$$. Then, $$\cos\Theta=Z\cdot[1,0,\ldots,0]=Z_1$$. So what we are after is the distribution of $$Z_1$$ for random points $$Z$$ on the unit $$n-1$$-sphere.

We can express the $$n-1$$-dimensional area of the unit $$n-1$$-sphere as $$\omega_{n-1} = \int_0^\pi \omega_{n-2}(\sin\theta)^{n-2}\,d\theta$$ where $$\omega_{n-2}(\sin\theta)^{n-2}$$ is the $$n-2$$-area of an $$n-2$$-sphere with radius $$\sin\theta$$. Since we are after a uniform probability distribution, we need to divide this by $$\omega_{n-1}$$.

Next, we wish to express this in terms of the coordinate $$z_1=\cos\theta$$, which, using $$d\theta/dz_1=-\sin\theta$$ and $$\sin\theta=\sqrt{1-z_1^2}$$, gives us \begin{align} \int_0^\pi \frac{\omega_{n-2}}{\omega_{n-1}} (\sin\theta)^{n-2}\, d\theta &=\int_{-1}^1 \frac{\omega_{n-2}}{\omega_{n-1}} (\sin\theta)^{n-2}\, \left|\frac{d\theta}{dz_1}\right|\,dz_1 \\ &=\int_{-1}^1 \frac{\omega_{n-2}}{\omega_{n-1}} (1-z_1^2)^{\frac{n-3}{2}}\, dz_1. \end{align} Replace the boundary $$[-1,1]$$ for $$z_1$$ with any other interval, and you get the probability of $$Z_1=\cos\Theta$$ within that interval; so the probability density of $$Z_1=\cos\Theta$$ is $$f_{\cos\Theta}(z) = \frac{\omega_{n-2}}{\omega_{n-1}} (1-z^2)^{\frac{n-3}{2}}.$$ This is basically just stating that for random variables $$Y=h(X)$$, the probability densities are related by $$f_X(x)=f_Y(y)\cdot\left|h'(x)\right|$$.

Returning to $$R$$, we already know $$R^2$$ is linear in $$\cos\Theta$$ with values in $$[(r_1-r_2)^2, (r_1+r_2)^2]$$. Entering the distribution of $$\cos\Theta$$, this gives the density of $$S=R^2$$: $$f_{R^2}(s) = \frac{\omega_{n-2}}{2r_1r_2\omega_{n-1}} \left[ 1 - \left(\frac{s-r_1^2-r_2^2}{2r_1r_2}\right)^2 \right]^{\frac{n-3}{2}}.$$ Now, $$f_R(r) = 2rf_{R^2}(r^2)$$ (same rule as above for change of variables) which yields $$f_{R}(r) = \frac{r\omega_{n-2}}{r_1r_2\omega_{n-1}} \left[ 1 - \left(\frac{r^2-r_1^2-r_2^2}{2r_1r_2}\right)^2 \right]^{\frac{n-3}{2}}.$$

Note that for points uniformly distributed between two radii, you should have density $$f_R(r)=ar^{n-1}$$ for some constant $$a$$ as the $$n-1$$-areas of the $$n-1$$-spheres of radius $$r$$ is $$\omega_{n-1}r^{n-1}$$. So for no $$n$$ is that the case.

This gives the distribution $$F_R(r)$$ of the distance from the origin. The probability density of the $$n$$-dimensional vector $$U$$ is found by dividing by the $$n-1$$-area $$\omega_{n-1}r^{n-1}$$ of the $$n-1$$-sphere of radius $$r=||u||$$: $$f_{U}(u) = \frac{F_R(||u||)}{\omega_{n-1} ||u||^{n-1}} = \frac{\omega_{n-2}}{||u||^{n-2}r_1r_2\omega^2_{n-1}} \left[ 1 - \left(\frac{||u||^2-r_1^2-r_2^2}{2r_1r_2}\right)^2 \right]^{\frac{n-3}{2}}.$$

As for the $$k$$-area of the unit $$k$$-sphere, $$\omega_k = \frac{2\pi^{\frac{n+1}{2}}}{\Gamma\left(\frac{n+1}{2}\right)},$$ as may be found on Wikipedia, where the gamma-function satisfies $$\Gamma(s+1)=s\Gamma(s)$$, and $$\Gamma(n+1)=n!$$ for integers.

As a side-note, the $$1-z^2$$ term inside the brackets may be rewritten $$1 - \left(\frac{r^2-r_1^2-r_2^2}{2r_1r_2}\right)^2 = \frac{[r^2-(r_1-r_2)^2]\cdot[(r_1+r_2)^2-r^2]}{(2r_1r_2)^2}$$ which helps highlight that $$r^2$$ lies between $$(r_1-r_2)^2$$ and $$(r_1+r_2)^2$$.

• Thanks a lot. I will go over it later today. I hope you don't mind if I send you questions. – Lisa Apr 30 at 21:21
• Feel free to ask. Chances are I may have made some mistake, so if something doesn't seem to make sense, maybe it doesn't. – Einar Rødland Apr 30 at 21:55
• @Lisa: I redid the derivation, arriving at the same answer, so maybe it's all right. – Einar Rødland May 1 at 14:27
• Thanks for the update. Here is Q1: Can I ask you about the angle between two vectors? How do you exactly define it in the multi-dimensional case? Is it better to call it just an inner product term? – Lisa May 1 at 14:32
• @Lisa: The angle between two vectors in the multi-dimensional case could probably be defined in a number of equivalent ways. You can reduce it to the angle within the plane spanned by the two vectors; or you could define it in terms of the inner product; or you could define it as the distance on the unit sphere. The only difference between two vs more dimensions is that in two dimensions you can define either negative angles or angles from $0$ to $2\pi$. I guess I could also have avoided using angles and worked directly on the $Z=\cos\Theta$ term from the start. – Einar Rødland May 1 at 14:40

It is known that the uniform distribution on the unit $$(n-1)$$-sphere can be represented as a standard multivariate Gaussian divided by its norm. Therefore, \begin{align*} X_1 \overset{\mathcal{D}}{=} r_1\frac{Z_1}{\|Z_1\|} \qquad \text{and} \qquad X_2 \overset{\mathcal{D}}{=} r_2\frac{Z_2}{\|Z_2\|} \end{align*} where $$Z_1, Z_2 \overset{\text{iid}}{\sim} N(\mathbf{0}_n, I_{n\times n})$$. Hence, \begin{align*} \|U\| \overset{\mathcal{D}}{=} \left\|r_1\frac{Z_1}{\|Z_1\|} + r_2\frac{Z_2}{\|Z_2\|}\right\| = \sqrt{r_1^2 + r_2^2 + 2r_1r_2 \frac{Z_1^\intercal Z_2}{\|Z_1\|\|Z_2\|}} \end{align*} The next step is to find the distribution of $$P \overset{\text{def}}{=} \frac{Z_1^\intercal Z_2}{\|Z_1\|\|Z_2\|}$$, which takes the form of Pearson's correlation coefficient, except we are not subtracting out the sample mean in the variance/covariance calculation. You can actually show that

\begin{align*} T \overset{\text{def}}{=} \frac{P}{\sqrt{1-P^2}} \sim t_{n-1}/\sqrt{n-1} \end{align*} where $$t_n$$ is the t-distribution with $$n$$ degrees of freedom. This follows from the proof in Hotelling's "New Light on the Correlation Coefficient and its Transforms" (1953), changed from $$n-2$$ to $$n-1$$ because of not needing to estimate the mean.

• Thank you. Do you think we can find a closed form expression for the distribution of $P$. – Lisa Apr 24 at 18:22
• Does $T$ have $n$ degrees of freedom or $n-1$? – Lisa May 1 at 23:21
• Hi @Lisa, I think I made a mistake in my post; the distribution should be $t_{n-1}/\sqrt{n-1}$ instead of $t_n/\sqrt{n}$. With this new information, Jason's derivation using my result now matches with Einar's. – Tom Chen May 2 at 4:38
• I edited my answer to reflect this change. – Jason Swanson May 2 at 11:55

Continuing on from Tom Chen's answer, let $$X\sim t_{n-1}$$ and $$f(x) = \frac x{(1-x^2)^{1/2}}.$$ Then $$f(P)=_d (n-1)^{-1/2}X$$, so that $$\|U\|=_d g(X)$$, where $$g(x) = \sqrt{r_1^2 + r_2^2 + 2r_1r_2 f^{-1}((n-1)^{-1/2}x)}\,.$$ Note that $$X$$ has density $$\varphi(x) = C_n\left({1 + \frac{t^2}{n-1}}\right)^{-n/2},$$ where $$C_n = \frac{\Gamma(n/2)}{\sqrt{(n-1)\pi}\,\Gamma((n-1)/2)}.$$ Thus, the density of $$\|U\|$$ is $$h(y) = \left({\frac d{dy}(g^{-1}(y))}\right)\varphi(g^{-1}(y)),$$ defined for $$r_1-r_2\le y\le r_1+r_2$$. If we let $$\gamma_y = \frac{y^2 - r_1^2 - r_2^2}{2r_1r_2},$$ then $$g^{-1}(y)=\sqrt{n-1}\,f(\gamma_y)$$, so that \begin{align} \frac d{dy}(g^{-1}(y)) &= \sqrt {n-1}\,f'(\gamma_y)\left({\frac y{r_1r_2}}\right)\\ &= \frac{\sqrt {n-1}}{r_1r_2}\frac y{(1 - \gamma_y^2)^{3/2}}. \end{align} Also, \begin{align} \varphi(g^{-1}(y)) &= C_n(1 + f^2(\gamma_y))^{-n/2}\\ &= C_n\left({\frac1{1 - \gamma_y^2}}\right)^{-n/2}\\ &= C_n(1 - \gamma_y^2)^{n/2}. \end{align} Thus, $$h(y) = \frac{\sqrt {n-1}\,C_n}{r_1r_2}\,y\,(1 - \gamma_y^2)^{(n-3)/2}.$$ Putting it all together, the density of $$\|U\|$$ is $$h(y) = \frac{\Gamma(n/2)}{r_1r_2\sqrt\pi\,\Gamma((n-1)/2)} \,y\,\left({1 - \left({ \frac{y^2 - r_1^2 - r_2^2}{2r_1r_2} }\right)^2}\right)^{(n-3)/2}$$ for $$r_1-r_2\le y\le r_1+r_2$$, and $$0$$ otherwise.

EDIT:

Regarding the comment, when $$n=3$$, since $$\Gamma(3/2)=\sqrt\pi\,/2$$ and $$\Gamma(1)=1$$, this reduces to $$h(y) = \frac1{2r_1r_2}y.$$ We then have \begin{align} \int_{r_1-r_2}^{r_1+r_2} h(y)\,dy &= \frac1{4r_1r_2}y^2 \bigg|_{r_1-r_2}^{r_1+r_2}\\ &= \frac1{4r_1r_2}((r_1+r_2)^2 - (r_1-r_2)^2)\\ &= \frac1{4r_1r_2}(4r_1r_2) = 1. \end{align}

• Can you check if it is correct? For $n=2$, I am getting that $\int_{r_1-r_2}^{r_1+r_2} h(y) dy =2$ – Lisa May 1 at 18:21
• @Lisa, I have edited the answer to include a verification of the $n=2$ case. It seems to work fine. – Jason Swanson May 1 at 18:56
• Sorry. I made a mistake in a calculation. – Lisa May 1 at 22:48
• I can't tell does your answer agree with that of Einar? – Lisa May 1 at 22:49
• If you replace $n$ with $n+1$ in Einar's solution, it matches the one that I have derived from Tom Chen's solution. – Jason Swanson May 1 at 23:10