Mean and variance of geometric function using binomial distribution 
Can anyone help solving this question please? I tried but not sure of the steps to reach the conclusion.
 A: Let the probability of success on any trial be $p\gt 0$. Let $X$ be the number of trials until the first success. Then 
$$\Pr(X=n)=(1-p)^{n-1}p.$$
For brevity, let $q=1-p$.. .
We want $E(X)$, which is given by 
$$p +2qp+3q^2p +4q^3p+5q^4p+\cdots.\tag{1}$$
We need to evaluate this sum. There is a common factor of $p$. Recall the expansion of the function $\dfrac{1}{1-x}$. It is
$$\frac{1}{1-x}=1+x+x^2+x^3+\cdots$$
(for $|x|\lt 1$). Now comes the crucial trick, differentiate both sides. We get
$$\frac{1}{(1-x)^2}=1+2x+3x^2+4x^3+\cdots.\tag{2}$$
Putting $x=q$, and recalling that $q=1-p$, we get
$$\frac{1}{p^2}=1+2q+3q^2+4q^3+\cdots.$$
Comparing with (1), we get $E(X)=p\cdot \frac{1}{p^2}=\frac{1}{p}$.
Now go back to (2), and differentiate again. We get
$$\frac{2}{(1-x)^3}=(2)(1)+(3)(2)x+(4)(3)x^2+(5)(4)x^3+\cdots.\tag{3}$$
We now write down an expression for the expectation of $X(X-1)$, as suggested by the hint. It is
$$(2)(1)pq +(3)(2)q^2p+(4)(3)q^3p+(5)(4)q^4p+\cdots.\tag{4}$$
Compare (4) with (3). You will have to do a certain amount of manipulation to finish. 
