A clever reformulation of the absolute value Is there a nice algebraic, non-piecewise definition for the absolute value of a number/function? For example, 
$$\max(a,b) = \frac{a + b + |b - a|}{2}$$
is a horribly useless computation to go through for a human, but max in one line of code is quite aesthetic.
 A: For real numbers, a neat little definition for the absolute value of any number $n$ is: $$\left\vert x\right\vert = \sqrt{x^2}$$ This is because without the sign, the square root notation computes the positive square root of a number. Remember that $x \in \mathbb{R}$ for this to work. 
The definition for the absolute value can be extended to complex numbers. Wikipedia says,

The absolute value of a complex number is defined as its distance in the complex plane from the origin using the Pythagorean Theorem.

In this case, for a complex number $z = a + bi$, $\left\vert z \right\vert$ is computed by $$\left\vert z \right\vert = \sqrt{(\operatorname{Re}(z))^2 + (\operatorname{Im}(z))^2} = \sqrt{x^2 + y^2}$$ where $\operatorname{Re}(z)$ is $x$ and $\operatorname{Im}(z)$ is $y$. These represent the real and imaginary parts of $z$ respectively. There are many other ways to rewrite the absolutve value of a complex number depending on what form it is written in. This is because the set of complex numbers are not ordered, so there is no direct generalization of the definition of the absolute value function. 
There are other generalizations for the absolute value, especially in abstract algebra, where you can generalize such for ordered rings, fields, vectors, etc. So, the definition of the absolute value depends on what set it belongs to.
Sources:


*

*Absolute value - Wikipedia
