Probability question with trees and fruit using probability generating functions 
Each year a tree of a particular type flowers once and the probability that it has n flowers is $(1-p)p^n$, $n=0,1,2...,$ where $0<p<1$. Each flower has probability $1/2$ of producing a ripe fruit, independently of all other flowers. Find the probability generating function for the number of ripe fruits produced by the tree. Hence find the probability that in a given year
(a) the tree produces $r$ ripe fruits.
(b) the tree had $n$ flowers if it produces $r$ ripe fruits.

I have called the number of flowers $N$ where it's generating function is $G_N(s)=\frac{1-p}{1-ps}$. If we say that the number of fruits coming from flower $i$ is $X_i$ where $X_i\sim$ Ber(1/2) then $G_X(s)=\frac{1}{2}-\frac{1}{2}s$. This should mean the generating function of $F$ (The number of fruit, i.e. $\sum_{i=1}^{N}X_i$ )is $G_N(G_X(s))=\frac{2(1-p)}{2-p-ps}$. I was wondering how I might get answers to (a) and (b) from this. Thank you for any help.
 A: Given that the tree produced $N=n$ flowers, the number of ripe fruits $R$ follows binomial distribution $\operatorname{Bin}\left(n,\frac{1}{2}\right)$. Hence the probability of having $r$ ripe fruits is
$$
  \Pr\left(R=r\right) = \sum_{n=r}^\infty \Pr(N=n)\Pr(R=r\mid N=n) = \sum_{n=r}^\infty (1-p)p^n \binom{n}{r} \frac{1}{2^n}
$$
We are tasked with computing the probability generating function:
$$\begin{eqnarray}
   \mathcal{P}_R(z) &=& \sum_{r=0}^\infty \Pr(R=r)z^r = \sum_{r=0}^\infty \sum_{n=r}^\infty\Pr(R=r\mid N=n) \Pr(N=n)z^r = \\ &=& \sum_{n=0}^\infty \Pr(N=n) \sum_{r=0}^n \Pr(R=r\mid N=n) \Pr(N=n)z^r \\
 &=&  \sum_{n=0}^\infty \Pr(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-2p}{2-p - p z} = \sum_{r=0}^\infty \frac{2-2p}{2-p} \left(\frac{p}{2-p}\right)^r z^r
\end{eqnarray}
$$
Hence
$$
    \Pr(R=r) = \frac{2-2p}{2-p} \left(\frac{p}{2-p}\right)^r
$$
For the second question we can use Bayes theorem:
$$\begin{eqnarray}
   \Pr\left(N=n\mid R=r\right) &=& \frac{\Pr\left(N=n, R=r\right)  }{\Pr\left(R=r\right)} = \frac{ \Pr\left(R=r\mid N=n\right) \Pr(N=n)  }{\Pr\left(R=r\right)} \\
 &=& \frac{ \binom{n}{r} 2^{-n} (1-p) p^n}{\frac{2-2p}{2-p} \left(\frac{p}{2-p}\right)^r }
\end{eqnarray}
$$
