Where is the flaw in evaluating the following integral?

I was trying to evaluate a complicated integral by substitution and along the way I got stuck in nonsensical answer. Surprisingly enough the point I wanted to discuss can be demonstrated using the following primitive integral:

$\displaystyle\int_0^\pi \sin\theta d\theta=-\cos\theta|_0^\pi=-\cos\pi+\cos 0=1+1=2$

Now Imagine we are trying to do the same integral in another way, by substitution.

If we take $\sin\theta\equiv y$ then the limits of the integral will change accordingly from $0$ to $\pi$ to from $0$ to $0$, which will kill the integral instantly and give us $0$!

So either there is a flaw in my solution that I cannot find, or that there are conditions under which one can (or cannot) use integration by substitution that I am not aware of (at least I have never seen it in college level calculus).


Solution 1:

Integration by substitution tells us that $$\int_a^b f(g(\theta))g'(\theta)\, d\theta = \int_{g(a)}^{g(b)} f(y)\, dy$$ where $g:[a,b] \to g([a,b])$ is continuously differentiable and $f:g([a,b]) \to \mathbb{R}$ is continuous.

Now, between $0$ and $\frac{\pi}{2}$, if we set $y=g(\theta)=\sin \theta$ then $g'(\theta)=\cos \theta = \sqrt{1-y^2}$. But between $\frac{\pi}{2}$ and $\pi$ it is in fact the case that $\cos \theta = -\sqrt{1-y^2}$. So in the above expression we must have $$ f(y) = \begin{cases} \frac{y}{\sqrt{1-y^2}} & \text{if } 0 \le \theta \le \frac{\pi}{2} \\ -\frac{y}{\sqrt{1-y^2}} & \text{if } \frac{\pi}{2} \le \theta \le \pi \end{cases}$$

And so the integral actually transforms, by integration by substitution, to

$$\int_0^1 \frac{y}{\sqrt{1-y^2}}\, dy + \int_1^0 \frac{-y}{\sqrt{1-y^2}}\, dy$$

which can readily be seen to evaluate to $2$.