<s>[INST] Is there a simpler expression for this piecewise-defined function? As a math-for-fun exercise, I challenged myself to find a globally-defined, everywhere-differentiable antiderivative of $\sqrt{1-\sin(x)}$. Because of the fundamental theorem of calculus, the problem boils down to evaluating the integral
$$f(x)=\int_{-\frac{\pi}{2}}^{x}\sqrt{1-\sin(t)}\text{ }dt$$
After lots of thinking, many laborious calculations and a series of roadblocks, I arrived at this piecewise-defined expression:
$$f(x)=\begin{cases}
4\sqrt{2} \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor + 2\sqrt{1+\sin(x)} & \text{if } 2\pi \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor - \frac{\pi}{2}\leq x \leq 2\pi \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor + \frac{\pi}{2}\\
4\sqrt{2} \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor +4\sqrt{2} - 2\sqrt{1+\sin(x)} & \text{if } 2\pi \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor + \frac{\pi}{2}\leq x \leq 2\pi \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor + \frac{3\pi}{2}
\end{cases}$$
Using knowledge obtained during the solution process, I obtained the (perhaps) simpler expression
$$f(x)=\begin{cases}
4\sqrt{2} \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor + 2\sqrt{1+\sin(x)} & \text{if } \cos(x)\geq 0\\
4\sqrt{2} \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor +4\sqrt{2} - 2\sqrt{1+\sin(x)} & \text{if } \cos(x)\leq 0
\end{cases}$$
Naturally, I wondered whether this expression could be simplified further. Maybe there's a non-piecewise expression for $f(x)$? I originally thought about writing
$$4\sqrt{2}\left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor + 4\sqrt{2}=4\sqrt{2} \left( \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor +1 \right)=4\sqrt{2}\left \lceil \frac{x}{2\pi}+\frac{1}{4} \right \rceil$$
but quickly recognized that this is not valid when $\frac{x}{2\pi}+\frac{1}{4}$ is an integer. I also tried writing
$$f(x)=\begin{cases}
4\sqrt{2} \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor + 2\text{sgn}(\cos x)\sqrt{1+\sin(x)} & \text{if } \cos(x)\geq 0\\
4\sqrt{2} \left \lfloor \frac{x}{2\pi}+\frac{1}{4} \right \rfloor +4\sqrt{2} + 2\text{sgn}(\cos x)\sqrt{1+\sin(x)} & \text{if } \cos(x)\leq 0
\end{cases}$$
but this fails when $\cos(x)=0$. I don't have any other tricks up my sleeve. Could I get some assistance?
 [/INST] $$\sqrt{1-\sin x}=\sqrt{\cos^2\frac x2-2\cos\frac x2\sin\frac x2+\sin^2\frac x2}=\left|\cos\frac x2-\sin\frac x2\right|
\\=\sqrt2\left|\sin\left(\frac x2-\frac\pi4\right)\right|$$ and we can focus on the antiderivative of $|\sin t|=\pm\sin t$, where the sign alternates with period $\pi$.
For the antiderivative, we can take $-\cos(t\bmod\pi)$ with a jump of $2$ units at every $k\pi$, to compensate the discontinuity.
$$2\left\lfloor\frac t\pi\right\rfloor-\cos(t\bmod\pi)$$

Don't forget that $t=\dfrac x2-\dfrac\pi4$. If you want, you can emulate the modulo and the floor by elementary transformations of $\tan(\arctan(x))$.
</s>