From ggrothendieck at gmail.com  Mon Sep  3 21:25:58 2007
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Mon, 3 Sep 2007 15:25:58 -0400
Subject: [Rd] When 1+2 != 3 (PR#9895)
In-Reply-To: <XFMail.070903173242.Ted.Harding@manchester.ac.uk>
References: <59d7961d0709030812p6b490c63j1b13f4246c1e7639@mail.gmail.com>
	<XFMail.070903173242.Ted.Harding@manchester.ac.uk>
Message-ID: <971536df0709031225g54c6cfj2df54f3400720f61@mail.gmail.com>

Not sure if this counts but using the Ryacas package

> library(Ryacas)
> x <- Sym("x")
> Set(x, Sym(3)/7)
expression(3/7)
> cat(i, "0: "); print(x)
10 0: expression(3/7)
> for(i in 1:10) {
+ yacas("Set(x, If(x <= 1/2, 2*x, 2*(1-x)))")
+ cat(i, "i: "); print(x)
+ }
1 i: expression(6/7)
2 i: expression(2/7)
3 i: expression(4/7)
4 i: expression(6/7)
5 i: expression(2/7)
6 i: expression(4/7)
7 i: expression(6/7)
8 i: expression(2/7)
9 i: expression(4/7)
10 i: expression(6/7)

On 9/3/07, Ted Harding <ted.harding at nessie.mcc.ac.uk> wrote:
> 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 ------------------------------
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



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