To find the variance for a variable I know you're supposed to use:
$$Var(X)=E(X^2)-E^2(X)$$
When looking at the solutions to one of my class's problems I see $E(X)=p/(1-p)$.
They then go on to say that $E^2(x)=p^2/(1-p^2)$.
I'm confused because I thought $E^2(X)$ just meant to square $E(X)$, which would be
$$p/(1-p) * p/(1-p) = p^2/(1-2p+p^2)$$
Am I mistaken or is there a typo in the solution?
**Edit: Here's the full problem's solution, which is to compute the variance in the number of users in an M/M/1 system: https://i.stack.imgur.com/hLEzD.jpg
The variance is indeed the expectation of the squared variable minus the square of the expectation of the variable (see below why). This is denoted as
$$E(X^2)-(E(X))^2$$ or simply $$E(X^2)-E^2(X).$$
For a geometric distribution, we have
$$(1-p)\sum_{k=0}^\infty p^k=1$$ and differentiating on $p$ gives
$$-\sum_{k=0}^\infty p^k+(1-p)\sum_{k=0}^\infty kp^{k-1}=0$$ and from this
$$E(X)=\sum_{k=0}k(1-p)p^k=p\sum_{k=0}^\infty p^k=\frac p{1-p}.$$
Now,
$$\sum_{k=0}^\infty kp^k=\frac p{(1-p)^2}$$ and differentiating again,
$$E(X^2)=(1-p)p\sum_{k=0}^\infty k^2p^{k-1}=(1-p)p\frac{(1-p)^2+2p(1-p)}{(1-p)^4}=p\frac{1+p}{(1-p)^2}.$$
Finally,
$$\text{Var}(X)=p\frac{p+1}{(1-p)^2}-\frac{p^2}{(1-p)^2}=\frac p{(1-p)^2}.$$
By definition,
$$\text{Var}(X)=E((X-E(X))^2)=E(X^2-2XE(X)+E^2(X)).$$
By linearity of the expectation operator and the fact that the expectation of a constant is that constant, this equals
$$E(X^2)-2E(X)E(X)+E(E^2(X))=E(X^2)-2E^2(X)+E^2(X)=E(X^2)-E^2(X).$$
Alternatively, we have (notice the starting indexes)
$$S_k:=\sum_{k=1}^\infty kp^k=\sum_{k=1}^\infty (k-1)p^{k-1}$$
so that, from $k-(k-1)=1$,
$$(1-p)S_k=S_k-pS_k=\sum_{k=1}^\infty kp^k+\sum_{k=1}^\infty (k-1)p^k=\sum_{k=1}^\infty p^k=\frac p{1-p}$$ and $$S_k=\frac p{(1-p)^2},\\E(X)=\frac p{1-p}.$$
Similarly
$$T_k:=\sum_{k=1}^\infty k^2p^k=\sum_{k=1}^\infty (k-1)^2p^{k-1}$$
so that, with $k^2-(k-1)^2=2k-1$,
$$(1-p)T_k=T_k-pT_k=\sum_{k=1}^\infty k^2p^k+\sum_{k=1}^\infty (k-1)^2p^k=2\sum_{k=1}^\infty kp^k-\sum_{k=1}^\infty p^k=\frac{2p}{(1-p)^2}-\frac p{1-p}$$ and $$T_k=\frac{p^2+p}{(1-p)^3},\\E(X^2)=p\frac{p+1}{(1-p)^2}.$$