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.

You cannot make that choice of $g$ but  the result is true:
You get $P(X \in A, Y\in A)=P(X \in A)$ by taking $g=h=I_A$. But $(X \in A, Y\in A) \subseteq (X \in A)$. From this it follows that $X\in A$ implies $Y \in A$ a.s. [in the sense $P(X \in A, Y \notin A)=0$. Thus $\frac {i-1}n \leq X \leq \frac i n$ implies $\frac {i-1}n \leq Y \leq \frac i n$ so $|X-Y| \leq \frac 1 n$ a.s.  Can you take it from here?
