This is an extension to the [[Total Probability Theorem#^83d664|Total Probability Theorem]], which states the following for a discrete [[Random Variable]].
![[Total Probability Theorem#^881fd7]]
However, now instead of the unconditional $p_X(x)$ we want to obtain the unconditional $\mathbb E[X]$. Similarly we achieve this by doing a weighted sum of all conditional [[Expectation|expectations]].
$
\begin{align}
\mathbb E[X] =\sum_x x*p_X(x)&= \underbrace{\sum_x x*p_{X\vert A_1}(x)}_{\mathbb E[X\vert A_1]} *\mathbf P(A_1)+ \cdots \\&+ \underbrace{\sum_x x*p_{X\vert A_n}(x)}_{\mathbb E[X\vert A_n]}*\mathbf P(A_n)
\end{align}
$
We notice that $x$ multiplied by the conditional PMF $p_{X\vert A}$ returns the conditional expectation $\mathbb E[X \vert A]$ and write a sum over all discrete events $A_i$.
$ \mathbb E[X] = \sum_{i=1}^n\mathbb E[X\vert A_i]* \mathbf P(A_i)$ ^38d58d
The same logic applies to continuous r.v.:
$ \mathbb E[X] =\int_z \mathbb E [X \vert Z=z] * f_Z(z)* dz $