Similarly to this question I have a question about the problem:
"Let a and b be positive integers with $a \leq b$, and let $X$ be a random variable that takes as values, with equal probability, the powers of $2$ in the interval $[2^a, 2^b]$. Find the expected value and the variance of X."
I'm aware that $$\mathbb{E}[X] = \sum_{k=a}^{b} \frac{1}{b - a + 1} 2^k = \frac{2^{b+1} - 2^a}{b - a + 1}$$ and I also derived it for myself.
But from the master solution, I don't understand how the second moment $\mathbb{E}[X^2]$ is derived:
$$ \mathbb{E}[X^2] = \sum_{k=a}^{b} \frac{1}{b - a + 1} (2^k)^2 = \frac{4^{b+1} - 4^a}{3(b - a + 1)}$$
Specifically: why do we need to multiply the denominator with 3 instead of just dividing by their differences $b - a + 1$ once? Since we're only squaring the random variable $X$ and there are no terms that rely on the index $k$ in the fraction, we should basically be able to move it out of the sum and just multiply the whole sum with $\frac{1}{b - a + 1}$, i.e: $$ \frac{1}{b - a + 1} \sum_{k=a}^{b}(2^k)^2 $$
So I was hoping someone could enlighten me on where that multiplicative factor comes from!
Recalling the identity $$1+x+x^2+\cdots+x^n=\frac{x^{n+1}-1}{x-1}$$ and noting that $(2^k)^2=4^k$, we get \begin{align*} &\sum_{k=a}^{b}(2^k)^2\\[4pt] =\;&\sum_{k=a}^{b}4^k\\[4pt] =\;&4^a\sum_{k=0}^{b-a}4^k\\[4pt] =\;&4^a\left(\frac{4^{b-a+1}-1}{4-1}\right)\\[4pt] =\;&\frac{4^{b+1}-4^a}{3}\\[4pt] \end{align*}