Integrating an absolute difference transformation I have a dependent variable which is $$ W = |X - Y| $$ X and Y are independently distributed where $ X \sim Uniform(0,1)$ and $ Y \sim Uniform(0,2)$
What am I supposed to do is find the probability of $W \le 0.5 $
I have split the function to two case one being $ X > Y$ and the other $ Y > X $ so I can define two functions for Y one is being $ Y = W + X$ for $Y > X$ and the other being $ Y = X - W$  for $ X > Y$. And then I tried to write down the integrals.
Trial 1:
$$\int_0^{0.5} \int_x^{x+w} \int_0^y dx\frac{dy}{2}dw$$ for $Y > X$ and
$$\int_0^{0.5}\int_y^{y+w} \int_0^x \frac{dy}{2}dxdw$$ for $X > Y$
When I evaluate these integrals and sum them, the answer comes out as a function of Y and X since it is far from being definite as I have not been provided with any X or Y values.
Trial 2:
Then I thought that maybe I should use $\int_x^{x+0.5}dy$ instead of $\int_0^{0.5}\int_x^{x+w}dydw$ which I still cannot understand why they give different values.
Then my function became
$$\int_x^{x+0.5} \int_0^y dx\frac{dy}{2}$$ for $Y > X$ and
$$\int_y^{y+0.5} \int_0^x \frac{dy}{2}dx$$ for $X > Y$
which led me to oppose the same problem now I cannot think of an alternative solution to this problem. Any help would be appreciated.
 A: Comment. Maybe some simulation results (from R) will help you get a mental picture of this problem.
set.seed(213)
X = runif(10^6);  Y = runif(10^6, 0,2)
W = abs(X-Y)
mean(W <= .5)
[1] 0.437011    # aprx 7/16 = 0.4375


hist(W, br=20, prob=T, col="skyblue2")
 abline(v=.5, col="orange", lwd=3, lty="dotted")


Using fewer points for better plots of individual points.
Points plotted in orange, are the ones that match $\{W < .5\}.$
(Integration is probably best done in two pieces. However, because the joint distribution of $X$ and $Y$ is uniform, you could get
the answer by geometry instead of integration.)
x = X[1:n]; y = Y[1:n];  w = W[1:n]
plot(x, y, pch=".")
 points(x[w<.5], y[w<.5], pch=".", col="orange")


A: Hi: I won't do all the work so this is not a complete answer but take the first case where W = (Y - X) > 0.
Then, if W < 0.5, then that means that Y  < 0.5 + X.
So, the double integral goes from 0 to 1 on X and from 0 to 0.5 + X
on Y.  So, one gets
$\int_{0}^{1} \int_{0}^{0.5 + x} \frac{1}{2} ~dy~dx $
The other case is similar except that (X - Y) > 0.
A: I have just solved the question so, here is the answer, I am changing the question as find the probability of W≤0.6 because I think that value serves better for purposes of teaching and will eliminate any possible confusions in the question.
First of all what we should do first is to assign probabilities.
If $ W = |X-Y|$ and $Pr(W <= 0.6)$ we are looking for $ Pr( Y - X <= 0.6)$ for $ Y > X$. $Y\epsilon[X,X+0.6]$
We are looking is in my domain as well as all $X\epsilon[0,1]$ So my integral for $Y > X$ is:
$$Pr(Y - X <= 0.6|Y>x) = \int_0^1 \int_x^{x+0.6}\frac{dy}{2}dx = \frac{3}{10} $$
and ${Pr( X - Y <= 0.6)}$, $Y\epsilon[X - 0.6, X]$ for $X\epsilon[0.6,1]$ so integral for $ X > Y$ is:
$$Pr(X - Y <= 0.6|X>y) =\int_{0.6}^1 \int_{x-0.6}^{x}\frac{dy}{2}dx + \int_0^{0.6} \int_0^{x}\frac{dy}{2}dx$$
Now all we have to do is sum that two integrals and then the probability of $ W <= 0.6 $ equals to::
$$ \frac{3}{10}+\frac{6}{50}+\frac{9}{100} = \frac{51}{100}$$
