I'm working through the solution posted for this question here:
Probability question with trees and fruit using probability generating functions
But I'm stuck on the last line finding the probability generating function. I know that part of the answer involves finding the sum of an infinite geometric series and then flipping it back to get z on it's own but I don't get the circled part in the picture below. Any pointers on how you can do this would be appreciated!
Given that the tree produced $N=n$ flowers, the number of ripe fruits $R$ follows binomial distribution $\mathrm{Bin}\left(n,\frac12\right)$. Hence the probability of having $r$ ripe fruits is $$\mathbb P(R=r) = \sum_{n=r}^\infty \mathbb P(N=n)\mathbb P(R=r\mid N=n) = \sum_{n=r}^\infty (1-p)p^n\binom nr \frac1{2^n}. $$ We are tasked with computing the probability generating function: \begin{align} \mathcal P_R(z) &= \sum_{r=0}^\infty \mathbb P(R=r)z^r) = \sum_{r=0}^\infty \sum_{n=r}^\infty \mathbb P(R=r\mid N=n)\mathbb P(N=n)z^r\\ &= \sum_{n=0}^\infty \mathbb P(N=n)\sum_{r=0}^n \mathbb P(R=r\mid N=n)\mathbb P(N=n) z^r\\ &=\sum_{n=0}^\infty \mathbb P(N=n)\mathcal P_{R\mid N=n}(z)\\ &= \sum_{n=0}^\infty (1-p)p^n\left(\frac{1+z}2\right)^n\\ &= \frac{1-p}{1-p\frac{1+z}2}\\ &=\frac{2(1-p)}{2-p-pz} = \sum_{r=0}^\infty \frac{2(1-p)}{2-p}\left(\frac p{2-p}\right)^r z^r. \end{align} Hence $$\mathbb P(R=r) = \frac{2(1-p)}{2-p}\left(\frac p{2-p}\right)^r. $$