Exercise 12.6 Suppose $X$ and $Y$ are independent $U[0,1]$ variables.
Find the conditional expectation $E(|X-Y| \mid Y=y)$.
Answer is $y^2 - y + \frac12$ but I am not sure why
I calculated 1/3 and have no idea how the y^2 - y + 1/2 is the solution ~ any help would be greatly appreciated. I am not familiar with the script to type in my answer ~ so I attached an image of my hand calculations.
So~ if z =|x-y|

$E[(|X-Y|) | Y = y] = P(X < y)\cdot E[Y-X | Y=y$ and $X < y] + P(X > y)\cdot E[X-Y | Y=y$ and $X > y]$
$P(X < Y | Y = y) = y$
$P(X>y|Y=y) = 1-y$
so $E[(|X-Y|) | Y = y] = y\cdot E[y-X |X < y] + (1-y)\cdot E[X-y | X > y]$
$ = y\int_0^y(y-x)\cdot f(x|X<y) dx + (1-y) \int_y^1(x-y)f(x|X>y)dx$
Since $X$ is uniform, so is its conditional.
$f(x|X<y) = 1/y$
$f(x|X>y) = 1/(1-y)$
So we have $E[(|X-Y|) | Y = y] = y\cdot E[y-X |X < y] + (1-y)\cdot E[X-y | X > y] = $
$$y\int_0^y(y-x)\cdot 1/y dx + (1-y) \int_y^1(x-y)]\cdot1/(1-y)dx$$ $$ = \int_0^y(y-x) dx + \int_y^1(x-y)] dx$$ $$ = y^2 - y + 1/2$$