Re: comparing implicit 0 with machine floats

*To*: mathgroup at smc.vnet.net*Subject*: [mg71211] Re: [mg71108] comparing implicit 0 with machine floats*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>*Date*: Fri, 10 Nov 2006 06:38:22 -0500 (EST)*References*: <11095316.1163039426494.JavaMail.root@eastrmwml01.mgt.cox.net> <F3C6DEC6-64C4-45D4-98CC-8A79F52F3B0A@mimuw.edu.pl> <445AE1FB-31B2-4C25-841A-6F03BFE2FC68@mimuw.edu.pl>

I forgot that one has to be careful using Timing in the way I did below in Mathematica. What I should have done was: In[1]:= Timing[Simplify[Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] == 0.]] Out[1]= {0.046394999999999964*Second, True} In[2]:= Developer`ClearCache[] In[3]:= Timing[Simplify[Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]]]] Out[3]= {0.03863100000000008*Second, Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]]} There still seems to be a difference in Timing but a much smaller one. Clearly Simplify performs some numerical zero testing. I tried to control it using Developer`SetSystemOptions and the option AlgebraicZeroTestMaxAccuracy in SimplificationOptions, but changing its settings does not seem to make any difference. Andrzej Kozlowski On 9 Nov 2006, at 18:39, Andrzej Kozlowski wrote: > In fact, things look even more surprising (to me anyway). > > In[1]:= > Simplify[Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] == 0.]//Timing > > Out[1]= > {0.046486 Second,True} > > while > > In[2]:= > Timing[Simplify[Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]]]] > > Out[2]= > {0.0008739999999998194*Second, Sqrt[2] + Sqrt[3] - > Sqrt[5 + 2*Sqrt[6]]} > > Note that the first evaluation took a non-negligible amount of > time. One reason why I am surprised is that I would have thought > one would need to increase $MaxExtraPrecision to something like > > Accuracy[0.] > > 307.653 > > Andrzej Kozlowski > > > > On 9 Nov 2006, at 12:10, Andrzej Kozlowski wrote: > >> Yes indeed, it does. This is rather curious because Simplify does >> not actually reduce Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] to 0 >> (since Simplify does not make use of RootReduce) one needs >> FullSimplify to do that. >> >> In[51]:= >> Simplify[Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]]] >> >> Out[51]= >> Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] >> >> In[52]:= >> FullSimplify[Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]]] >> >> Out[52]= >> 0 >> >> Andrzej Kozlowski >> >> On 9 Nov 2006, at 11:30, Bob Hanlon wrote: >> >>> Using Simplify will force the comparison >>> >>> Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] == 2.//Simplify >>> >>> False >>> >>> Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] == N[10^3]//Simplify >>> >>> False >>> >>> >>> Bob Hanlon >>> >>> ---- Andrzej Kozlowski <akoz at mimuw.edu.pl> wrote: >>>> Consider the following: >>>> >>>> >>>> Sqrt[2] + Sqrt[3] - Sqrt[4 + 2*Sqrt[6]] == 2. >>>> >>>> False >>>> >>>> No problem here. Now let's make a small change >>>> >>>> In[17]:= >>>> Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] == 2. >>>> >>>> Out[17]= >>>> >>>> Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] == 2. >>>> >>>> In fact the expression on the LHS is exactly 0: >>>> >>>> In[19]:= >>>> RootReduce[Sqrt[2]+Sqrt[3]-Sqrt[5+2*Sqrt[6]]] >>>> >>>> Out[19]= >>>> >>>> The curious thing is that if you try a comparison between a zero of >>>> this kind and any machine float, however large, Mathematica 5.1 >>>> will >>>> return the original input: >>>> >>>> In[20]:= >>>> Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] == N[10^3] >>>> >>>> Out[20]= >>>> Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6]] == 1000. >>>> >>>> yet if the number of the left hand side is altered, however >>>> slightly, >>>> the comparison will be made: >>>> >>>> >>>> Sqrt[2] + Sqrt[3] - Sqrt[5 + 2*Sqrt[6+1/10^20]] == 2. >>>> >>>> False >>>> >>>> This suggests that Mathematica actually did perform a >>>> computation of >>>> the left hand side in the examples where it just returned the input >>>> and having discovered that it could not determine if the LHS is an >>>> exact zero decided "not to answer the question". But this seems >>>> quite >>>> unreasonable; after all it is not being asked if the LHS is an >>>> exact >>>> 0, or even an approximate 0, but if it is an approximate large >>>> number >>>> like 1000., and this it certainly can decide. >>>> >>>> I believe this used to be handled differently (better?) in older >>>> versions of Mathematica but I no longer have any installed to >>>> check. >>>> >>>> Andrzej Kozlowski >>>> >>> >> >