$\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?

*

*$\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.
