15
$\begingroup$

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?

$\endgroup$
13
  • 3
    $\begingroup$ Look what Abs[r] returns. Please make a report to [email protected] $\endgroup$ Commented Oct 17, 2020 at 17:18
  • 5
    $\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
    Commented Oct 17, 2020 at 21:53
  • 1
    $\begingroup$ @Carl the Root expression was the output of Eigenvalues[mat]. Since there's no problem with the eigenvalues function I left that part out. $\endgroup$
    – Gert
    Commented Oct 18, 2020 at 7:13
  • 1
    $\begingroup$ Workaround N[RealAbs[r]] (*15.5817*) $\endgroup$ Commented Oct 18, 2020 at 8:55
  • 1
    $\begingroup$ This has been internally reported as a bug, and bug tagging would be appropriate. $\endgroup$
    – Carl Woll
    Commented Oct 28, 2020 at 19:44

1 Answer 1

15
$\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 and acknowledge you have read our privacy policy.

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