# Probability density function of a product of uniform random variables

Let $z = xy$ be a product of two uniform random variables, with $x$ having the range $[a, b)$ and $y$ the range $[c, d)$.

What is the probability density function of $z$, and how is it calculated?

There are different solutions depending on whether $a > 0$ or $a < 0$, $c > 0$ or $c < 0$ etc. If you can tie it down a bit more, I'd be happy to compute a special case for you.

In the case of: $a > 0$ and $c > 0$, there are three special sub-cases:

• Case 1: $a d > b c$

• Case 2: $a d < b c$

• Case 3: $a d = b c$

Here is the output for Case 1 using the mathStatica/Mathematica combo ...

# Case 1: $a > 0$, $c > 0$, $a d > b c$

Given $X \sim \text{Uniform}(a,b)$ with pdf $f(x)$, and $Y \sim \text{Uniform}(c,d)$ with pdf $g(y)$ and parameters $a>0$ and $c>0$, we have:

f = 1/(b-a);    domain[f] = {x, a, b} && {0 < a < b, a d > b c};
g = 1/(d-c);    domain[g] = {y, c, d} && {0 < c < d};


Find pdf of the product $Z = X * Y$, say $h(z)$:

h = TransformProduct[{f, g}, z]


with domain of support (just define it on the real line):

domain[h] = {z, -∞, ∞};


Here is a plot of the pdf for Case 1:

PlotDensity[h /. {a -> 2, b -> 4, c -> 1/2, d -> {6, 7, 8}}]


update ...

# Case 3: $a > 0$, $c > 0$, $a d == b c$

Case 3 is really just a special case of case 1 ...

Given $X \sim \text{Uniform}(a,b)$ with pdf $f(x)$, and $Y \sim \text{Uniform}(c,d)$ with pdf $g(y)$, and parameters $a>0$ and $c>0$, we have:

f = 1/(b-a);    domain[f] = {x, a, b} && {0 < a < b, a d == b c};
g = 1/(d-c);    domain[g] = {y, c, d} && {0 < c < d};


Find pdf of the product $Z = X * Y$, say $h(z)$:

h = TransformProduct[{f, g}, z]


with domain of support (just define it on the real line):

domain[h] = {z, -∞, ∞};


Here is a plot of the pdf for Case 3, for your set-up, with $a = c$, and $b = d$:

PlotDensity[h /. {a -> Range[5], b -> 12, c -> Range[5], d -> 12}]


... and you are all done :) I might update the mathStatica code to automatically output all the special cases ... for the next version :)

• In case 2, of course, we can simply make a change of variables and use case one, as they're symmetric. At the moment, I have two specific cases, both with a>0, c>0, one of which falls into case 1, but the other falls into case 3, as a=c, b=d. I'd also really like to have the probability density function Pz(a,b,c,d) if possible, as I don't have access to Mathematica, and there are a lot of different ranges of z that are significant for this problem, more than I could ask someone to solve for me. – Theodore Murdock Apr 29 '13 at 14:54
• @TheodoreMurdock Hi Theo - yes, case 2 by symmetry, and case 3 can be obtained as a special case of case 1 or 2. I've updated the above to include case 3 + plot. – wolfies Apr 29 '13 at 15:39
• Oh...sorry for being slow to get it, I just realized your function h is the probability density I need, taking different forms in different regions of the graph. Thanks for the help! Now I just need to plug in the numbers, integrate over the proper interval, and I'll be able to clear up the confusion I started a few years ago over how many dwarves are fat enough and tall enough to wield a two-handed sword in dwarf fortress. – Theodore Murdock Apr 29 '13 at 15:52
• In an example to a recent answer, I computed the density of the product of two uniform variables on $[0,1]$. I am pleased to see that my result is confirmed here. (+1) – robjohn Mar 28 '14 at 10:39

The general formula for the pdf of the product $Z=XY$ of two random variables $X$ and $Y$ is given by

$$p_{Z}(z)= \int_{-\infty}^{\infty}\frac{1}{|x|}p_{XY}\left (x,\frac{z}{x}\right )\;dx$$

where $p_{XY}(x,y)$ is the joint distribution of the two random variables. If they are independent you can use $p_{XY}(x,y)=p_X(x)p_Y(y)$.