What is the second derivative of the absolute function $\left|\frac{x+1}{x+2}\right|$? I calculated the derivative of $\left|\frac{x+1}{x+2}\right|$ in the same way that I would do with $ \frac{x+1}{x+2}$ in order to study the function.
But when I verified on wolfram, I noticed it is all wrong. Wolfram uses the chain rule as you can see here.
I don't get it. The only rule I've been taught as far as absolute function derivatives are concerned, is $|x|' = \frac{x}{|x|}$. Does a similar rule apply for $f(x)$? And why does wolfram uses chain rule?

Edit
I calculated the derivatives as there is no absolute and then, at the result, I applied the absolute.
My answers are $|(\frac{x+1}{x+2})|' = |(\frac{x+1}{x+2})'| = \frac{1}{\left(x+2\right)^2}$ and $|(\frac{x+1}{x+2})|'' = |(\frac{x+1}{x+2})''| = \frac{2}{\left(x+2\right)^3}$
Wolfram's answer is
$\left(\left|\frac{x+1}{x+2}\right|\right)'\:=\frac{\left|x+2\right|\left(x+1\right)}{\left|x+1\right|\left(x+2\right)^3}$

 A: This is how I deal with absolute functions:
$$
\begin{align}
\left|\frac{x+1}{x+2}\right|&=\sqrt{\left(\frac{x+1}{x+2}\right)^{2}}\\
\\
\frac{d}{dx} \left|\frac{x+1}{x+2}\right|&=\frac{d}{dx} \sqrt{\left(\frac{x+1}{x+2}\right)^{2}}\\
&=\frac{1}{2 \sqrt{\left(\frac{x+1}{x+2}\right)^{2}}}\cdot 2 \left(\frac{x+1}{x+2}\right)\cdot\frac{1}{\left(x+2\right)^{2}}\\
&=\frac{x+1}{\left(x+2\right)^{3}\cdot\left|\frac{x+1}{x+2}\right|}
\end{align}
$$
Notice the chain rule when I differentiate the square root
A: Hint:
As
$$\left|\frac{x+1}{x+2}\right|=\pm\frac{x+1}{x+2},$$
it is legitimate to take the derivative of the fraction without the absolute value.
Instead of an absolute value, you will use a piecewise definition where the sign is adjusted in every interval, and the derivatives naturally follow.
A: As an alternative, using sign function we have that for $x\neq -1,-2$
$$\left|\frac{x+1}{x+2}\right|=\frac{x+1}{x+2}\cdot \frac{\left|\frac{x+1}{x+2}\right|}{\frac{x+1}{x+2}}=\frac{x+1}{x+2} \operatorname{sign}\left(\frac{x+1}{x+2}\right)$$
therefore by chain rule, since $(\operatorname{sign}(x))'=0 $ for $x\neq 0$, we obtain
$$\frac d{dx}\left|\frac{x+1}{x+2}\right|=\left(\frac d{dx}\frac{x+1}{x+2}\right)\operatorname{sign}\left(\frac{x+1}{x+2}\right)=\frac1{(x+2)^2}\operatorname{sign}\left(\frac{x+1}{x+2}\right)=\frac{\left|\frac{x+1}{x+2}\right|}{(x+1)(x+2)}$$
which is an equivalent form for the derivative.
