$\sqrt{x^2}=|x|$ or $\sqrt{x^2}=x$ in an indefinite integral Question:
Find the following integral: $\int{\sqrt{1+\cos(x)}}dx$
My attempt:
$$\int{\sqrt{1+\cos(x)}}dx$$
$$=\int{\sqrt{2\cos^{2}\frac{x}{2}}}dx$$
$$=\int{\sqrt{2}\ \left|\cos\frac{x}{2}\right|}dx$$
$$=\sqrt{2}\int{\left|\cos\frac{x}{2}\right|}dx\tag4$$
$$=\sqrt{2}\int{\pm\cos\frac{x}{2}}dx$$
$$=\pm\sqrt{2}\int{\cos\frac{x}{2}}dx$$
$$=\pm2\sqrt{2}\sin\frac{x}{2}+C$$
My book's attempt:
$$\int{\sqrt{1+\cos(x)}}dx$$
$$=\int{\sqrt{2\cos^{2}\frac{x}{2}}}dx$$
$$=\int{\sqrt{2}\cos\frac{x}{2}}dx$$
$$=\sqrt{2}\int{\cos\frac{x}{2}}dx$$
$$=2\sqrt{2}\sin\frac{x}{2}+C$$
Basically, my book didn't put $\pm$ sign, while I did. My book did this essentially: $\sqrt{x^2}=x$, while I did this: $\sqrt{x^2}=|x|$. Is my process more correct?
 A: *

*$\displaystyle\pm\cos\frac{x}{2}$ is actually less descriptive
than
$\displaystyle\left|\cos\frac{x}{2}\right|.$

