<s>[INST] 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}$

 [/INST] 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.
</s>