How to derive the law of total probability for three or more RVs? I'm confused about the generalization of the law of total probability (or sum rule) for more than two Random Variables. For two RVs, it is defined as
$$
P(X=x) = \sum_{y\in \mathcal{Y}}P(x,y).
$$
However, I'd like to clarify how this generalizes to more than two RVs. What I've tried is a simple analogy, e.g. for three RVs:
$$
P(X=x) = \sum_{y\in \mathcal{Y}}\sum_{z\in \mathcal{Z}}P(x,y,z).
$$
I'm not sure about is whether the analogy is correct and whether some prior must be considered in between the steps of the computation, e.g. is it needed to consider $P(Y)$ if I still need to compute $P(x,y,Z)$? I'm possibly confused with the conditional form of this.
Also it causes confusion for me when I see
$$
P(X_1) = \sum_{i=2}^\ell P(X_1,X_i)
$$
because I'm not sure whether $X_i$ (i=1,\dots,\ell) can be considered different RVs or $X_i$ are instances of some RV $X$.
I'll be grateful if you can give also general advise on this theme. Thank you very much
 A: When dealing with discrete random variables, $X,Y$, whose probability mass function are supported over intervals $\mathcal X,\mathcal Y$, the Law of Total Probability states:
$$\mathsf P(X{=}x)=\sum_{y\in\mathcal Y}\mathsf P(X{=}x,Y{=}y)$$
Or $$P_{\small X}(x)=\sum_{y\in\mathcal Y} P_{\small X,Y}(x,y)$$
Of course this can be expanded to more such random variables.  Say by adding $Z$
$$\mathsf P(X{=}x)=\sum_{y\in\mathcal Y}\sum_{z\in\mathcal Z}\mathsf P(X{=}x,Y{=}y, Z{=}z)$$
Or $$P_{\small X}(x)=\sum_{y\in\mathcal Y}\sum_{z\in\mathcal Z} P_{\small X,Y,Z}(x,y,z)$$

Basically the probability mass of event $\{X=x\}$ equals the sum of the probability mass of disjoint events $\{X=x,Y=y,Z=z\}$ for all supported values for $y, z$; because $\{X=x\}$ equals the union of all these disjoint events.


Also it causes confusion for me when I see: $$P(X_1) = \sum_{i=2}^\ell P(X_1,X_i)$$

Indeed, in such an expression, those do not appear to be random variables at all, but rather events. To be clear, let us use some different letters for them. Specifically when $A$ is an event and ${\{B_i\}}_{i=1}^\ell$ is a sequence of $\ell$ disjoint events that partition over $A$  [that is, $A\subseteq \bigcup_{i=1}^\ell\{ B_i\}$ ], then:$$\mathsf P(A)=\sum_{i=1}^\ell\mathsf P(A\cap B_i)$$
