Let $(X,Y)$ be a random variable that takes values in $\mathbb{R}^2$. We say $X$ and $Y$ are independent if $E(f(X)g(Y))=Ef(X)Eg(Y)$. Prove that if $P(X=a)=0$ for all $a\in\mathbb{R}$, then $P(X=Y)=0$.
My work:
We can define $\mu(A)=P(X\in A)$ and $\nu(B)=P(Y\in B)$ as probability measure. Then, one has $P(X=a)=\mu(a)=0$. But I have trouble to prove $P(X=Y)=P(X=a,Y=a)=\mu(a)\nu(a)=0$, so we do not know whether two variables are independent or not. Can someone give me hints?
As noted, you have to assume $X,Y$ are independent.
Let $f(x,y) = \begin{cases} 1, & x=y \\ 0, & x \ne y \end{cases}$ be the Kronecker delta function. Then note that $P(X=Y) = E[f(X,Y)]$.
Now if $\mu,\nu$ are the respective distributions of $X,Y$, then by independence and Fubini's theorem, we have $$P(X=Y) = E[f(X,Y)] = \iint_{\mathbb{R}^2} f(x,y)\, (\mu \times \nu)(dx,dy) = \int_{\mathbb{R}} \int_{\mathbb{R}} f(x,y) \mu(dx) \nu(dy).$$ But for each $y \in \mathbb{R}$, we have $\int_{\mathbb{R}} f(x,y) \mu(dx) = E[f(X,y)] = P(X=y) = 0$.