# To Chop or not to Chop

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

If I take $$N[]$$, it returns

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.

• 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? Commented Jul 17, 2023 at 20:54
• 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.
– Moo
Commented Jul 17, 2023 at 20:57
• "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. Commented Jul 17, 2023 at 22:20
• It's better to use N[res, prec] with prec >= \$MachinePrecision, imo, if you Commented Jul 18, 2023 at 0:18

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

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.