Let $x$ and $y$ be iid random variables, with $x\sim U[0,1]$ and $y\sim U[0,1]$. Define $a=x+y$. What is $\mathbb{E}[x^2|a]$?
I know that $a$ has a triangular distribution, and can guess that $\mathbb{E}[x|a]=a/2$. But I don't know how to approach finding the distribution of $x$ conditional on $a$.
In general, for two random variables $\xi, \eta$ with joint density $f(x, y)$, the conditional density of $\xi$ given $\eta = y$ is given by \begin{align} g(x|y) = \frac{f(x, y)}{\int_\mathbb{R} f(t, y)dt}, \quad x \in \mathbb{R}. \tag{1} \end{align}
So the key step of solving this problem (i.e., "how to approach finding the distribution of $x$ conditional on $a$") is to determine the joint distribution of $(X, A)$ (I will follow the convention of using capital letters for random variables and using lower-case letters for real values). By considering the bijective $\xi = X, \eta = X + Y$ with Jacobian determinant $1$, it can be shown that the joint density of $(X, A)$ is \begin{align} f(x, a) = \begin{cases} 1 & (x, a) \in \{(u, v): 0 \leq u \leq 1, u \leq v \leq u + 1\}, \\ 0 & \text{otherwise}. \end{cases} \tag{2} \end{align}
Visually, $(X, A)$ is uniformly distributed in the shaded parallelogram as shown above.
It then follows by $(1)$ and $(2)$ that:
If $0 < a < 1$: \begin{align} g(x|a) = \begin{cases} a^{-1} & 0 < x \leq a, \\ 0 & \text{otherwise}. \end{cases} \end{align} Hence \begin{align} E[X^2|A = a] = \int_0^ax^2g(x|a)dx = a^{-1}\int_0^ax^2dx = \frac{1}{3}a^2.\tag{3} \end{align}
If $1 \leq a < 2$: \begin{align} g(x|a) = \begin{cases} (2 - a)^{-1} & a - 1 < x \leq 1, \\ 0 & \text{otherwise}. \end{cases} \end{align} Hence \begin{align} E[X^2|A = a] = \int_{a - 1}^1x^2g(x|a)dx = (2 - a)^{-1}\int_{a - 1}^1x^2dx = \frac{1}{3}(a^2 - a + 1). \tag{4} \end{align}
In terms of standard conditional expectation notation, $(3)$ and $(4)$ can be collapsed as:
\begin{align} E[X^2|A] = \frac{1}{3}A^2I_{(0, 1)}(A) + \frac{1}{3}(A^2 - A + 1)I_{[1, 2)}(A). \end{align}