Expectations as integrals with respect to a joint distribution As part of self-study, I'm trying to learn about conditional expectation. Example 5 here presents the problem:
"Let $X_1, X_2$ be independent with $U(0, \theta)$ distribution for some known $\theta$. Let
$Y = \max\{X_1, X_2\}$ and $X = X_1$. We want to find the conditional mean of $X$ given $Y$."
It presents an equation based on "rewrit[ing]...expectations as integrals with respect to the joint distribution of $(X_1, X_2)$:" $\int_0^d\int_0^d\frac{x_1}{\theta^2}\mathrm{d}x_1\mathrm{d}x_2 = \int_0^d\frac{3y}{4}\frac{2y}{\theta^2}\mathrm{d}y$, but I don't really get this. I think the $\frac{1}{\theta^2}$ comes from the joint density of $(X_1, X_2)$ but I don't understand why there is a double integral for calculating expectation on one side and how there is a $2$ on the other side.
Can I have some guidance on how this rewriting was done?

You're right, $f(x_1,x_2)=\frac{1}{\theta^2}I(0<x_1<\theta)I(0<x_2<\theta)$ is the joint density of $(X_1, X_2)$. The left hand side $E(X_1 I(Y<d))$ is computed using $$E(g(X_1,X_2))=\int g(x_1,x_2)f(x_1,x_2) dx_1 dx_2$$ where in this particular case $g(x_1,x_2)=x_1 I(\max(x_1, x_2)<d)$. The right hand side $E([3Y/4]I(Y<d))$ only involves $Y$, so it's easier to handle if we can obtain the density of $Y$. This density can be obtained by differentiating the cdf of $Y$, and you should obtain $f(y)=\frac{2y}{\theta^2}$.
Note: you could also calculate the right hand side as a double integral, explicitly rewriting $Y$ as $\max(X_1,X_2)$. This is perfectly possible, but the stated approach is easier if you are familiar with the density of $Y$.
