mathics-core icon indicating copy to clipboard operation
mathics-core copied to clipboard

SameQ for PrecisionReal

Open mmatera opened this issue 3 years ago • 0 comments

When SameQ is applied to two PrecisionReal numbers that differ in a quantity under the precision, WMA returns True, while Mathics returns False. The issue does not affect Equal. For example, in WMA,

In[1]:= a=N[2/9,3]; b=0.22222`5; {a,b,a==b, a===b}

returns

Out[1]= {0.222,0.22222,True, True}

while in Mathics,

Out[1]:=  {0.222,0.22222,True, False}

This issue comes up when we try to implement low-level tests (see for example #145), and seems to be related to how the comparison operator is implemented in mpf.

A similar issue comes up if we evaluate a-b. In WMA,

In[2]:= a=N[2/9,3]; b=0.22222`5; {a-b, Precision[a-b]}

results in

Out[2]={0.`, 0.}

while in Mathics,

Out[2]={0.0000153, 3.}

A possible fix would be to check the precision in PrecisionReal.sameQ and in the constructors of Real and PrecisionReal..

mmatera avatar Feb 01 '22 23:02 mmatera