Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #3509 > unrolled thread
| Started by | "slawek" <slawek@host.pl> |
|---|---|
| First post | 2011-07-06 09:37 +0000 |
| Last post | 2011-07-07 11:35 +0000 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Bug 1+4/10 "slawek" <slawek@host.pl> - 2011-07-06 09:37 +0000
Re: Bug 1+4/10 Peter Breitfeld <phbrf@t-online.de> - 2011-07-06 11:06 +0000
Re: Bug 1+4/10 "slawek" <slawek@host.pl> - 2011-07-07 11:41 +0000
Re: Bug 1+4/10 "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-07-07 11:27 +0000
Re: Bug 1+4/10 "slawek" <human@site.pl> - 2011-07-08 08:52 +0000
Re: Bug 1+4/10 "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-07-09 11:41 +0000
Re: Bug 1+4/10 Daniel Lichtblau <danl@wolfram.com> - 2011-07-07 11:35 +0000
| From | "slawek" <slawek@host.pl> |
|---|---|
| Date | 2011-07-06 09:37 +0000 |
| Subject | Bug 1+4/10 |
| Message-ID | <iv1acv$sk7$1@smc.vnet.net> |
Let check In[1]:= 1.4 == 1 + 4/10 Out[1]= True In[2]:= a = SetPrecision[1.4, 30] Out[2]= 1.39999999999999991118215802999 In[3]:= b = SetPrecision[1 + 4/10, 30] Out[3]= 1.40000000000000000000000000000 No comment is needed. slawek
[toc] | [next] | [standalone]
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Date | 2011-07-06 11:06 +0000 |
| Message-ID | <iv1fjv$vs$1@smc.vnet.net> |
| In reply to | #3509 |
"slawek" wrote:
> Let check
>
> In[1]:= 1.4 == 1 + 4/10
> Out[1]= True
>
> In[2]:= a = SetPrecision[1.4, 30]
> Out[2]= 1.39999999999999991118215802999
>
> In[3]:= b = SetPrecision[1 + 4/10, 30]
> Out[3]= 1.40000000000000000000000000000
>
> No comment is needed.
>
> slawek
>
Thats documentated behaviour. In the help of Equal (Scope/Numeric
Equalities):
Approximate numbers that differ in their last seven binary digits are
considered equal. (this are about the two last decimals)
RealDigits[1.4, 2]
RealDigits[1 + 4/10, 2]
{{1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1,
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0,
1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0}, 1}
{{1, {0, 1, 1, 0}}, 1}
or
RealDigits[1.4]
RealDigits[1 + 4/10]
{{1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 1}
{{1, 4}, 1}
There is no difference in the last 2 decimals. But
1.4===1+4/10
False
SameQ returns True, if the numbers differ in the last binary digit only,
so and have the same head. (1.4 is a Real, but 1+4/10 is Rational, so
SameQ returns False)
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
[toc] | [prev] | [next] | [standalone]
| From | "slawek" <slawek@host.pl> |
|---|---|
| Date | 2011-07-07 11:41 +0000 |
| Message-ID | <iv461a$f8i$1@smc.vnet.net> |
| In reply to | #3516 |
Użytkownik "Peter Breitfeld" <phbrf@t-online.de> napisał w wiadomości grup dyskusyjnych:iv1fjv$vs$1@smc.vnet.net... > Thats documentated behaviour. In the help of Equal (Scope/Numeric > Equalities): 2 + 2 == 5 is well documented in "1984" by Orwell, 2 + 2 == 7 is well documented in "Robot's fables" by S. Lem
[toc] | [prev] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-07-07 11:27 +0000 |
| Message-ID | <iv456e$eop$1@smc.vnet.net> |
| In reply to | #3509 |
On Wed, 06 Jul 2011 10:37:35 +0100, slawek <slawek@host.pl> wrote:
> Let check
>
> In[1]:= 1.4 == 1 + 4/10
> Out[1]= True
>
> In[2]:= a = SetPrecision[1.4, 30]
> Out[2]= 1.39999999999999991118215802999
>
> In[3]:= b = SetPrecision[1 + 4/10, 30]
> Out[3]= 1.40000000000000000000000000000
>
> No comment is needed.
>
> slawek
Yet:
In[4] :=
a == b
Out[4] =
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[5] :=
a = SetPrecision[Interval[1.4], 30]
Out[5] =
Interval[{1.39999999999999968913755310495,
1.40000000000000013322676295502}]
In[6] :=
b = SetPrecision[Interval[1 + 4/10], 30]
Out[6]=
Interval[{1.40000000000000000000000000000,
1.40000000000000000000000000000}]
In[7] :=
IntervalMemberQ[a, b]
Out[7] =
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.
[toc] | [prev] | [next] | [standalone]
| From | "slawek" <human@site.pl> |
|---|---|
| Date | 2011-07-08 08:52 +0000 |
| Message-ID | <iv6gh6$s04$1@smc.vnet.net> |
| In reply to | #3519 |
Użytkownik "Oleksandr Rasputinov" napisał w wiadomości grup dyskusyjnych:iv456e$eop$1@smc.vnet.net... >Proper treatment of inexact numbers requires at least some care and There is no "inexact numbers". There are only inexact computations and/or measurements. 3.14 is an approximation of pi, but it is exactly 3+1/10+4/100
[toc] | [prev] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-07-09 11:41 +0000 |
| Message-ID | <iv9epg$df2$1@smc.vnet.net> |
| In reply to | #3519 |
On Fri, 08 Jul 2011 09:52:54 +0100, slawek <human@site.pl> wrote: > U=BFytkownik "Oleksandr Rasputinov" napisa=B3 w wiadomo=B6ci grup > dyskusyjnych:iv456e$eop$1@smc.vnet.net... > >> Proper treatment of inexact numbers requires at least some care and > > There is no "inexact numbers". There are only inexact computations and= /or > measurements. > > 3.14 is an approximation of pi, but it is exactly 3+1/10+4/100 > In this context, "inexact number" means a distribution, the exact number being the expectation value of this distribution. In the case of finite-precision inexact numbers we have uniform distributions over finite fields; the true expectation values are then the means, whose values are however not necessarily exactly representable in such fields. I trust that you understand these concepts, so let us not enter into a futile debate over nomenclature or epistemology.
[toc] | [prev] | [next] | [standalone]
| From | Daniel Lichtblau <danl@wolfram.com> |
|---|---|
| Date | 2011-07-07 11:35 +0000 |
| Subject | Re: Bug 1+4/10 |
| Message-ID | <iv45lp$f3e$1@smc.vnet.net> |
| In reply to | #3509 |
On Jul 6, 4:37 am, "slawek" <sla...@host.pl> wrote:
> Let check
>
> In[1]:= 1.4 == 1 + 4/10
> Out[1]= True
>
> In[2]:= a = SetPrecision[1.4, 30]
> Out[2]= 1.39999999999999991118215802999
>
> In[3]:= b = SetPrecision[1 + 4/10, 30]
> Out[3]= 1.40000000000000000000000000000
>
> No comment is needed.
>
> slawek
(1) Approximate numbers in Mathematica are internally stored and
manipulated in a binary base.
(2) Given an approximate number, SetPrecision will pad with binary
zeros if requested to set to a precision that is greater than the
precision of the input.
The result Out[2] shown above is a consequence of these.
In a bit (well, a few bits...) more detail:
In[24]:= bits = RealDigits[1.4,2]
Out[24]//InputForm=
{{1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
1, 0,
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1,
0, 0,
1, 1, 0}, 1}
In[25]:= morebits = PadRight[bits[[1]], Floor[20*Log[2,10]]]
Out[25]//InputForm=
{1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
1, 0,
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1,
0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
In[26]:= rational = FromDigits[{morebits, bits[[2]]}, 2]
Out[26]//InputForm= 3152519739159347/2251799813685248
In[27]:= N[rational,20]
Out[27]//InputForm=
1.399999999999999911182158029987476766109466552734375`20.
Daniel Lichtblau
Wolfram Research
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web