 # Is algebra of random variables commutative?

Hi !
I have a bizarre output from the following script:

import openturns as ot
u = ot.Uniform(0.0, 1.0)
n = ot.Normal(0.0, 1.0)
z1 = u * n
z1.setDescription(["u * n"])
graph = z1.drawPDF()
z2 = n * u
z2.setDescription(["n * u"])
graph.add(z2.drawPDF())
graph.setColors(["dodgerblue3", "darkorange1"])
graph.setXTitle("X")


The script draws the PDF of the random variables:

Z_1 = U \times N

and

Z_2 = N \times U

where U \sim \mathcal{U}(0, 1) and N \sim \mathcal{N}(0,1).
This produces:

This is surprising, because both PDFs should match (the variables are independent).
The PDF writes:

f_{Z_1}(z) = \int^{1}_{0} f_U \left( x \right) f_N \left( z/x \right) \frac{1}{|x|}\, dx,

and

f_{Z_2}(z) = \int^{\infty}_{-\infty} f_N \left( x \right) f_U \left( z/x \right) \frac{1}{|x|}\, dx.

I guess that there might be an integration issue at 0, but I am not sure if this singularity can be integrated.
In general, should the operators +, -, *, / commute mathematically and numerically?
Regards,
Michaël

Hi Michaël,

The algebra is supposed to be commutative, which is the case despite the strange graph! The density function is defined in a unique way up to a set of probability zero. Depending of the order of the factors in the multiplication, you can get different results at x==0. It has no impact on the CDF, the sampling and the moments of the distribution. If your drawing grid does not contains 0 the two curves are identical:

import openturns as ot
u = ot.Uniform(0.0, 1.0)
n = ot.Normal(0.0, 1.0)
z1 = u * n
z1.setDescription(["u * n"])
graph = z1.drawPDF(200)
z2 = n * u
z2.setDescription(["n * u"])
graph.add(z2.drawPDF(200))
graph.setColors(["dodgerblue3", "darkorange1"])
graph.setXTitle("X") 1 Like

Great, thanks!

Your welcome ;-). just to make things clear: when I say that the algebra is commutative, I mean + and *, not - and / of course!