I'm reading a paper (section 5.1) that approximated the expected value of a function $f(X,Y)$ of two random variables using Gibbs sampling.
As far as I know the expectation of $f(X,Y)$ is defined to be:
$E[f(X,Y)] = \sum_{x}\sum_{y}p(X=x,Y=y) f(x,y)$
what they said in the paper is that this is very expensive to compute so they said that we approximate the expectation by drawing a sample from the joint distribution using Gibbs sampling and then calculate the expectation as the following:
1- Draw a sample $x$ using Gibbs sampling.
2- Then $E[f(X,Y)] = \sum_{y}p(Y=y|x) f(x,y)$.
What I don't understand is step 2. I don't why we removed the summation over all values of $x$ and why we are using the conditional probability and the link or idea behind how a sample of $x$ from the joint distribution would make up that equation in 2. How and why is that equivalent to the expectation?!
p.s. I don't have excellent skills in probability theory so please elaborate your answers :)