TITLE: How to calculate $ \left| \sin x \right| $ derivative in a more elegant way?
QUESTION [7 upvotes]: I am trying to calculate the derivative of $\left| \sin x \right| $
Given the graphs, we notice that the derivative of $\left| \sin x \right|$ does not exist for $x= k\pi$.
Graph for $\left|\sin x\right|$:

We can rewrite the function as
$\left| \sin(x) \right| =  \left\{
\begin{array}{ll}
      \sin(x),& 2k\pi < x < (2k+1)\pi \\
      -\sin(x), & \text{elsewhere} \\
\end{array} 
\right.  $
Therefore calculate its derivative as:
$(\left| \sin(x) \right|)^{'} =  \left\{
\begin{array}{ll}
      \cos(x),& 2k\pi < x < (2k+1)\pi \\
      -\cos(x), & \text{elsewhere} \\
\end{array} 
\right.  $
Is there a way to rewrite this derivative, in a more elegant way (as a non-branch function) $(\left| \sin(x) \right|)^{'} = g(x)$?

REPLY [4 votes]: Apparently other answers missed the following direct approach: we have $$|x|' = \frac{x}{|x|}$$ for $x\ne 0$.
So, for example, VIVID's formula $|f(x)|' = \frac{f(x)}{|f(x)|} f'(x)$ is just the chain rule.