# Expectation of special sum and indicator function, i.i.d. random variables

Let $$X_1, X_2, X_3, \ldots \in \mathscr{L}^1(\mathbb{P})$$ be independent, identically distributed random variables with values in $$\left[0, \infty\left[\right. \right.$$ and $$N \in \mathscr{L}^1(\mathbb{P})$$ a random variable independent of $$X_1, X_2, X_3, \ldots$$ with values in $$\mathbb{N}$$. Let the random variable $$S_N$$ be given by $$S_N:=\sum_{n=1}^{\infty} S_n \mathbf{1}_{\{N=n\}}$$ where $$S_n:=\sum_{k=1}^n X_k, n \in \mathbb{N}$$. Show that $$\mathbb{E}\left(S_N\right)=\mathbb{E}(N) \mathbb{E}\left(X_1\right)$$ holds.

First of all, I think I have to show that $$S_N$$ is a random variable. Nevertheless, I got this: $$\mathbb{E}\left(S_N\right)=\mathbb{E}\left(\sum_{n=1}^{\infty} S_n \mathbf{1}_{\{N=n\}}\right)=\sum_{n=1}^{\infty}\mathbb{E}\left(S_n \mathbf{1}_{\{N=n\}}\right)=\sum_{n=1}^{\infty}\mathbb{E}(S_n) \mathbb{E}(\mathbf{1}_{\{N=n\}})$$ and here I dont know if it is right to say that this equals to $$\sum_{n=1}^{\infty}\mathbb{E}(S_n) \mathbb{E}(N)=\sum_{n=1}^{\infty}\mathbb{E}\left(\sum_{k=1}^n X_k\right) \mathbb{E}(N)=\sum_{n=1}^{\infty}\sum_{k=1}^n\mathbb{E}\left(X_k\right) \mathbb{E}(N)=\mathbb{E}(X_1) \mathbb{E}(N)$$ I am not sure and I think I broke some math laws here. Any hints on this expectation and how to show that $$S_N$$ is a random variable? Thanks in advance!

That $$S_N$$ is a random variable simply follows from the fact that it is the pointwise limit of $$\left(\sum_{n=1}^\ell S_n\mathbf{1}_{\{N=n\}}\right)_{\ell\geqslant 1}$$ (the series is convergent since the sets $$\{N=n\},n\in\mathbb N$$ are pairwise disjoint.
The expectation you want is not equal to $$\sum_{n=1}^{\infty}\mathbb{E}(S_n) \mathbb{E}(N)$$, actually, unless $$X_1$$ is centered, $$\sum_{n=1}^{\infty}\mathbb{E}(S_n)$$ is divergent.
However, it was correct until this point and you can use that $$\mathbb E(S_n) \mathbb{E}\left(\mathbf{1}_{\{N=n\}}\right)=n\mathbb E(X_1)\mathbb{E}(\mathbf{1}_{\{N=n\}})$$ then $$n\mathbb{E}\left(\mathbf{1}_{\{N=n\}}\right)= \mathbb{E}\left(n\mathbf{1}_{\{N=n\}}\right)= \mathbb{E}\left(N\mathbf{1}_{\{N=n\}}\right),$$ which gives $$\mathbb E(S_n) \mathbb{E}\left(\mathbf{1}_{\{N=n\}}\right)=\mathbb E(X_1)\mathbb{E}\left(N\mathbf{1}_{\{N=n\}}\right)$$ and summing over $$n\in\mathbb N$$ gives the wanted formula.