# How to calculate $P (|X − Y | ≤ 1/6)$? [duplicate]

$f_{X,Y} \left( x, y \right) = 1\quad \text{for}\quad 0≤x≤1,\ 0≤y≤1$ and $0$ otherwise.

How to calculate $P \left( |X − Y | ≤ 1/6 \right)$?

• Hint: draw a graph. – JohnK Nov 21 '14 at 9:35
• I don't know how to draw a graph for two variables :/ – Ghetty Noman Nov 21 '14 at 9:37
• You can put x on the x axis and y on the y axis. The support, ie where the pdf is nonzero, is a square. Find the locus of points for which y is within a sixth of x - that's the region you have to integrate over, and since the density is constant, that's equivalent to finding the area and multiplying by the density. – Silverfish Nov 21 '14 at 10:18
• Hi Ghetty and welcome to the site! As this is clearly a self-study-question, please add the self-study tag to your question because we treat these questions differently. More information here. – COOLSerdash Nov 21 '14 at 10:54
• Please read the self-study tag wiki and update your question accordingly. – Glen_b Nov 21 '14 at 14:29

You can solve it with some reformulations of your initial condition. At first, get rid off the absolute value and replace it with an interval. Then, take the probability for values up to $1/6$ and subtract the probability for values up to $-1/6$. In the next step, one needs to find the integrals. For this, you need to think for what points the inequalities are true. Hence, I split up $P[X-Y \le 1/6]$ into two integrals. Clearly, the inequality holds for all $x \in [0,1/6]$ and $y \in [0,1]$. However, it does not hold for all $x \in [1/6,1]$ but one can easily find the values by rearranging the inequality such that one finds an interval for $y$ depending on $x$. For the other term holds $P[X-Y < -1/6]=P[Y-X \ge 1/6]$. Now, one needs to consider again all values the inequality holds for but needs to take into account the domain of $y$ .

When all these steps are done, the only thing left is to solve the integrals, but that's easy since the density is 1.

$\quad P[\left|X-Y \right| \le 1/6] \\ = P[X-Y \in [ -1/6,1/6] ] \\ = P[X-Y \le 1/6] - P[X-Y < -1/6] \\ = \int_{0}^{1/6} \int_{0}^{1}dxdy + \int_{1/6}^{1} \int_{x-1/6}^{1}dxdy - \int_{0}^{5/6} \int_{x+1/6}^{1}dxdy \\ = 47/72 - 25/72 = 11/36.$

Edit: I updated this answer because in the first try I took wrong integrals. But now it's correct! :)

• I don't think this is correct. It appears you have counted an area that does not belong to the unit square. – JohnK Nov 21 '14 at 13:59
• I think using calculus actually obfuscates things. A quick sketch, and knowledge of "half base times height" to find the area of a triangle (which reduces to "base times height" if you have two of them!) and the required area pops out easily. – Silverfish Nov 21 '14 at 14:05
• I agree with @Silverfish. For comparison, I think the correct answer is $\frac{11}{36}\approx 0.31$. – COOLSerdash Nov 21 '14 at 14:09
• @JohnK To be sure, I ran two simulations: one using R and one using Mathematica. Both tend to agree with my result which gives me confidence that it is correct. Provided I didn't misunderstand the question, of course. – COOLSerdash Nov 21 '14 at 14:53
• I thought I did simple algebra. What do you think, where is the mistake? – random_guy Nov 21 '14 at 14:55