Are random variables equal almost surely if their expectation are interchangable? Suppose you have $X$ and $Y$ on a common probability space Let $h,g$ be arbitrary bounded Borel-measurable functions. If you have:
$$
\mathbb{E}(h(X)g(Y)) = \mathbb{E}(h(X)g(X))
$$
Do you also have X=Y a.s.?
My intuition is yes, using $h=1,g(\cdot)=|\cdot-X|$ (is this allowed?), and then LHS=RHS=0 meaning $|X-Y|=0$ a.s.

For $A,B\in \mathcal B(\mathbb R)$, using the hypothesis with $h=1_A$ and $g=1_B$, $$P\big((X\in A) \cap (Y\in B)\big) = P\big(X\in (A\cap B)\big).$$
Taking $A=\mathbb R$ yields $ \forall B\in \mathcal B(\mathbb R)$, $P(Y\in B) = P(X\in B)$, hence $X\stackrel{d}= Y$.
Consequently, for any bounded measurable $h,g$ we have
$$E\big(h(X)g(Y) \big) = E\big(h(X)g(X) \big) = E\big(h(Y)g(Y) \big)$$
and exchanging $h$ and $g$ we have additionally
$$E\big(g(X)h(Y) \big) = E\big(g(X)h(X) \big)$$
thus
$$E\big(h(X)g(Y) \big) = E\big(g(X)h(Y) \big) = E\big(h(X)g(X) \big) = E\big(h(Y)g(Y) \big)$$
so that $$E\big([g(X)-g(Y)][h(X)-h(Y)] \big) = 0.$$
Taking $g=h=\arctan$ yields $$E\big([\arctan(X)-\arctan(Y)]^2 \big) = 0,$$ hence
$\arctan(X)=\arctan(Y)$ a.s. and
$X=Y$ a.s.
