TITLE: Retrieve the random variable from its conditional expectations
QUESTION [10 upvotes]: I came across a problem that looks easy but turns out to be extremely hard. The problem goes as follows:
$X,Y$ are two independent random variables with support on interval $[0,1]$ and $\mathrm{E}[X]=\mathrm{E}[Y]=\mu \in (0,1)$. Construct a random variable $Z=f(X,Y)$ as a function of $X,Y$ with the following two properties:

$Z$ has support [0,1].
$\mathrm{E}[f(X,Y)|X] = X$ and $E[f(X,Y)|Y]=Y$.

Remark 1.
The first example I have is $Z=XY/\mu$ which satisfies 2 but not 1 because $Z$ could take on value $Z=1/\mu>1$. The second example is $Z=X+Y-\mu$ which satisfies 2 but not 1 again.
Remark 2. In fact, my best strategy now is to consider a class of random variables
$$
Z= \alpha \frac{XY}{\mu} + (1-\alpha) (X+Y-\mu) + \beta\mathrm{E}[(g(X)-\mathrm{E}g(X))(h(Y)-\mathrm{E}h(Y))]
$$
for any functions $g,h$ and scalars $\alpha,\beta$. $Z$ clearly satisfies 2. But it is very hard to restrict the support of $Z$ to interval $[0,1]$.
I am stuck and I am looking forward to a fresh set of ideas from the community.

REPLY [2 votes]: This isn’t possible for continuous $f$. Since $\mathsf E(f(X,Y)\mid X=0)=0$, we must have $f(0,Y)=0$, and since $\mathsf E(f(X,Y)\mid Y=1)=1$, we must have $f(X,1)=1$; but then $0=f(0,1)=1$.
I suspect you could extend that to an argument that it’s not possible for discontinuous $f$, either.