While self studying analytic number theory from Tom M Apostol I could not think about how Apostol deduces this argument.
Image ( the part in which I have doubt is highlighted) -


I am unable to think how Apostol changes index from m to n. I am having a problem in understanding it as index that has n only has $x^{2n} $ while on LHS $ x^m $ ( both of these are raised to power 2) , so in RHS only even powers are summed.
Edit 1 - I have another doubt in the same theorem. I am adding image ( with doubt highlighted)

I have doubt that how does (1- $x^{4n}$) = (1-$x^{8n}$) (1-$x^{8n-4} $) ?
Can anybody please explain!!
The powers of $i$ repeat between $i,-1,-i,1$. In particular the terms when $m$ is $1\mod 4$ cancel out the terms when $m$ is $-1\mod 4$ (the former give $i^m=i$ and the latter give $i^m=-i$). Leaving out those terms that cancel gives us $$ \sum_{m\in\mathbb Z}x^{m^2}i^m=\sum_{m\in 2\mathbb Z}x^{m^2}i^m, $$ where I write $2\mathbb Z$ for the even integers. Now let $m=2n$, so we find that $$ \sum_{m\in 2\mathbb Z}x^{m^2}i^m=\sum_{n\in \mathbb Z}x^{(2n)^2}i^{2n}=\sum_{n\in \mathbb Z}x^{(2n)^2}(-1)^{n}, $$ since $i^2=-1$.