Bug introduced in 5.2 or earlier and fixed in 12.2
According to the documentation Abs[z] gives the absolute value of the real or complex number z and is also known as the modulus. As far as I'm aware for any definition of the absolute value, norm or modulus the range of the function is supposed to be the positive real numbers but it seems that Mathematica's Abs function also returns negative numbers:
r = Root[ -1 - 9 # -15 #^2 + #^3&, 3, 1 ];
N[r]
(* 15.5817 *)
r > 0
(* True *)
N[Abs[r]]
(* -15.5817 *)
Abs[N[r]]
(* 15.5817 *)
I know that Simplify
, Reduce
and others show similar behaviour when working with powers of complex numbers, whose numerical value may change due multivaluedness of complex powers, but here I did not ask for a symbolic simplification and even if I did, there should be no change in numerical value since the Abs function is inherently single valued.
So I wondered whether this is a design choice or an actual bug and if it is a design choice, then how am I supposed to e.g. sort eigenvalues on magnitude and return a list positive magnitudes?
EDIT I have contacted the customer service but they get different results when running the same code. The full code I used is the following:
r = Abs @ Last @ SortBy[ Eigenvalues[{{0,1,0,0},{1,10,6,4},{0,6,4,3},{0,4,3,2}}], Abs @* N ];
N[r] < 0
(* True *)
r//InputForm
(* -Root[-1 - 9*#1 - 15*#1^2 + #1^3 & , 3, 1] *)
N[Abs[r]]
(* -15.5817 *)
The code that the person from the customer service ran is exactly the same but the output seems to be correct when he runs it.
The results I get have also been confirmed by someone using Mathematica 11.2.
Are there people who can confirm this behaviour?
N[RealAbs[r]] (*15.5817*)
$\endgroup$