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.
 A: 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.
A: 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?
