Generating Function of non identically distributed random variables in branching process Let $\{Z_n\}_{n=0}^{\infty}$ be a sequence of random variables such that
$Z_0 = 1 \,\,\,\,\,\,\,\,\,  $ and $ \,\,\,\,\,\,\,\,\, Z_n = \sum_{i=1}^{Z_{n-1}} Y_{i}^{n-1}$
where $\{ Y_i ^n \}_{(n,i) \in \mathbb{N} \times \mathbb{N}}$ is a sequence of independent random variables satisfying
$\mathbb{P}( Y_i ^ n = 2) = \frac{e^{\frac{1}{n+2}}}{2}\,\,\,\,\,\,$ and $\mathbb{P}( Y_i ^ n = 0) = 1 - \frac{e^{\frac{1}{n+2}}}{2}$
Find the Generating Function $G_n$ of $Z_n$ in terms of $G_{n-1}$, the Generating Function of $Z_{n-1}$.
My attempt:
There is a theorem that states that if $S$ is a sum of $N$ independent and identically distributed random variables as $S = X_1 + ... + X_N$ (where $N$ is also a random variable), then
$G_S(s) = G_N (G_X (s))$
But as for each $n$ and $k \geq 0$, $Z_n$ and $Z_{n-k}$ are composed of non identically distributed random variables I am not sure this applies. I tried that as $Z_n$ for fixed $n$ is a sum of independent random variables, then
$G_{Z_n}(s) = G_{\sum_{i=1}^{Z_{n-1}} Y_{i}^{n-1}} (s) = G_{Y_{1}^{n-1}}(s) (...) G_{Y_{Z_{n-1}}^{n-1}}(s)$
which would be equal to $(G_{Y_{i}^{n-1}}(s))^{Z_{n-1}}$ and which by some calculation would end with
$G_{Z_n}(s) = \left( 1 - \frac{e^{\frac{1}{n+2}}}{2} + s^2 \frac{e^{\frac{1}{n+2}}}{2}\right)^{Z_{n-1}} $
but then I would also end with
$G_{Z_{n-1}}(s) = \left( 1 - \frac{e^{\frac{1}{n+1}}}{2} + s^2 \frac{e^{\frac{1}{n+1}}}{2}\right)^{Z_{n-2}} $
I would like to know if my approach is in the wrong direction and maybe a hint.
 A: I think I solved the question. By the Law of Total Expectation we have
$ G_{Z_n} (s) = \mathbb{E}[s^{Z_n}] = \sum_{k=0}^{\infty} \mathbb{E}[s^{Z_n}|Z_{n-1} = k]\mathbb{P}(Z_{n-1} = k)$
$= \sum_{k=0}^{\infty} \mathbb{E}\left[s^{\sum_{i = 1}^{Z_{n -1}} Y_{i}^{n-1}} \bigg| Z_{n - 1} = k\right]\mathbb{P}(Z_{n -1} = k)$
$= \sum_{k=0}^{\infty} \mathbb{E}\left[s^{\sum_{i = 1}^{k} Y_{i}^{n-1}} \bigg| Z_{n - 1} = k\right]\mathbb{P}(Z_{n -1} = k)$
such that by independence is equal to
$\sum_{k=0}^{\infty} \mathbb{E}\left[s^{\sum_{i = 1}^{k} Y_{i}^{n-1}} \right]\mathbb{P}(Z_{n -1} = k)$
$= \sum_{k=0}^{\infty} \mathbb{E}\left[\prod_{i = 1}^{k} s^{ Y_{i}^{n-1}} \right]\mathbb{P}(Z_{n -1} = k) $
which by independence is equal to
$= \sum_{k=0}^{\infty} \left( \prod_{i = 1}^{k} \mathbb{E}\left[ s^{ Y_{i}^{n-1}} \right]\mathbb{P}(Z_{n -1} = k) \right) $
But, as in the exercise we have that the generating function of $Y_{i}^{n-1}$ is
$G_{Y_{i}^{n-1}}(s) = \sum_{j=0}^{\infty} s^j \mathbb{P} (Y_{i}^{n-1} = j)$
which, for $n$ fixed does not depend on the value of $i$ we can write $G_{Z_n}$ as
$G_{Z_n} (s) = \sum_{k=0}^{\infty} \left( \left[ G_{Y_{i}^{n-1}}(s) \right]^k \mathbb{P}(Z_{n - 1} = k) \right) $
but as
$G_{Z_{n-1}} (s) = \sum_{j=0}^{\infty} s^j \mathbb{P} (Z_{n-1} = j)$
we end with $G_{Z_n} (s) = G_{Z_{n-1}}(G_{Y_{i}^{n-1}}(s))$
