TITLE: Where is the absolute value when computing antiderivatives?
QUESTION [23 upvotes]: Here is a typical second-semester single-variable calculus question:
$$ \int \frac{1}{\sqrt{1-x^2}} \, dx $$
Students are probably taught to just memorize the result of this since the derivative of $\arcsin(x)$ is taught as a rule to memorize. However, if we were to actually try and find an antiderivative, we might let 
$$ x = \sin \theta \quad \implies \quad dx = \cos \theta \, d \theta $$
so the integral may be rewritten as
$$ \int \frac{\cos \theta}{\sqrt{1 - \sin^2 \theta}} \, d \theta  = \int \frac{\cos \theta}{\sqrt{\cos^2 \theta}} \, d \theta $$
At this point, students then simplify the denominator to just $\cos \theta$, which boils the integral down to 
$$ \int 1 \, d \theta = \theta + C = \arcsin x + C $$
which is the correct antiderivative. However, by definition, $\sqrt{x^2} = |x|$, implying that the integral above should really be simplified to 
$$ \int \frac{\cos \theta}{|\cos \theta|} \, d \theta = \int \pm 1 \, d \theta $$
depending on the interval for $\theta$. At this point, it looks like the answer that we will eventually arrive at is different from what we know the correct answer to be. 
Why is the first way correct even though we're not simplifying correctly, while the second way is... weird... while simplifying correctly?

REPLY [8 votes]: Let $\operatorname{sgn}(x)$ be the function that takes values $-1, 0, 1$ depending on the sign of $x$.
For the sake of generality, if you have two variables $x$ and $\theta$ related by $x = \sin \theta$ and the square root symbol means to always take the positive square root, then the opening post is correct: the right formula relating the differentials is
$$ \frac{\mathrm{d}x}{\sqrt{1 - x^2}} = \operatorname{sgn}(\cos(\theta)) \mathrm{d} \theta $$
Now, one thing to note is that the domain of these functions excludes $x = \pm 1$; similarly, it excludes all values of $\theta$ for which $\cos(\theta) = 0$.
On this domain, $\operatorname{sgn}(\cos(\theta))$ is locally constant. In this situation, the domain consists of a series of completely disjoint intervals $$\ldots \cup (-3\pi/2, -\pi/2) \cup (-\pi/2, \pi/2) \cup (\pi/2, 3\pi/2) \cup \ldots$$
"Locally constant" means any function that is constant on each of these intervals, but can have different values on different intervals.
Nearly everywhere in calculus where you learned something involving constants is actually about things that are locally constant
For example, since $\operatorname{sgn}(\cos(\theta))$ is locally constant, its antiderivatives are all of the form
$$ \operatorname{sgn}(\cos(\theta)) \theta + C(\theta) $$
where $C(\theta)$ is also locally constant. (note that we need a local constant of integration, not merely a constant of integration!)
Now, if we were so inclined, we can extend this formula to the domain of all $\theta$ by lining up all of the constants. The end result is that the antiderivative is a constant plus the sawtooth function depicted below:

Image produced by Wolfram alpha

As an example of seeing how this working, suppose our goal was to compute the integral
$$ \int_{-1}^1 \frac{\mathrm{d}x}{\sqrt{1 - x^2}} $$
While unusual, we can rewrite this as 
$$ \int_{-\pi/2}^{5\pi/2} \operatorname{sgn}(\cos(\theta)) \mathrm{d} \theta $$
This isn't an invertible substitution, since each value of $x$ corresponds to three different values of $\theta$ (barring a few exceptions). But one-dimensional integration is very robust, and we should still expect to get the right answer if we have the details right.
And we do; if we take the sawtooth function above as the antiderivative, then the integral becomes
$$ \left( \frac{\pi}{2} \right) - \left( -\frac{\pi}{2} \right) = \pi $$
which is the correct answer — and the same answer we'd get by only integrating over $(-\pi/2, \pi/2)$.

Of course, if we aren't interested in the greater generality, we can just simplify by insisting that $\theta \in [-\pi/2, \pi/2]$ and simply take $\theta + C$ as the antiderivative, thus avoiding any hassles with the sign.