The product of two uniform distributions

Recently someone asked me the following question, what is the distribution of the product of two uniform distributions? Not knowing the answer immediately we discussed this problem and concluded that this is not a trivial question. Below I show you my solution to this problem.

Numerical approach

We first want to have some intuition about what we expect to obtain. We do this by generating 10000 pairs of random uniform samples between 0 and 1. Then we multiply each of the pairs and plot the histogram of the results. We can do this with the following piece of python code.

import numpy as np
import matplotlib.pyplot as plt

rs = np.random.RandomState(37)

X = rs.rand(10000)
Y = rs.rand(10000)
Z = X*Y

hist = np.hstack(Z)
plt.hist(hist, bins = 'auto')
plt.show()

The results are quite surprising

It seems that the product of two uniform distributions are distributed on a logarithmic scale. Now the question is, can we find the explicit distribution function, and can we prove the correctness of the distribution function.

The distribution function of the product of two uniform distributions

Let $X$ and $Y$ be uniform distributions between $0$ and $1$. Define $Z = XY$. We write $f_X$ and $f_Y$ for the distributions $X$ and $Y$, respectively. Let $0 \leq T \leq 1$, then
$$
\begin{split}
P(Z < T) &= \int_0^1 P(xY < T) f_X(x) dx = \int_0^1 P(Y < T/x) f_X(x) dx
\end{split}
$$
If $x < T$, then $P(Y < T/x) = 1$, hence we split the integral
$$
\begin{split}
P(Z < T) &= \int_0^T f_X(x) dx + \int_T^1 P(Y < T/x) f_X(x) dx \\
&= \int_0^T f_X(x) dx + \int_T^1 \frac{T}{x} f_X(x) dx \\
&= \int_0^T 1 dx + \int_T^1 \frac{T}{x} dx \\
&= T – T \log(T).
\end{split}
$$
Hence
$$
f_Z(x) = \frac{d}{dx} (x – x\log(x)) = 1 – (1 + \log(x)) = -\log(x).
$$

The distribution function of the product of an arbitrary product of uniform distributions

We can do better. Let $X_1$, $X_2$, …, $X_n$ be uniform distributions. What is the distribution function for $Z_n = X_1 X_2 \ldots X_n$? We will show, in general, that
$$
f_{Z_n}(x) = \frac{(-1)^{n-1}}{(n-1)!} \log(x)^{n-1}, \quad 0 \leq x \leq 1.
$$
For $n = 2$ we already showed that $f_{Z_2}(x) = -\log(x)$. Assume that we can show this formula for all $k \leq n$. We show that the formula holds for $n+1$. By induction this proves that the formula holds for all $n$. We use the somewhat known identities, seeĀ https://en.wikipedia.org/wiki/List_of_integrals_of_logarithmic_functions,
$$
\begin{split}
\int \log(x)^n dx &= x \sum_{k=0}^n (-1)^{n-k} \frac{n!}{k!} (\log(x))^k, \\
\int \frac{\log(x)^n}{x} dx &= \frac{\log(x)^{n+1}}{n+1}.
\end{split}
$$
Using
$$
\begin{split}
P(Z_n < T) &= \int_0^1 P(x X_n < T) f_{Z_{n-1}}(x) dx \\
&= \int_0^1 P(X_n < T/x) f_{Z_{n-1}}(x) dx \\
&= \int_0^T f_{Z_{n-1}}(x) dx + \int_T^1 \frac{T}{x} f_{Z_{n-1}}(x) dx,
\end{split}
$$
where $Z_{n-1} = X_1 X_2 \ldots X_{n-1}$, we have
$$
\begin{split}
P(Z_{n+1} < T) &= \int_0^T f_{Z_{n}}(x) dx + \int_T^1 \frac{T}{x} f_{Z_{n}}(x) dx \\
&= \int_0^T \frac{(-1)^{n-1}}{(n-1)!} \log(x)^{n-1}dx
+ \int_T^1 \frac{T}{x} \frac{(-1)^{n-1}}{(n-1)!} \log(x)^{n-1}dx \\
&= \frac{(-1)^{n-1}}{(n-1)!} \left(
\int_0^T \log(x)^{n-1}dx + \int_T^1 \frac{T}{x} \log(x)^{n-1} dx
\right) \\
&= \frac{(-1)^{n-1}}{(n-1)!} \left(
T \sum_{k=0}^{n-1} (-1)^{n-k} \frac{n!}{k!} (\log(T))^k – \frac{T}{n} \log(T)^n
\right)
\end{split}
$$
The differential of $P(Z_{n+1} < T)$ is a telescope sum, i.e. using
\begin{equation*}
\frac{d}{dx} x\log(x)^k = k\log(x)^{k-1} + \log(x)^k,
\end{equation*}
we have
$$
\begin{split}
\frac{d}{dx} \left(
x \sum_{k = 0}^{n} (-1)^{n-k} \frac{n!}{k!} \log(x)^k
\right) &= \sum_{k = 0}^{n} (-1)^{n-k} \frac{n!}{k!} (k\log(x)^{k-1} + \log(x)^k) \\
&= \sum_{k = 0}^{n-1} (-1)^{n-k+1} \frac{n!}{k!} \log(x)^k
+ \sum_{k = 0}^{n} (-1)^{n-k} \frac{n!}{k!} \log(x)^k \\
&= \log(x)^{n}
\end{split}
$$
Therefore
$$
\begin{split}
f_{Z_{n+1}}(x) &= \frac{d}{dx} P(Z_{n+1} < x) \\
&= \frac{(-1)^{n-1}}{(n-1)!} \left(
\log(x)^{n-1}
– \log(x)^{n-1}
– \frac{1}{n} \log(x)^{n}
\right) = \frac{(-1)^n}{n!} \log(x)^n.
\end{split}
$$
Hence by induction we showed that $f_{Z_n}(x)$ holds for all $n$.

Leave a Reply

Your email address will not be published. Required fields are marked *