Change of variable paradox Below is very normal steps of getting the area formula of circle using integration and change of varible.  But there seems to be a paradox.
Let $x=a\sin\theta$ and $dx=a\cos\theta{d\theta}$
$$\begin{align}{}
A &=4\int^a_0\sqrt{a^2-x^2}dx &(1)\\
  &=4\int^a_0\sqrt{a^2-a^2\sin^2\theta}dx &(2)\\
  &=4a\int^a_0\sqrt{1-\sin^2\theta}dx &(3)\\
  &=4a\int^a_0\cos\theta{dx} &(4)\\
  &=4a^2\int^{\pi/2}_0\cos^2\theta{d\theta} 
  \enspace\text{whereas }x=a\to\theta=\pi/2 \text{ and } x=0\to\theta=0       &(5)\\
  &=2a^2\int^{\pi/2}_01+\cos2\theta{d\theta} &(6)\\
  &=2a^2\Big[\theta+\frac{1}{2}\sin{2\theta}\Big]^{\pi/2}_0 &(7)\\
  &=\pi{a^2} &(8)
\end{align}$$
Now comes my questions: For step (5), it is also true that $x=0\to\theta=\pi$, if we substitue this to the lower limit, we get $$A=2a^2\Big[\theta+\frac{1}{2}\sin{2\theta}\Big]^{\pi/2}_\pi=-\pi{a^2}$$ this seems like a paradox, what went wrong?
Another paradox is that for the same step (5), it is also true that $x=a\to\theta=\frac{5\pi}{2}$, if we substitute this to the upper limit, we get$$A=2a^2\Big[\theta+\frac{1}{2}\sin{2\theta}\Big]^{{5\pi}/{2}}_0=5\pi{a^2}$$ This paradox is slightly different than the above paradox which might be explained by that the range of $x$ is $[-a,a]$ instead of$[0,a]$when $\theta$ is in $[0,(5\pi)/2]$. But I hope there is a more rigorous explanation for both paradoxes.
 A: You really need to track carefully what's going on with the substitution.
Say we have a substitution: $f(\theta)=x$, where $x\in [x_1, x_2], \theta\in [\theta_1, \theta_2]$, usually we need $f(\theta)$ to be increasing and $f(\theta_1)=x_1, f(\theta_2)=x_2$, and of course we need $f$ to be (continuously) differentiable over $[\theta_1, \theta_2]$. However, it's not strictly required that $x_1<x_2$ and $\theta_1<\theta_2$ hold and even when $f$ is not monotone, it's possible for the substitution to work, but one has to be careful.
For example, we may have $\theta$ from $\pi$ to $\pi/2$ to represent the process of $x$ varying from $0$ to $a$. However, you need to keep track of all the computations. As if so, we have $\sqrt{1-\sin^2(\theta)}=-\cos(\theta)\not=\cos(\theta)$! since $\cos(\theta)\le 0$. With the extra negative sign, the first "paradox" is resolved.
The second paradox suffered the same issue, as for certain values of $\theta$ in $[0, 5\pi/2]$, you picked the wrong square-root. If $\theta$ goes from $0$ to $5\pi/2$, then $f(\theta)=a\sin(\theta)$ doesn't simply go from $0$ to $a$, but winds around more than once, it actaully goes from $0$ to $a$, then $a$ to $0$, then $0$ to $a$, etc. This is no big deal, as there ought to be cancellation of integrals (the integral for $x$ from $0$ to $a$ should cancel the one from $a$ to $0$), but only when all the imtermediate steps are properly handled.
Anyway, it's not a good idea to do (definite) integrals for $f$ that is not monotone.
