2

I was looking at my calculator and saw the abs() function to which I thought, this function is fairly unnecessary. So I suppose my question is: is abs(x) different from sqrt(x^2) in some way? If they are not different, why is it so common to see abs(x) function on calculators and in programming languages etc.?

Thanks!

Arnaldo
  • 21,342
Curtis
  • 133
  • How is it unnecessary? Why square and then root if you can just abs (x) instead? – Karl Mar 23 '17 at 18:54
  • 1
    In programming it's way easier to return $x$ or $-x$ rather then squaring and square rooting which might even be impossible for big numbers,also you could lose precision.Other then that it's convenient to have a separate notation for abs(x) – kingW3 Mar 23 '17 at 18:54
  • @kingW3 Thanks! I did not think about squaring large numbers! – Curtis Mar 23 '17 at 18:58
  • In any case, it's easier. Or do you propose removing the ² and ³-buttons too, since you can also do e.g. $x \times x \times x$...? :-) – StackTD Mar 23 '17 at 18:59
  • Why make things simple when it's so simple to make them complex? Why write 3: it could be written ${\varnothing,{\varnothing},{\varnothing,{\varnothing}}}$? – Bernard Mar 23 '17 at 19:04
  • @StackTD My point was that I and many that I know do not use the function very frequently, so it seemed like a waste of space (to me). – Curtis Mar 23 '17 at 19:06
  • @Bernard see my comment to StackTD – Curtis Mar 23 '17 at 19:07

3 Answers3

3

If $x$ is complex, then $|x|$ denotes the norm of $x$. This coincides with the usual absolute value if $x$ happens to be real. However, $\sqrt{x^2}$ differs from $|x|$ for most complex $x$ -- the former is a complex number, while the latter is always real and nonnegative.

vadim123
  • 82,796
  • 1
    I think this is a little confusing because the notation for norm in some texts is double bars, specifically to differentiate it from absolute value – qwr Mar 23 '17 at 18:59
  • The vertical bar is the most over-used symbol in mathematics. – vadim123 Mar 23 '17 at 19:01
  • This is a good point too, forgot about negative imaginary numbers. Thank you! – Curtis Mar 23 '17 at 19:08
2

First, abs() just removes the sign from the number, which is computationally a LOT less expensive than squaring and the extracting the square root. Second, extracting square roots causes round off error.

  • Very good point, I was thinking primarily in terms of calculator "real-estate". This makes it a much more valuable function. – Curtis Mar 23 '17 at 19:01
2

Generality

"Absolute value", abs(x), |x| can be always seen as an interpretation of distance - values on number line, points in space... The idea of distance makes sense in places where powers and roots do not - graphs, sets, etc. Mathematicians tend to prefer more general and abstract concepts over restricted ones.