<s>[INST] How to calculate $\mathbb{E}(X^2)$ when $X \sim Geo(\frac{1}{2})$ I am reading Mark Joshi's "Quant Job Interview Questions And Answers" question 3.7, and I am having trouble understanding how he proved that $\mathbb{E}(X^2)$ of $X \sim Geo(\frac{1}{2})$ is 6.
Here is his original question:
QUESTION 3.6. Suppose we toss a fair coin, and let N denote the number of tosses until we get a head (including the final toss). What is $\mathbb{E}(N)$ and $Var(N)$?
Here is his proof:

In particular, he says "applying the same technique (twice) gives $\mathbb{E}(X^2) = \frac{2 - 0.5}{0.5^2} = 6$". How did that work? How does applying the same technique twice gives this answer?
 [/INST] Applying the trick once gives:
\begin{align*}
E(X^2) &= 0.5^1+2^2\times0.5^2 + 3^2\times0.5^3+\dots\\
\implies 0.5E(X^2) &= 0.5^2+2^2\times0.5^3 + 3^2\times0.5^4+\dots\\
\implies 0.5E(X^2) &= 0.5^1 +(2^2-1)\times0.5^2 + (3^2-2^2)\times0.5^3+\dots
\end{align*}
But $k^2-(k-1)^2$ simplifies to $2k-1$, so we can rewrite this as
$$0.5E(X^2) = 0.5^1 +(2\times2 - 1)\times0.5^2 + (2\times3 - 1)\times0.5^3+\dots$$
Doing the trick again:
\begin{align*}
0.5E(X^2) &= 0.5^1 +(2\times2 - 1)\times0.5^2 + (2\times3 - 1)\times0.5^3+\dots\\
\implies 0.25E(X^2) &= 0.5^2 +(2\times2 - 1)\times0.5^3 + (2\times3 - 1)\times0.5^4+\dots\\
\implies 0.25E(X^2) &= 0.5 +2\times0.5^2 + 2\times0.5^3+ 2\times 0.5^4\dots\\
\end{align*}
i.e.
\begin{align*}
0.25E(X^2) + 0.5 &= 2\times 0.5 + 2\times0.5^2 + 2\times0.5^3+ 2\times 0.5^4\dots\\
&= 2.
\end{align*}
</s>