Why do we take $\sqrt{f^2(x)} = f(x)$ when integrating by substitution? I've posted a similar question Confusion in finding derivative of $\sqrt{\frac{1-\cos(2x)}{1 + \cos(2x)}}$.

Consider the following integral: $$\int\sqrt{1 - x^2}\ dx.$$
Putting $x = \sin(\theta):$
$$=\int\sqrt{1 - \sin^2\theta}\ \cos\theta\ d\theta$$
$$=\int\sqrt{\cos^2\theta}\ \cos\theta\ d\theta\tag{1}$$
$$=\int\ \cos\theta\cos\theta\ d\theta\tag{2}$$
$$=\int\cos^2\theta\ d\theta$$
$$...$$
$$...$$
$$...$$

From step $(1)$ to $(2)$, I don't understand why we take $\sqrt{f^2(x)} = f(x)$ instead of $\sqrt{f^2(x)} =|f(x)|.$ I've seen many such examples like the above, where we ignore the negative values (mainly in substitutions in integration, differentiation, and inverse trigonometric functions).
 A: 
$$\int\sqrt{1 - x^2}\,\mathrm dx.$$
Putting $x = \sin(\theta):$
\begin{align}&\implies\int\sqrt{\cos^2\theta}\ \cos\theta\,\mathrm d\theta\tag{1}\\
&\implies\int\ \cos\theta\cos\theta\,\mathrm d\theta\tag{2}\\
&\implies\int\cos^2\theta\,\mathrm  d\theta\end{align}
why we take $\sqrt{f^2(x)} = f(x)$ instead of $\sqrt{f^2(x)} =|f(x)|.$


*

*The above is an implicit
substitution of the
form $x=h(\theta),$ which
requires $h$ to be
invertible.
The author has tacitly restricted $\sin\theta$ to its principal
domain so that $h$ has domain $$\left[-\frac\pi2,\frac\pi2\right].$$
Thus, $\cos\theta\ge0;$ so, $\sqrt{\cos^2\theta}=|\cos\theta|$
simply equals $\cos\theta.$


*A nitpick: the implication symbol $\implies$ connects statements
like $x^2+3x=7,$ and is not interchangeable with the symbol $=,$
which connects expressions like $x^2+3x.$


*As a contrast, this solution opts for the alternative substitution
$\displaystyle
x=\sin\alpha\quad\left(\alpha\in\left[\frac\pi2,\frac{3\pi}2\right]\right):$
\begin{align}&\int\sqrt{1 - x^2}\, \mathrm dx\\
\\={}&\int\sqrt{\cos^2\alpha}\ \cos\alpha\, \mathrm d\alpha\\
\\= {}&\int\ (-\cos\alpha)\cos\alpha\, \mathrm d\alpha\\
\\= {}&\int(-\cos^2\alpha)\, \mathrm d\alpha.\end{align} It nonetheless gives the same answer (the negative sign appears as this substitution function is decreasing, which flips the integration limits relative to the previous substitution): \begin{align}&\int_{-1}^{1}\sqrt{1 - x^2}\, \mathrm dx
\\= {}&\int_{\color{red}{3\pi/2}}^{\color{red}{\pi/2}}(\color{red}-\cos^2\ \color{red}{ \alpha})\, \mathrm d \color{red}{\alpha}
\\= {}&\int_{\pi/2}^{3\pi/2}\cos^2\alpha\, \mathrm d\alpha \\= {}&\int_{\pi/2}^{3\pi/2}\cos^2\theta\, \mathrm d\theta.\end{align}

