# Sum of infinite geometric series within probability generating function question

I'm working through the solution posted for this question here:

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.$$

There were two sign errors that I just corrected. The idea in the last step is to rewrite in the form of a geometric series: $$\frac{a}{1-x}=\sum_{n=0}^\infty a x^n.$$ To get the $$1$$ where we want it, divide both numerator and denominator by $$2-p$$: $$\frac{2(1-p)}{2-p-pz}=\frac{2(1-p)/(2-p)}{(2-p-pz)/(2-p)}=\frac{2(1-p)/(2-p)}{1-pz/(2-p)}.$$ Now take $$a=2(1-p)/(2-p)$$ and $$x=pz/(2-p)$$ in the formula for geometric series.