From ted.harding at nessie.mcc.ac.uk  Mon Sep  3 19:50:28 2007
From: ted.harding at nessie.mcc.ac.uk ( (Ted Harding))
Date: Mon, 03 Sep 2007 18:50:28 +0100 (BST)
Subject: [Rd] When 1+2 != 3 (PR#9895)
In-Reply-To: <59d7961d0709030812p6b490c63j1b13f4246c1e7639@mail.gmail.com>
Message-ID: <XFMail.070903173242.Ted.Harding@manchester.ac.uk>

On 03-Sep-07 15:12:06, Henrik Bengtsson wrote:
> On 9/2/07, marco.vicentini at gmail.com <marco.vicentini at gmail.com> wrote:
>> [...]
>> If it may be usefull, I have written to small function
>> (Unique and isEqual)
>> which can deal with this problem of the double numbers.
> 
> Quiz: What about utility functions equalsE() and equalsPi()?
> ...together with examples illustrating when they return TRUE and when
> they return FALSE.
> 
> Cheers
> 
> /Henrik

Well, if you guys want a Quiz: ... My favourite example
of something which will probably never work on R (or any
machine which implements fixed-length binary real arithmetic).

An interated function scheme on [0,1] is defined by

  if 0 <= x <= 0.5 then next x = 2*x

  if 0.5 < x <= 1  then next x = 2*(1 - x)

in R:

  nextX <- function(x){ifelse(x<=0.5, 2*x, 2*(1-x))}

and try, e.g.,

 x<-3/7; for(i in (1:60)){x<-nextX(x); print(c(i,x))}

x = 0 is an absorbing state.
x = 1 -> x = 0
x = 1/2 -> 1 -> 0
...
(these work in R)

If K is an odd integer, and 0 < r < K, then

x = r/K ->  ... leads into a periodic set.

E.g. (see above) 3/7 -> 6/7 -> 2/7 -> 4/7 -> 2/7

All other numbers x outside these sets generate non-periodic
sequences.

Apart from the case where initial x = 1/2^k, none of the
above is true in R (e.g. the example above).

So can you devise an "isEqual" function which will make this
work?

It's only Monday .. plenty of time!
Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 03-Sep-07                                       Time: 17:32:38
------------------------------ XFMail ------------------------------

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 03-Sep-07                                       Time: 18:50:23
------------------------------ XFMail ------------------------------



[Rd] When 1+2 != 3 (PR#9895)
 (Ted Harding