# Expected value of $\max(X-Y,0)^2$ and $g(X_1,\ldots,X_n)$

Let $Y,Z$ be two continuous random variables with density functions $f_Y(y),f_Z(z)$ respectively. Then is it true that

$$\mathbb E[(\max(Z-Y,0))^2] = \int_{-\infty}^\infty \int_{-\infty}^\infty f_Y(y)f_Z(z)(\max(z-y,0))^2 dz dy$$

? If so, is the following (more general) statement true as well? Let $X_1,\ldots,X_n$ be some continuous random variables and $g:\mathbb R^n\to\mathbb R$ some function (possibly measurable in some sense?). Then

$$\mathbb E[g(X_1,\ldots,X_n)] = \int_{-\infty}^\infty\ldots \int_{-\infty}^\infty f_{X_1}(x_1)\ldots f_{X_n}(x_n)g(x_1,\ldots,x_n)\ dx_n\ldots dx_1$$

One must also have independence of $Y$, $Z$; otherwise you cannot use the product of their marginal densities, but their joint density $f_{Y,Z}(y,z)$. With respect to the basic idea, yes, the relationship is true.