TITLE: Average distance between two random points on a square with sides of length $1$
QUESTION [5 upvotes]: "What's the average distance between two random points on a square with sides of length $1$?"
Here is an attempt which is wrong but I can't see how exactly.
Fix $(x, y) \in [0, 1]^2$
The average distance from $x$ to some $x' \in [0,1]$ is 
$\triangle x = 0.5x^2 + 0.5(1-x)^2 $
Likewise $\triangle y = 0.5y^2 + 0.5(1-y)^2 $
One could argue that the average distance between fixed $(x, y)$ and some $(x', y') \in [0,1]^2$ is then  $\triangle r = \sqrt{\triangle y^2 + \triangle x^2} $
Then just take the average of $\triangle r(x,y)$. Double integrating $\triangle r$ in terms of x and y over the boundaries  gives around 0.47.
Close but not correct. Why doesn't this work?

REPLY [5 votes]: $\newcommand{\angles}[1]{\left\langle\,{#1}\,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\Li}[1]{\,\mathrm{Li}}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
Note that, in $\ds{2D}$,
\begin{align}
r & = {1 \over 3}\,\nabla\cdot\pars{r\,\vec{r}} =
{1 \over 3}\bracks{\partiald{\pars{rx}}{x} + \partiald{\pars{ry}}{y}} =
{1 \over 3}\bracks{\partiald{\pars{rx}}{x} - \partiald{\pars{-ry}}{y}}
\\[3mm] & =
{1 \over 3}\bracks{\nabla\times\pars{-ry\,\hat{x} + rx\,\hat{y}}}_{z} =
-\,{1 \over 3}\braces{\nabla\times\bracks{\root{x^{2} + y^{2}}
\pars{y\,\hat{x} - x\,\hat{y}}}}_{z}\tag{1}
\end{align}

Lets $\ds{\vec{r} \equiv \pars{x,y}}$ and $\ds{\vec{R} \equiv \pars{X,Y}}$.

\begin{align}
\color{#f00}{?} & =
\iint_{\pars{0,1}^{\,\, 4}}\ \verts{\vec{r} -\vec{R}}\,\dd^{2}\vec{r}
\,\dd^{2}\vec{R} =
\int_{\pars{0,1}^{\,\, 2}}\bracks{\int_{\pars{0,1}^{\,\, 2}}\
\verts{\vec{R} -\vec{r}}\,\dd^{2}\vec{R}}\dd^{2}\vec{r}\tag{2}
\end{align}

With the identity $\ds{\pars{1}}$:
\begin{align}
&\!\!\!\!\!\int_{\pars{0,1}^{\,\, 2}}\verts{\vec{R} -\vec{r}}\,\dd^{2}\vec{R} =
-\,{1 \over 3}\oint_{\pars{0,1}^{\,\, 2}}
\root{\pars{X - x}^{2} + \pars{Y - y}^{2}}
\bracks{\pars{Y - y}\,\dd X - \pars{X - x}\,\dd Y}
\\[8mm]= &\
\!\!-\,{1 \over 3}\int_{0}^{1}
\root{\pars{X - x}^{2} + y^{2}}\pars{-y}\,\dd X -
{1 \over 3}\int_{0}^{1}
\root{\pars{1 - x}^{2} + \pars{Y - y}^{2}}\bracks{-\pars{1 - x}}\,\dd Y
\\[3mm] &\ 
\!\!-\,{1 \over 3}\int_{1}^{0}
\root{\pars{X - x}^{2} + \pars{1 - y}^{2}}\pars{1 - y}\,\dd X -
{1 \over 3}\int_{1}^{0}
\root{x^{2} + \pars{Y - y}^{2}}\bracks{-\pars{-x}}\,\dd Y
\\[8mm] = &\
{2 \over 3}\,y\,\mathrm{f}\pars{x,y^{2}} +
{2 \over 3}\,x\,\mathrm{f}\pars{y,x^{2}}\tag{3}
\\[3mm] &\
\qquad\qquad\mbox{where}\quad
\mathrm{f}\pars{a,b} \equiv
\int_{0}^{1}\root{\pars{\xi - a}^{2} + b}\,\dd\xi\tag{4}
\end{align}

With $\ds{\pars{3}}$ and $\ds{\pars{4}}$, the expression $\ds{\pars{2}}$ is reduced to:
\begin{align}
\color{#f00}{?} & =
\int_{0}^{1}\int_{0}^{1}\bracks{%
{2 \over 3}\,y\,\mathrm{f}\pars{x,y^{2}} +
{2 \over 3}\,x\,\mathrm{f}\pars{y,x^{2}}}\,\dd x\,\dd y
\\[3mm] & =
{2 \over 3}\int_{0}^{1}\int_{0}^{1}\mathrm{f}\pars{x,y}\,\dd y\,\dd x =
{2 \over 3}\int_{0}^{1}\int_{0}^{1}\int_{0}^{1}\root{\pars{\xi - x}^{2} + y}
\,\dd\xi\,\dd x\,\dd y
\\[3mm] & =
{4 \over 9}\int_{0}^{1}\int_{0}^{1}
\left.\vphantom{\huge A^{a}}
\bracks{\pars{\xi - x}^{2} + y}^{3/2}\,\,\right\vert_{\ y\ =\ 0}^{\ y\ =\ 1}
\,\,\,\,\,\dd\xi\,\dd x
\\[3mm] & =
{4 \over 9}\int_{0}^{1}\int_{0}^{1}
\braces{\bracks{\pars{\xi - x}^{2} + 1}^{3/2} - \verts{\xi - x}^{3}}
\,\dd\xi\,\dd x
\\[3mm] & =
{4 \over 9}\int_{0}^{1}\int_{-x}^{1 - x}
\pars{\bracks{\xi^{2} + 1}^{3/2} - \verts{\xi}^{3}}
\,\dd\xi\,\dd x
\\[3mm] & =
{4 \over 9}\int_{0}^{1}
\pars{\bracks{\xi^{2} + 1}^{3/2} - \verts{\xi}^{3}}
\pars{\int_{0}^{1 - \xi} - \int_{\xi}^{1}\,\dd x}\,\dd\xi
\\[3mm] & =
{8 \over 9}\int_{0}^{1}\pars{\xi^{2} + 1}^{3/2}\,\dd\xi\ -\
\overbrace{{8 \over 9}\int_{0}^{1}\xi\pars{\xi^{2} + 1}^{3/2}\,\dd\xi}
^{\ds{{8 \over 45}\pars{4\root{2} - 1}}}\
+\
\overbrace{{8 \over 9}\int_{0}^{1}\pars{\xi^{4} - \xi^3}\,\dd\xi}
^{\ds{-\,{2 \over 45}}}
\end{align}
The remaining integration can be straightforward evaluated with the sub$\ds{\ldots\xi = \sinh\pars{\theta}}$. The final result becomes:
$$
\color{#f00}{?} =
\color{#f00}{{1 \over 15}\bracks{2 + \root{2} + 5\ln\pars{1 + \root{2}}}} \approx 0.5214
$$