# A simple transformation (confusion) from standard uniform distribution to Triangular distribution

I am trying to do (myself) the very basic uniform distribution to triangular distribution conversion. But I am not getting success. if $u,v$ are two standard uniform distributed random variable (R.V.) such that $u,v \in [0,1]$, then $w = |u-v|$ is the R.V. I have to find pdf for $w$ which is of course $f_W(w) = 2(1-w)$. Now following is my solution

$f_U(u) = f_V(v) = 1$ are standard uniform R.V. with range $[0,1]$. Then

$$P[W<w] = P[|U-V| < w] = P[(U-V) < w] + P[(V-U) < w]$$ first, $$E_V[P[U < w + v]] = E_V[w+v] = w +\frac{1}{2}$$ where $E_V[]$ is expectation w.r.t R.V. $V$ and $E_V[.] = \frac{1}{2}$ for std. unifrom R.V $V \in [0,1]$

Similarly, $$E_U[P[V < w + u]] = E_V[w+u] = w +\frac{1}{2}$$

So $$P[W < w] = w +\frac{1}{2} + w +\frac{1}{2} = 2w + 1$$ Now, if I differentiate w.r.t $w$, then I will get

$$f_W(w) = 2$$

where am I going wrong?

I think you mean Uniform distribution, not Normal. The first mistake is in the first line, which should be

$$P[W<w] = P[|U-V| < w] = P[\color{red}{-w<(U-V) < w}] .$$

[Obs: OP already edited the question to fix these issues.]

I'm not sure how to follow your logic, but here is an alternative. Notice that

$$f_U(x)=f_V(x)=\begin{cases}1&x\in[0,1]\\0&\text{otherwise}\end{cases},$$

and, letting $Z\equiv U-V$ we have

$$f_Z(z)=\int_{-\infty}^{\infty} f_U(z+v)f_V(v)dv=\int_{0}^{1} f_U(z+v)dv=\begin{cases}1-z &z\in[0,1]\\1+z&z\in[-1,0)\\0&\text{otherwise}\end{cases}.$$

Therefore,

$$P[-w<(U-V) < w] = \int_{-w}^w f_Z(z)dz= \begin{cases}w(2-w)&w\in[0,1]\\0&\text{otherwise}\end{cases},$$

and, finally, taking derivative with respect to $w$,

$$f_W(w)= \begin{cases}2(1-w)&w\in[0,1]\\0&\text{otherwise}\end{cases}.$$

• Thanks. Yes its unifrom distr. and the second objection is incorrect as I wrote $P[(U-V)] < -w$ which is essentially the same as $P[(V-U) <w]$. See the negative sign with $w$ – Kashan Aug 14 '18 at 21:44
• It is only the same if you flip the inequality sign also. – mzp Aug 14 '18 at 21:47
• ah. ok. it was silly mistake. thanks for notifying – Kashan Aug 14 '18 at 21:48
• Thanks. It might look silly, but I cannot understand the second step, after taking $Z=U-V$ :( – Kashan Aug 15 '18 at 4:15
• This is not silly at all, indeed it is the hard part of the answer, one I should have explained better. That equality comes from the fact that the density of the sum of two independent random variables is the convolution of the density of the two variables. This very well explained in the answer to this question. (The only difference is that I adapted the formula for the difference instead of the sum.) – mzp Aug 15 '18 at 21:51