# A key part in the expectation of geometric distribution

I'm learning the proof of the expectation for a geometric random variable. The proof is as follows:

I just cannot understand the parts where I place two red boxes.

Why can we use differentiation here to get $$\sum_{k=1}^{\infty }k(1-p)^{k-1}$$?

Is there any theorem which I can follow?

• The first red box: They got $p$ out of the sum because $p$ is not indexed in the sum. It does not change the value of the sum whether you include it or not. For the second red box: If you notice, $k(1 - p)^{k - 1}$ is the derivative of $(1 - p)^k$ which is a geometric sequence. – Zouhair El Yaagoubi Oct 21 '18 at 17:20
• @ZouhairElYaagoubi thanks, I have understood about it. – Crisp Oct 21 '18 at 19:00

\begin{align*} E(X) = \begin{cases} \sum_{x} x \, p_X(x) & X \text{ is a discrete RV}\\ \int_{-\infty}^{\infty} x \, f_X(x)\, dx & X \text{ is a continuous RV} \end{cases}, \end{align*}