Sorry if this question has been asked before. I'm not sure how to phrase this question properly (hence I couldn't find any fruitful results on Google).
We know that the following holds true for $|x| < 1$,
$$ \frac{1}{1-x} = \sum_{i=0}^\infty x^i = 1 + x + x^2 + \ldots $$
If we substitute $x^2$ as the variable into both sides of the equation, we obtain:
$$ \frac{1}{1-x^2} = \sum_{i=0}^\infty x^i = 1 + x^2 + x^4 + \ldots $$
which is also true.
However, if we try the same with integration, we will get a different outcome.
The following holds true by basic law of integration:
$$ \int x dx = \frac{x^2}{2} + C $$ where C is an arbitrary constant.
If we substitute $x^2$ as the variable into both sides of the equation, we obtain:
$$ \int x^2 dx = \frac{x^4}{2} + C $$
which is clearly wrong.
My question is, $ x $ is meant to be an arbitrary input for a function. Hence, (I think) we could substitute $ x $ with anything and simply plug the new variable into the output as well. Although this is evidently false in the integration example, it works for the example using geometric series. Why does this claim hold true sometimes and fail in other situations (just like in the 2 examples given above)?