# How to check if a given expression is an “explicit algebraic number”?

The documentation for PossibleZeroQ says:

Unfortunately, there is no formal definition of what expressions are considered explicit algebraic numbers. I noticed that trig functions of rational multiples of π are not considered explicit algebraic numbers. Neither are RootSum expressions with algebraic functions as a second argument, nor Re, Im parts of Root expressions.

In[1]:= PossibleZeroQ[
Root[-7 + 56 #1^2 - 112 #1^4 + 64 #1^6 &, 4] - Sin[π/7], Method -> "ExactAlgebraics"]

PossibleZeroQ::ztest1: Unable to decide whether numeric quantity Root[-7 + 56 #1^2 - 112 #1^4 + 64 #1^6 &, 4,] - Sin[π/7] is equal to zero. Assumіng‌ it is. >>

Out[1]= True

In[2]:= PossibleZeroQ[
Root[25 + 3300 #1^4 - 530 #1^8 + 20 #1^12 + #1^16 &, 16] -
RootSum[5 - 20 #1^2 + 16 #1^4 &, Sqrt], Method -> "ExactAlgebraics"]

PossibleZeroQ::ztest1: Unable to decide whether numeric quantity Root[25 + 3300 #1^4 - 530 #1^8 + 20 #1^12 + #1^16 &, 16] - RootSum[5 - 20 #1^2 + 16 #1^4 &, Sqrt[#1] &] is equal to zero. Assumіng it is. >>

Out[2]= True

In[3]:= PossibleZeroQ[Re[Root[5 + 20 #1^2 + 16 #1^4 &, 1]], Method -> "ExactAlgebraics"]

PossibleZeroQ::ztest1: Unable to decide whether numeric quantity Re[Root[5 + 20 #1^2 + 16 #1^4 &, 1]] is equal to zero. Assumіng it is. >>

Out[3]= True


Could you suggest a function that can determine if a given expression is considered an explicit algebraic number from PossibleZeroQ's point of view?

-
...why again are you avoiding RootReduce[]? –  Ｊ. Ｍ. Jun 6 at 2:31
Thanks, I am well aware of RootReduce. But, first, it can take much time for larger expressions, and if I only need to check for zero, I want to invoke RootReduce only if necessary. Second, it does not work for cases like RootReduce[RootSum[5 - 20 #1^2 + 16 #1^4 &, Sqrt]] so other approaches (e.g. invoke Normal first) may be needed. –  Vladimir Reshetnikov Jun 6 at 2:41
Good question. I find it surprising that there is apparently no problem with a RootSum, and even more so that the sum of a RootSum and a Root is accepted, but the difference isn't. (Differences between Roots, though, are handled without any message.) –  Oleksandr R. Jun 6 at 3:49
Also I found, although your example threw warnings at first time, if I evaluate them again, they'll be quiet. –  Silvia Jun 6 at 4:02

This is not an answer, but some clue which I think might suggest a bug on what is going on.

First I'd like to state that the following test is done in Mathematica 9.0.1 only, and I have no idea about the cases in other versions.

# The inconsistency

Now let's start a fresh kernel, evaluate one of the examples in the question:

PossibleZeroQ[Re[Root[5 + 20 #1^2 + 16 #1^4 &, 1]], Method -> "ExactAlgebraics"]


It threw a warning message as OP described.

Now let's evaluate it again:

To my surprise, the warning is gone!

# Trace it!

To invesgate it more detailed, here is the comparison of Trace results:

Restart the kernel, and evaluate the following Dynamic command:

evalCache = {};
Dynamic[evalCache // StringJoin,
UpdateInterval -> 0, Initialization :> (evalCache := {})]


Keep the Dynamic cell visible and evaluate the following trace command:

With[{cachelength = 20},
TraceScan[
Module[{stopCond = False},
If[Length[evalCache] > cachelength,
evalCache = evalCache[[-cachelength ;;]]];
stopCond = ! FreeQ[#, Message] &&
! FreeQ[#, MessageName[PossibleZeroQ, "ztest1"]];
AppendTo[evalCache,
StringJoin[Flatten@{ConstantArray["|\t", TraceLevel[] - 2],
ToString[
Framed[#, FrameStyle -> If[stopCond, Red, Hue[.3, .3, .8]]],
StandardForm],
"\n"}]
];
If[stopCond, Print[#]; Abort[]]
] &,

PossibleZeroQ[Re[Root[5 + 20 #1^2 + 16 #1^4 &, 1]], Method -> "ExactAlgebraics"],

TraceInternal -> True, TraceDepth -> 2]
]


Record the result in the Dynamic cell, and evaluate evalCache = {} to re-initialize the evaluation chain cache, then re-trace. Hopefully you'll see what happened in my Mathematica, that the second trace result is different from the first, fresh one.

This is what the results look like here. (Please open image in new tab/window to see the details.) The middle one is the result from the first, fresh trace, the right side is from the second trace. For comparison, I also pinned on the left side the result for default setting, i.e. PossibleZeroQ[Re[Root[5 + 20 #1^2 + 16 #1^4 &, 1]]].

Please note the Method option they chose. For the fresh one, even though we explicitly specified Method -> "ExactAlgebraics", it seems Mathematica ignored it and went on with the default settings.

My conjecture: I guess there is a bug here in the method-choosing code.

According to @0x4A4D, PossibleZeroQ[] caches. But nevertheless, hope my trace function will help you/someone find the real answers.

-
The caching is easily confirmed: ClearSystemCache[]; PossibleZeroQ[Re[Root[5 + 20 #1^2 + 16 #1^4 &, 1]], Method -> "ExactAlgebraics"] will produce an error even if executed repeatedly. –  Ｊ. Ｍ. Jun 6 at 7:27
@0x4A4D Thanks I see it now. So what do you think about OP's question? –  Silvia Jun 6 at 7:53
I haven't the foggiest notion on how to solve it. This will probably need somebody from within WRI to answer. –  Ｊ. Ｍ. Jun 6 at 7:58
@0x4A4D Agree.. –  Silvia Jun 6 at 8:02