# Getting message Maximize::ztest: — how should I deal with it?

I am working on a maximization problem of the form

Maximize[{f, cons}, {x, y, ...}]


Mathematica outputs a warning and a result. The warning is

Maximize::ztest: Unable to decide whether numeric quantities {..., ..., ...} are equal to zero. Assuming they are.

What does this warning mean? Can I rely on the result, or does in rely on a (possibly wrong) assumption?

Note that I am looking for a general explanation of this warning, so the exact function, constraints and result I get should be irrelevant.

This message is likely coming from PossibleZeroQ. Take a look at its documentation: PossibleZeroQ.

Under details:

The general problem of determining whether an expression has value zero is undecidable; PossibleZeroQ provides a quick but not always accurate test.

This is why the function is not called ZeroQ, i.e. it does not promise you that its response will always be accurate.

Even when this problem is decidable, it is not always easy in practice (the so-called constant problem).

When dealing with numerical expressions (i.e. there are no symbolic parameters are present), Mathematica may use arbitrary precision arithmetic to decide if the expression has certain properties.

Here's an example:

expr = Sqrt + Sqrt - Sqrt[5 + 2 Sqrt]


Questions like Positive[expr+1] are decided by calculating expr+1 to sufficient precision. But here expr actually turns out to be exactly zero. If you ask to calculate it to 10 digits, Mathematica will fail:

In[]:= N[expr, 10]

During evaluation of In[]:= N::meprec: Internal precision limit \$MaxExtraPrecision = 50. reached while evaluating Sqrt+Sqrt-Sqrt[5+2 Sqrt].

Out[]= 0.*10^-66


It keeps calculating more and more digits to get 10 significant ones, but all it gets is zeros. After a while, it gives up and it gives a warning.

It can, in fact, show that expr is zero:

FullSimplify[expr]
(* 0 *)


But that involves doing complicated and time-consuming symbolic transformations.

Thus when presented with a question like

PossibleZeroQ[expr]


Mathematica may resort to a numerical evaluation, and if it doesn't find a difference from zero after calculating many digits, it may just decide that it's zero. But it also gives you a warning, saying that this is not a proof.

It seems recent versions of Mathematica can prove this expression to be zero, but cannot do it for this alternative form:

In:= PossibleZeroQ[Sqrt + Sqrt - Root[1 - 10 #1^2 + #1^4 &, 4]]

During evaluation of In:= PossibleZeroQ::ztest1: Unable to decide whether numeric quantity Sqrt+Sqrt-Root[1-10 Slot[<<1>>]^2+#1^4&,4,0] is equal to zero. Assuming it is.

Out= True


There is another example in the documentation where the answer is clearly wrong, though the expression is indeed zero up to a very large number of digits:

In:= PossibleZeroQ[
Sqrt + Sqrt - Root[1 - 10 #1^2 + #1^4 &, 4] + 10^-10000]

During evaluation of In:= PossibleZeroQ::ztest1: Unable to decide whether numeric quantity 1/(100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000<<9712>>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)+Sqrt+Sqrt-Root[1-10 Slot[<<1>>]^2+#1^4&,4,0] is equal to zero. Assuming it is.

Out= True
`

So, to sum up:

The message you see means that Mathematica could not prove that certain expressions are identically zero. It did find some evidence that they might be, so it assumes that they are. This assumption may be incorrect.