14
$\begingroup$

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?

$\endgroup$
13
  • $\begingroup$ This is bug. Interesting is that N[Abs[ToRadicals[r]]] is correct. $\endgroup$ – Vaclav Kotesovec Oct 17 '20 at 16:53
  • $\begingroup$ "how am I supposed to e.g. sort eigenvalues on magnitude". Use SortBy[list, Abs[N[#]] &] or SortBy[list, Abs[N[#, prec]] &] for arbitrary precision. $\endgroup$ – Bob Hanlon Oct 17 '20 at 17:17
  • 3
    $\begingroup$ Look what Abs[r] returns. Please make a report to support@wolfram.com $\endgroup$ – Daniel Huber Oct 17 '20 at 17:18
  • 4
    $\begingroup$ Why are you using 3 arguments for the Root object? The third argument shouldn't be used, it should be set by Mathematica when the 2 argument Root object is evaluated. $\endgroup$ – Carl Woll Oct 17 '20 at 21:53
  • 1
    $\begingroup$ Workaround N[RealAbs[r]] (*15.5817*) $\endgroup$ – Ulrich Neumann Oct 18 '20 at 8:55
13
$\begingroup$

It is a bug that will be fixed in the nearest release of Mathematica. It affects Abs/Sign of positive Root objects with third argument 1, for which the real root isolation algorithm produces an isolating interval with the left end point 0.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.