Skip to main content

Most efficient way to determine conclusively whether an algebraic number is zero


Let x be an algebraic number of unspecified degree, expressed using arithmetic, rational powers, and algebraic integers (edit: Root[...] constructs). I would like to test conclusively whether it is zero.


I don't know whether any of the following are guaranteed to work:


x==0
Simplify[x]==0
FullSimplify[x]==0
PossibleZeroQ[x,Method->"ExactAlgebraics"]

The following should work, but seems unlikely to be efficient:



MinimalPolynomial[x][y]===y

I don't want to use numerical approximation unless the answer is guaranteed to be correct.


Do any of the first four lines above guarantee a correct answer?


What is the best way to perform this test in Mathematica?



Answer



Sometimes the only conclusive way of the four methods considered in the question can be PossibleZeroQ[ x, Method->"ExactAlgebraics"], it appears to be the most efficient as well. Dealing with explicitly algebraic numbers in almost all tests it is faster than FullSimplify. The main reason for this issue seems to be that FullSimplify is assumed to work with special functions, transcendental numbers and so on, thus there is a broader range of possible transformations while the option Method->"ExactAlgebraics" restricts to specific polynomial (algebraic) transformations. Moreover FullSimplify being able to transform given expressions involes drawbacks with respect to efficiency comparing it to PossibleZeroQ only performing tests yielding two values : True or False.


Explicit algebraic numbers


At first we need at least a few algebraic numbers i.e. roots of univariate non-zero polynomials with rational coefficients which are not explictly zero. We can provide a desired list of algebraic numbers using RootReduce to any nested radicals.


{x1, x2, x3, x4, x5, x6} = 

