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

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 03 Sep 2007 15:25:58 -0400

> 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@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 03 Sep 2007 - 19:30:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 03 Sep 2007 - 23:41:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.