# Integrating $\int_0^1 \int_0^1 |x-y|\,\text{d}x\,\text{d}y$ by hand

Here's a problem from my probability textbook:

If two points be taken at random on a finite straight line their average distance apart will be one third of the line.

What I did: I got the integral$${{\int_0^1 \int_0^1 |x-y|\,\text{d}x\,\text{d}y}\over{1^2}},$$which ends up evaluating to $${1\over3}$$ according to Wolfram Alpha. However, I am not sure how to evaluate the integral by hand, given that there's the absolute value sign. Any help would be appreciated.

• Split the integral into two parts, one where $y<x$ and one where $y>x$. Then you can rewrite the integral without the absolute value bars because you'll know the sign of $x-y$. Commented Sep 21, 2021 at 6:16
• math.stackexchange.com/q/3004029/321264 Commented Sep 21, 2021 at 6:56

Hint $$:$$ \begin{align*}\int_{0}^{1}\int_{0}^{1} |x - y|\ dx\ dy & = \int_{0}^{1}\int_{0}^{y} (y - x) \ dx\ dy + \int_{0}^{1}\int_{y}^{1} (x - y)\ dx\ dy. \end{align*}
• @Emperor Concerto$:$ I just break the interval in which $x$ varies. First I let $x$ to vary from $0$ to $y$ and then from $y$ to $1.$ Draw pictures to convince yourself.
• Second integral on the right should be $\displaystyle \int_{0}^{1}\int_{y}^{1} (x - y)\ dx\ dy$ Commented Sep 21, 2021 at 6:28
• @Math Lover$:$ That's exactly what I did. Please have a look at it.
• it shows correct now. It showed $\displaystyle \int_{0}^{1}\int_{y}^{x} (x - y)\ dx\ dy$ earlier. Commented Sep 21, 2021 at 6:31