*$$\int_0^{2\pi}{\left|\cos\frac{x}{2}\right|}\,\mathrm
dx = 4,$$ but $$\pm\int_0^{2\pi}{\cos\frac{x}{2}}\,\mathrm dx=0= \int_0^{2\pi}{\cos\frac{x}{2}}\,\mathrm dx.$$
The correct way to continue from line $(4)$ is to split up the integral such that each of the integrand's $x$-intercepts is a limit of integration.
A: Your solution goes further than the book's solution in terms of correctness. You have two issues. The first is that changing $\left|\cos\frac{x}{2}\right|$ to $\pm\cos\frac{x}{2}$ only creates a loss of information. Moreover, the $\pm$ sign itself depends on that value of $\cos\frac{x}{2}$, so it makes no sense to pull out the $\pm$ sign here, even if you did have it.
Integrating over absolute value signs is tricky. I'll use the definite integral to give an answer to the indefinite integral.
$$ \sqrt{2}\int{\left|\cos\frac{x}{2}\right|}dx = \sqrt{2}\int_{0}^{x}{\left|\cos\frac{u}{2}\right|}du + C $$
In the case of a definite integral, you have to split your domain into intervals on a case by case basis.
Case 1: $x>\pi$.
In this case, we have
\begin{align}
\sqrt{2}\int_{0}^{x}{\left|\cos\frac{u}{2}\right|}du + C &= \sqrt{2}\int_{0}^{\pi} \left|\cos\frac{u}{2}\right| du \\
& \quad+ \left( \sqrt{2}\int_{\pi}^{\pi+2\pi} \left|\cos\frac{u}{2}\right| du + \cdots + \sqrt{2}\int_{\pi+(n-1)2\pi}^{\pi+n2\pi} \left|\cos\frac{u}{2}\right| du \right) \\
& \quad+ \sqrt{2}\int_{\pi+n2\pi}^{x} \left|\cos\frac{u}{2}\right| du + C \qquad\qquad 
\end{align}
where $n = \left\lfloor \dfrac{x-\pi}{2\pi}\right\rfloor$.
We look at the various definite integrals separately. First, note that $\cos\frac{u}{2}$ is nonnegative for all $u\in (0, \pi)$. This means we have $\left|\cos\frac{u}{2}\right| = \cos\frac{u}{2}$ on that interval. Hence
$$ \sqrt{2}\int_{0}^{\pi} \left|\cos\frac{u}{2}\right| du = \sqrt{2}\int_{0}^{\pi} \cos\frac{u}{2} du = 2\sqrt{2}. $$
Next, using periodicity of cosine, we can deduce that
$$ \sqrt{2}\int_{\pi+(k-1)2\pi}^{\pi+k2\pi} \left|\cos\frac{u}{2}\right| du = \sqrt{2}\int_{-\pi}^{\pi} \cos\frac{u}{2} du = 4\sqrt{2} $$
for each integer $k$.
Lastly, we need to do the last integral, which is going to give us a function of $x$. Again, using properties of cosine, we can deduce that
\begin{align}
\sqrt{2}\int_{\pi+n2\pi}^{x} \left|\cos\frac{u}{2}\right| du &=  \sqrt{2}\int_{-\pi}^{x - 2(n+1)\pi} \cos\frac{u}{2} du = \sqrt{2}\cdot 
2\sin\left(\frac{u}{2}\right) \Big|_{-\pi}^{x-(n+1)2\pi} \\
&= 2\sqrt{2} \left[ \sin\left(\frac{x-(n+1)2\pi}{2}\right) - \sin\left(-\frac{\pi}{2}\right) \right] \\
&= 2\sqrt{2} \left[ \sin\left(\frac{x}{2}-(n+1)\pi\right) - (-1) \right] \\
&= 2\sqrt{2} \left[ \sin\left(\frac{x}{2}\right)\cos(-(n+1)\pi) + \sin(-(n+1)\pi)\cos\left(\frac{x}{2}\right) + 1 \right] \\
&= 2\sqrt{2} \left[ \sin\left(\frac{x}{2}\right)(-1)^{n+1} + 0 + 1 \right] \\
&= 2\sqrt{2} \left[ 1 + (-1)^{n+1}\sin\left(\frac{x}{2}\right) \right]
\end{align}
Going all the way back to the beginning of Case 1, and putting this all together, we have
\begin{align}
\sqrt{2}\int_{0}^{x}{\left|\cos\frac{u}{2}\right|}du + C &= 2\sqrt{2} + \underbrace{(4\sqrt{2} + \cdots + 4\sqrt{2})}_{n\text{ terms}} + 2\sqrt{2}[1 + (-1)^{n+1}\sin\left(\frac{x}{2}\right)] + C \\[1.2ex]
&= 2\sqrt{2} + n(4\sqrt{2}) + 2\sqrt{2} + 2\sqrt{2}(-1)^{n+1}\sin\left(\frac{x}{2}\right) + C \\[1.6ex]
&= (n+1)\cdot 4\sqrt{2} + 2\sqrt{2}(-1)^{n+1}\sin\left(\frac{x}{2}\right) + C
\end{align}
Thus, for $x > \pi$ we have
$$ \sqrt{2}\int{\left|\cos\frac{x}{2}\right|}dx = 4\sqrt{2}(n+1) + 2\sqrt{2}(-1)^{n+1}\sin\left(\frac{x}{2}\right) + C $$
where $n = \left\lfloor \dfrac{x-\pi}{2\pi}\right\rfloor$.
The solution might look weird, but when I graph it in desmos for $C=0$ I get a continuous function.
Cases for $0\le x\le \pi$, $-\pi\le x<0$, and $x<-\pi$ are similar. I'll leave these other cases to you :)
The reason why we have all these cases and the reason why we need to split our definite integral over various intervals is because the absolute value function is actually a piecewise function that is itself handled by cases.
A: Before a radical sign imho...
the non inclusion of $\pm$ in the last step is a convention. It is assumed that it is understood by implication , so not so necessary even to mention.
This practice is annoying when integral evaluations are done..
Omission of sign in differential equation is a misleading step that needs to be altogether avoided.
Your procedure is more correct.If you graph them they are seen as reflections on either side of x-axis, each in its own right, so to say.
A: Note that $\sqrt{t^2}=\text{sgn}(t)\cdot t$. Then, piecewise integrate
\begin{align}
\int\sqrt{1+\cos x}\>dx=
&\>\sqrt2\int\sqrt{\cos^2\frac x2}\>dx
=\>\sqrt2 \>\text{sgn}(\cos \frac x2)\int\cos \frac x2 \>dx\\
= &\>2\frac{ \sqrt{2\cos^2\frac x2}}{\cos \frac x2}\sin \frac x2 
=\>2\sqrt{1+\cos x}\>\tan \frac x2 
\end{align}
A global ante-derivative can be concatenated as
$$ \int\sqrt{1+\cos x}\>dx= 2\sqrt{1+\cos x}\>\tan \frac x2 +4\sqrt2\lfloor \frac {x+\pi}{2\pi}\rfloor
$$
