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

(Ted Harding) ted.harding at nessie.mcc.ac.uk
Mon Sep 3 19:50:28 CEST 2007


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 ------------------------------



More information about the R-devel mailing list