       Re: Bug 1+4/10

• To: mathgroup at smc.vnet.net
• Subject: [mg120118] Re: Bug 1+4/10
• From: "Christoph Lhotka" <christoph.lhotka at univie.ac.at>
• Date: Fri, 8 Jul 2011 05:37:13 -0400 (EDT)

```Dear group,

to my opinion everything is consistent with the bug example. Let me
explain why:

1) Why 1.4=1+4/10 is true:

a = 1.4;
b = 1 + 4/10;

the precision of the former is machine precision, the precision of the
latter is infinite:

Precision /@ {a, b}
{MachinePrecision, \[Infinity]}

As anytime Mathematica converts numbers to the lowest precision found in
the computation and returns an answer correct to the lowest precision
found in the computation. If we do it by ourselves:

FullForm[N[b, MachinePrecision]]
1.4`

FullForm[N[7/5]]
1.4`

so if we compare 1.4`==1.4` we get true.

2) Why SetPrecision does not convert 1.4 to 1.4000000000000000000:

Let us set a to be a machine precision number and b to be a number with
given infinite precision:

a = 1.4;
b = 1 + 4/10;

SetPrecision cannot determine the digits after the 16th digit of a, since
the are already lost (they are random):

a16 = SetPrecision[a, 30]
1.39999999999999991118215802999

If you want to specifiy that a is a 1.4 with 30 digit precision you should
rather use the notation (IMPORTANT):

a30 = a = 1.4`30
1.40000000000000000000000000000

On the other hand SetPrecision will determine all the correct digits of a
number with infinite precision:

SetPrecision[b, 30]
1.40000000000000000000000000000

So if you compare a16 with b you get:

a16 == b
False

But if you compare a30 with b you get the correct anwser:

a30 == b
True

I am happy that Mathematica takes care of all these details!

Best,

Christoph

On 07/07/2011 13:27, Oleksandr Rasputinov wrote:
> On Wed, 06 Jul 2011 10:37:35 +0100, slawek <slawek at host.pl> wrote:
>
>> Let check
>>
>> In:= 1.4 == 1 + 4/10
>> Out= True
>>
>> In:= a = SetPrecision[1.4, 30]
>> Out= 1.39999999999999991118215802999
>>
>> In:= b = SetPrecision[1 + 4/10, 30]
>> Out= 1.40000000000000000000000000000
>>
>> No comment is needed.
>>
>> slawek
>
> Yet:
>
> In :=
> a == b
>
> Out =
> False
>
> So here we have shown that a number padded with binary zeros is generally
> not equal to the same number padded with decimal zeros. I doubt anyone can
> be surprised by this. However, they are still comparable in a sense:
>
> In :=
> a = SetPrecision[Interval[1.4], 30]
>
> Out =
> Interval[{1.39999999999999968913755310495,
>            1.40000000000000013322676295502}]
>
> In :=
> b = SetPrecision[Interval[1 + 4/10], 30]
>
> Out=
> Interval[{1.40000000000000000000000000000,
>            1.40000000000000000000000000000}]
>
> In :=
> IntervalMemberQ[a, b]
>
> Out =
> True
>
> Proper treatment of inexact numbers requires at least some care and
> attention. It is important to remember that one is operating on
> distributions rather than points, so simplistic notions of arithmetic
> equality are not meaningful.
>
>

```

• Prev by Date: Re: Numerical accuracy/precision - this is a bug or a feature?
• Next by Date: Re: How to write a "proper" math document
• Previous by thread: Re: Bug 1+4/10
• Next by thread: Re: Bug 1+4/10