Is it always allowed to substitute the absolute value of a function by the square root of the squared function? I am in the middle of a proof. I want to know am I allowed to substitute $ \left| \frac{\cos \left(3 x^2\right)}{x \tan (x+1)}\right|$ by $\sqrt{\left(\frac{\cos \left(3 x^2\right)}{x \tan (x+1)}\right)^2}$? (for real $x$)
I mean is it always allowed to substitute the absolute value of a function by the square root of the squared function?
 A: Just to be pendantic.
The absolute value is defined to be $|z| = \sqrt{z\cdot \overline z}$ where $\overline z$ is defined to be $\overline z = Re(z) - Im(z)i$ for a complex number.  And $z\overline z = Re^2(z) + Im^2(z)$ is a non-negatove real number, then $\sqrt{W}$ where $W$ is real and $W \ge 0$ is defined to be the unique positive real $m$ so that $m^2 = W$.
If $x$ is a real number then $x = Re(x)$ and $Im(x) = 0$ and $\overline x = Re(x) - Im(x) i = Re(x) = x$.
So by definition we have $|x| =\sqrt{x^2}$, by definition, for all real numbers.
However as  "the unique positive number $m$ so that $m^2 = x^2$" is $m$ itself if $m \ge 0$ or $-m$ if $m < 0$ we derive the "usual" definition.
$|x|=\begin{cases} x& x\ge 0\\ -x& x< 0\end{cases}$.
.....
Of course, (in the literally sense of being a matter of course, and not the more common sense of being obvious as this is nothing of the sort), although this is the way mathematics is defined today, it is almost certainly reversed engineered,  I strongly suspect we had the concept of absolute value as "how big something is in purely positive real magnitude" long before we worked out a consistent definition.
......
Or we could solve it.
$(-x)^2 = x^2$ and $x^2 = x^2$.  If $x \ge 0$ the non-negative $m$ so that $m^2 = x^2$ is $m=x$ and  $\sqrt{x^2} = x=|x|$.  If $x < 0$ then $-x > 0$ and the non-negative $m$ so that $m^2 =x^2$ is $m=-x=|x|$.
So yes, it is always true that $|x| = \sqrt {x^2}$ for all real numbers $x$.
A: So long as we are in the realm of real numbers - this is fine yes. However - if we are in the realm of complex numbers, this is not true in general
A: Yes that's correct indeed by definition for any $x\in\mathbb R$
$$|x|=\sqrt{x^2}=\cases{\begin{align}x\quad \text{for} \quad x\ge 0\\-x\quad \text{for} \quad x< 0\end{align}}$$
