Given that the Maclaurin series for $g(x) = \frac{1}{1+x}$ is $1 - x + x^2 - x^3 + x^4 ... $, I'm told that the Maclaurin series for $\frac{1}{1+x^2}$ is $1 - x^2 + x^4 - x^6 ... $, by substituting in $x^2$.
What I'm confused about is why this is valid for this case specifically and what rules govern when you can and can't do something like this -- for example, you couldn't do it with the series for $x$ itself and substitute in, say, $cos(x) = x$, right?