MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Pi == 3 for imprecise values of 3?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22951] Re: Pi == 3 for imprecise values of 3?
  • From: Robert Knapp <rknapp at wolfram.com>
  • Date: Fri, 7 Apr 2000 02:54:33 -0400 (EDT)
  • Organization: Wolfram Research, Inc.
  • References: <8chbil$9ei@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Gavin Scott wrote:
> 
> In playing with my spiffy new copy of 4.0.2 for Windows, I'm curious
> why:
> 
>    In[1]:= N[Pi] == 3`0
>    Out[1]= True
> 
> It seems that a value compared to a number with very low precision
> will result in Equal[] returning True.
> 
>    In[2]:= 1 == 2`0.00001
>    Out[2]= True
> 
>    In[3]:= 1 == 2`0.0001
>    Out[3]= False
> 
> but then
> 
>    In[4]:= 10^10 == 2`0
>    Out[4]= False
> 
> I suppose that when you have zero digits of accuracy then you have no idea
> what the value is, so it certainly *could* be equal to any value, but I
> find it surprising that == chooses True over False in these cases.
> 

In Mathematica, Equal (and Less and Greater) use a tolerance so that two
numbers do not have to be identical to be deemed Equal.  THe motivation
behind this is beyond the scope of a simple reply, but if you are
interested, I suggest section 4.2.2 on Accuracy of floating point
numbers in Knuth's "Seminumerical Algorithms"

Given a tolerance, t, two numbers a and b are considered Equal to that
tolerance if

Precision[a - b] < t

A way of interpreting this is that a and b must be the same except in
the t least significant digits since the other digits must cancel in the
subtraction.  So in your example:
(Set $MinPrecision here so it is not at all restricted)

In[1]:=
Block[{$MinPrecision = -Infinity}, Precision[Pi - 3`0, Round -> False]]

Out[1]=
-1.32608

The tolerance Equal uses is

In[2]:=
$EqualTolerance

Out[2]=
2.10721

which corresponds to 7 bits.  In fact, with this tolerance, 

In[3]:=
Block[{$MinPrecision = -Infinity}, Precision[Pi - 3`3.3, Round ->
False]]

Out[3]=
1.97392

so...

In[4]:=
Pi == 3`3.3

Out[4]=
True


Rob Knapp
Wolfram Research, Inc.


  • Prev by Date: Re: Apparently easy ODE
  • Next by Date: Re: 2-D Vector Field scale ?
  • Previous by thread: Pi == 3 for imprecise values of 3?
  • Next by thread: Command to get a notebook's directory?