# Why define $|x|$ by a piecewise function?

So I was recently solving a question about the derivative of $|\sin(x)|$ and the answer above me used a piecewise function to solve the problem.

I used the definition $|x|=\sqrt{x^2}$, and the problem became incredibly easy to solve. So, I guess what I am wondering, is why people define $|x|$ by a piecewise function like:

$|x|= \begin{cases} x , & \text{if } x \geq 0\\ -x, & \text{otherwise} \end{cases}$

Because it is harder to differentiate and the only possible application is integration. Plus, my definition is easier to prove:

Proof:

The absolute value of a real number is defined as the magnitude of the real number.

The magnitude of a complex number $a+bi$ is $\sqrt{a^2+b^2}$, and if $b$ is $0$ because the number is real, then $|a|=\sqrt{a^2}$.

So, in conclusion, I want to know how this piecewise definition came about, and why I never see my definition. If possible, I would like to know the flaws with my definition.

• It is actually rather common to define $\vert x\vert$ as $\sqrt{x^2}$. Even without that definition one can easily find, using the limit definition of derivative, that the derivative of $\vert x\vert$ is $\frac{x}{\vert x\vert}=\frac{\vert x\vert}{x}$ and then use the chain rule when finding the derivative of $\vert f(x)\vert$. – John Wayland Bales Apr 13 '17 at 3:34
• It's as simple as the fact that the definition ought to be the most straightforward mathematical expression possible. Often definitions aren't mathematically convenient, that is why so many identities exist in the world of math. The identity you've given here is VERY common. In fact, a simple search on Wikipedia puts it as the second equation under the "Definition and properties" section. At the end of the day, both are equivalent, but one is a more sensible definition. – David Apr 13 '17 at 3:54
• Actually the first definition I ever saw was $|x|=\max(x,-x)$. – A. Bellmunt Sep 14 '18 at 15:16

I'm not sure if there is a good answer to this question. Both definitions have their merits. Your definition is just a special case of the definition of the standard metric on $\mathbf{R}^n$. Namely, $$d_E(x,y)=\sqrt{\sum_{i=1}^n(x^i-y^i)^2}$$ where $x=(x^1,\ldots, x^n)$ and $y=(y^1,\ldots y^n)$. In this case, $\lvert x\rvert$ is simply the Euclidean distance of $x$ from the origin in $\mathbf{R}$. That is, $$\lvert x\rvert=\sqrt{x^2}.$$ On the other hand, sometimes it is nice to regard $\lvert x\rvert$ as two lines. That is, $$\lvert x\rvert=\begin{cases} x&x\ge 0\\ -x&x<0. \end{cases}$$ In the latter case, we just know that we can pretend $\lvert x\rvert$ is either $x$ or $-x$ depending on which side of the origin we are on. In short, both of these definitions are fundamental and equally valid.
The definition for $|x|$ is naturally stated in terms of diferent conditions, depending whether $x \geq 0$ or $x<0$ because $|x|$ is distance from $0$ to $x$ and we agree that distance is always $\geq 0$.
The definition $|x|=\sqrt {x^2}$ is also fine because when we talk about square root we agree that square root of nonnegative real number is nonnegative itself so $\sqrt {x^2}$ is never a negative number and it equals $|x|$ because of $(-x)^2=x^2$.