8
$\begingroup$

If I run the command

  ResourceFunction[ "GlobalMaxima"][{x*y + 2*y*z + 6*x, x^2 + y^2 + z^2 == 36}, {x, y, z}]

This returns a closed form solution of

enter image description here

If I take $N[]$, it returns

enter image description here

Adding a Chop produces a max

  57.6271 at x = 3.7642, y = 3.68959, z = 2.86666

If I run the command

  N[Maximize[{x*y + 2*y*z + 6*x, x^2 + y^2 + z^2 == 36}, {x, y, z}]]

I get the chopped version of the result.

My question is, how do users know that they should chop a result in general (sure, the imaginaries are quite small) but why does one command show them and the other does not?

Is a user expected to test the results to determine if chopping should be used or is this never true?

Aside: It appears that MathJax/LaTex is not working at the moment for some reason hence the pictures above.

$\endgroup$
4
  • 4
    $\begingroup$ how do users know that they should chop a result in general well, you can always automatically add Chop to the result. This way no need to guess. If it is needed, it will be used, if not, it will not affect the result, right? $\endgroup$
    – Nasser
    Jul 17, 2023 at 20:54
  • $\begingroup$ So why does the numerical result return it at all in those cases? Yes, as a user I can do all sorts of things and massage outputs, but that seems clumsy somehow. $\endgroup$
    – Moo
    Jul 17, 2023 at 20:57
  • 1
    $\begingroup$ "GlobalMaxima" returned the results in the form of radical expressions that can produce imaginary artifacts particularly when using machine precision. However, if you FullSimplify the results they will be in the form of Root expressions (same as those produced by Maximize) that will avoid the imaginary artifacts when N is used. In general, use arbitrary-precision (e.g., N[#, 15]&) rather than machine precision (i.e., N) to get better precision. $\endgroup$
    – Bob Hanlon
    Jul 17, 2023 at 22:20
  • $\begingroup$ It's better to use N[res, prec] with prec >= $MachinePrecision, imo, if you $\endgroup$
    – Michael E2
    Jul 18, 2023 at 0:18

1 Answer 1

10
$\begingroup$

Look at the output of Maximize:

Maximize[{x*y + 2*y*z + 6*x, x^2 + y^2 + z^2 == 36}, {x, y, z}] //InputForm

{6Root[{-108 - 72#1 + 9*#1^2 + 5*#1^3 & , -144 - 6*#1 + 7*#1^2 + 5*#2^2 & }, {3, 2}] + Root[{-108 - 72*#1 + 9*#1^2 + 5*#1^3 & , -144 - 6*#1 + 7*#1^2 + 5*#2^2 & }, {3, 2}]Root[-108 - 72#1 + 9*#1^2 + 5*#1^3 & , 3, 0] + 2Root[{-108 - 72#1 + 9*#1^2 + 5*#1^3 & , -144 - 6*#1 + 7*#1^2 + 5*#2^2 & , -18*#2 - 21*#1*#2 + 5*#1^2*#2 + 36*#3 & }, {3, 2, 1}]Root[-108 - 72#1 + 9*#1^2 + 5*#1^3 & , 3, 0], {x -> Root[{-108 - 72*#1 + 9*#1^2 + 5*#1^3 & , -144 - 6*#1 + 7*#1^2 + 5*#2^2 & }, {3, 2}], y -> Root[-108 - 72*#1 + 9*#1^2 + 5*#1^3 & , 3, 0], z -> Root[{-108 - 72*#1 + 9*#1^2 + 5*#1^3 & , -144 - 6*#1 + 7*#1^2 + 5*#2^2 & , -18*#2 - 21*#1*#2 + 5*#1^2*#2 + 36*#3 & }, {3, 2, 1}]}}

The output of the resource function uses nested radicals. When numericizing nested radicals, the radicals may be complex, with the imaginary parts cancelling after arithmetic. It is basically unavoidable when working with radicals. The output of Maximize consists of Root objects. When numericizing Root objects, Mathematica is able to determine whether the output is real, and avoids generating any imaginary parts if not needed. This is why chopping is necessary when you have arithmetic with radicals, while chopping is generally not needed when the output consists of Root objects. Just another reason to prefer Root objects over radicals.

$\endgroup$
1
  • 1
    $\begingroup$ (+1) @Carl Woll Nice explanation! $\endgroup$ Jul 18, 2023 at 2:04

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.