{
(Sqrt[2] + Sqrt[3] + Sqrt[6] + 3)/Sqrt[5 + 2 Sqrt[6]] - 1 - Sqrt[3],

(-72 (1 - I Sqrt[3]))^(1/4) - 3 - I Sqrt[3],

Root[1 + #1^4 &, 4]
- ((7 - 2I)/(1 + I Sqrt[2]) + (4 + 14I)/(Sqrt[2] + 2I) - 8 + 2I)^(1/4),

((1 - 5 I)/(1 + I) - 5 (1 + 2 I)/(2 - I) + 2)^(1/3) - Root[16 - 4 #1^2 + #1^4 &, 3],


((-2 + 2 Sqrt[3] I)/(2 + I Sqrt[5]) - 5 (Sqrt[3] + I)/(2 Sqrt[5] + 5 I))^(1/4)
- Root[4 + 2 #1^4 + #1^8 &, 8],

- Root[ 65536 + 16384 #1^2 - 1024 #1^6 - 256 #1^8 - 64 #1^10 + 4 #1^14 + #1^16 &, 15]
+ (512 (1 - I Sqrt[3]))^(1/10) };

We do not test the first two ways (i.e. x == 0 and Simplify[x] == 0) since they certainly cannot guarantee that an algebraic number is zero e.g. we can check it with x == x1. One can see that neither x1 == 0 nor Simplify[x1] == 0 yield any constructive answers. While the other two methods work well.


Let's define a testing function :


rT[x_] := 
Module[{a, b},

a = AbsoluteTiming[ PossibleZeroQ[x, Method -> "ExactAlgebraics"]];
b = AbsoluteTiming[ FullSimplify[x] == 0];
If[ Last[a] ~ And ~ Last[b], First[a]/First[b]] ]

and it yields :


rT /@ {x1, x2, x3, x4, x5, x6} // Column


0.01111
0.1364

0.455
0.1667
1.222
0.48927

when we quit the kernel and try a twin function (reveresd the order of evaluation) :


rT1[x_] := 
Module[{a, b},
b = AbsoluteTiming[ FullSimplify[x] == 0];
a = AbsoluteTiming[ PossibleZeroQ[x, Method -> "ExactAlgebraics"]];

If[ Last[a] ~ And ~Last[b], First[a]/First[b]] ]

we can see even much better ratios :


rT1 /@ {x1, x2, x3, x4, x5, x6} // Column


0.00448
0.0435
0.364
0.0769

0.667
0.41071

Non-explicit algebraics


Let's consider another example (see How to get exact roots of this polynomial ?) where the numbers Cos[2 (6 - k) Ï€/11] for k ∈ Range[5] are not explicitely algebraic, but Mathematica simply decides they are indeed algebraic.


And @@ FullSimplify @ Table[ Cos[2 (6 - k) Ï€/11] ∈ Algebraics, {k, 5}]


 True


And @@ ( PossibleZeroQ[#, Method -> "ExactAlgebraics"]& /@ 
Table[ Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, k] -
Cos[2 (6 - k) π/11], {k, 5}])


 True

however FullSimplify[Table[...]] is not sufficient here even though we could prove that numbers are zero with RootReduce. One should point out that using options in FullSimplify we could prove as well that the above algebraics are zeros but in general it is difficult to guess which option (what ComplexityFunction or TransformationFunctions) can be helpful.


Let's consider the last example :


xa = RootSum[ 3 - 2 #1 + #1^7 &, (PolyGamma[0, -#1] #1)/(-2 + 7 #1^6) &];

xb = RootSum[2 + 5 #1 + 21 #1^2 + 35 #1^3 + 35 #1^4 + 21 #1^5 + 7 #1^6 + #1^7 &,
(PolyGamma[0, -#1] + PolyGamma[0, -#1] #1)/(5 + 42 #1 + 105 #1^2
+ 140 #1^3 + 105 #1^4 + 42 #1^5 + 7 #1^6) &];
x = xa - xb;

We can't prove with Mathematica whether xa and xb are algebraic numbers.


PossibleZeroQ[ x1, Method -> "ExactAlgebraics"]


 PossibleZeroQ::ztest1: Unable to decide whether numeric quantity 

RootSum[3-2 #1+#1^7&,(PolyGamma[0,-#1] #1)/(-2+7 Power[<<2>>])&] - RootSum[2+5 #1+...])&]
is equal to zero. Assuming it is. >>

True

We can see that PossibleZeroQ is not powerful enough to yield a definitive answer but FullSimplify cannot do it at all.
Nonetheless one can prove that x1 is indeed 0.


To sum up PossibleZeroQ[ x, Method -> "ExactAlgebraics"] is clearly faster than FullSimplify as well as more connvenient and universal in tests. However the latter can simplify expressions while the former one cannot.


Comments

Popular posts from this blog

calculus and analysis - Integral of the Sinc product

Let us consider the following integral $$ B_n = \int_0^\infty \prod_{k=1,3,5,\dots}^n\frac{\sin (x/k)}{x/k}dx $$ By definition, Sinc[x] == Sin[x]/x , therefore B[n_?OddQ] := Integrate[Product[Sinc[x/k], {k, 1, n, 2}], {x, 0, Infinity}] B /@ Range[1, 13, 2] {Pi/2, Pi/2, Pi/2, Pi/2, Pi/2, Pi/2, Pi/2} OK, everything is fine. But... B[15] 467807924713440738696537864469 Pi/935615849440640907310521750000 What's going on? Answer As Eckhard wrote in comments B[n] is the n-th Borwein integral . (The letter B was not accidental :) ) This funny properties of Borwein integrals is related to the Fourier transform of Sinc function FourierTransform[Sinc[x], x, k] 1/2 Sqrt[Pi/2] (Sign[1 - k] + Sign[1 + k]) Plot[%, {k, -2, 2}, Filling -> 0] which is the box function. The result is $\pi/2$ while the sum $$ 1/3+1/5+\dots+1/n $$ B_n = \frac{\pi}{2} - \pi \bigg(\sum_{k=3,5,\ldots}^n\frac{1}{k} -1\biggr)^\frac{n-1}{2}\prod_{k=3,5,\dots}^n\frac{k}{k-1}. $$ For $n=15$ it is equal to $$ \frac{46780...

list manipulation - Solving word search puzzles

I am trying to create a code that can identify the following terms in a grid of letters: MATHEMATICA, STACK, EXCHANGE and USERS. list1={"M","S","T","A","S","I","S","X","X","T","R","X"}; list2={"A ","T ","H ","X ","R ","X ","G ","R ","S ","H ","X ","A"}; list3={"M","A","T","H","E","M","A","T","I","C","A","I"}; list4={"A","X","S","G","S","X","A","I","R","T","X","T"}; list5={"T","I","T","G","U","C","C","I","R","N",...

implicit - Plotting a function with implicitly defined variable

I have a question about plotting a function with an implicitly defined variable. I think the solution should be something similar like here: Define a function with variables linked implicitly but I quite can't get it to work. I apologize if this has been asked for, I tried doing a thorough search before asking. Anyway, I am trying to plot the following function: $$ u(x,y,t)=\text{sgn}(x+y-t+r(t))\big(e^{-\vert x+y-t+r(t) \vert }-1\big)+r(t)e^{-\vert x+y+r(t)+\ln(\frac{1}{9}r(t)^2-\frac{1}{2}r(t)+1)\vert} $$ where $r(t)$ is implicitly defined with the following equation $$ \ln\vert r(t)\vert-\frac{1}{2}\ln\vert r(t)^2-\frac{9}{2}r(t)+9\vert+\frac{3\sqrt{}{7}}{7}\tan^{-1}\big(\frac{4r(t)-9}{3\sqrt{}{7}}\big)=2t. $$ Ultimately, I would like to use Plot3D for $u(x,y)$ and use Manipulate to see the function at different time steps of $t$. Thank you in advance for your time and help. It's greatly appreciated. Edit: Here is some mathematica format to make life easier: Sign[x + y - t ...