Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-14 Thread Martin Maechler
> "P" == ProfJCNash > on Sat, 4 Jul 2015 21:42:27 -0400 writes: P> n163 <- mpfr(163, 500) P> is how I set up the number. Yes, and you have needed to specify the desired precision. As author and maintainer of Rmpfr, let me give my summary of this overly long thread (with ma

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-04 Thread ProfJCNash
_ >> From: David Winsemius >> Sent: Saturday, July 4, 2015 1:12 PM >> To: Duncan Murdoch >> Cc: r-help; John Nash; Ravi Varadhan >> Subject: Re: [R] : Ramanujan and the accuracy of floating point computations >> - using Rmpfr in R >>

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-04 Thread Ravi Varadhan
nujan and the accuracy of floating point computations - using Rmpfr in R > On Jul 4, 2015, at 12:20 AM, Duncan Murdoch wrote: > > On 04/07/2015 8:21 AM, David Winsemius wrote: >> >>> On Jul 3, 2015, at 11:05 PM, Duncan Murdoch >>> wrote: >>> &

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-04 Thread David Winsemius
> On Jul 4, 2015, at 12:20 AM, Duncan Murdoch wrote: > > On 04/07/2015 8:21 AM, David Winsemius wrote: >> >>> On Jul 3, 2015, at 11:05 PM, Duncan Murdoch >>> wrote: >>> >>> On 04/07/2015 3:45 AM, David Winsemius wrote: > On Jul 3, 2015, at 5:08 PM, David Winsemius > wrote: >>

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-04 Thread Gabor Grothendieck
i > > From: David Winsemius > Sent: Friday, July 3, 2015 2:06 PM > To: John Nash > Cc: r-help; Ravi Varadhan > Subject: Re: [R] : Ramanujan and the accuracy of floating point > computations - using Rmpfr in R > > > On Jul 3, 20

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-04 Thread Duncan Murdoch
On 04/07/2015 8:21 AM, David Winsemius wrote: > >> On Jul 3, 2015, at 11:05 PM, Duncan Murdoch wrote: >> >> On 04/07/2015 3:45 AM, David Winsemius wrote: >>> On Jul 3, 2015, at 5:08 PM, David Winsemius wrote: It doesn’t appear to me that mpfr was ever designed to handle

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread Hadley Wickham
It doesn’t appear to me that mpfr was ever designed to handle expressions as the first argument. >>> >>> This could be a start. Obviously one would wnat to include code to do other >>> substitutions probably using the all.vars function to pull out the other >>> “constants” and ’numeric

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread David Winsemius
>> On Jul 3, 2015, at 12:01 PM, Ravi Varadhan wrote: >>>> >>>> Thank you all. I did think about declaring `pi' as a special constant, >>>> but for some reason didn't actually try it. >>>> Would it be easy to have the mpfr() written such tha

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread Duncan Murdoch
sqrt(n163)*pitan) >>>> r500 >>>> check <- "262537412640768743.25007259719818568887935385..." >>>> savehistory("jnramanujan.R") >>>> >>>> Note that I used 4*atan(1) to get pi. >>> >>> RK got

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread David Winsemius
t;>> check <- "262537412640768743.25007259719818568887935385..." >>> savehistory("jnramanujan.R") >>> >>> Note that I used 4*atan(1) to get pi. >> >> RK got it right by following the example in the help page for mpfr: &

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread David Winsemius
t; Is this easy to do? > > Best, > Ravi > > From: David Winsemius > Sent: Friday, July 3, 2015 2:06 PM > To: John Nash > Cc: r-help; Ravi Varadhan > Subject: Re: [R] : Ramanujan and the accuracy of floating point computations >

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread Ravi Varadhan
ther than converting. > > JN > > On 15-07-03 06:00 AM, r-help-requ...@r-project.org wrote: > >> Message: 40 >> Date: Thu, 2 Jul 2015 22:38:45 +0000 >> From: Ravi Varadhan >> To: "'Richard M. Heiberger'" , Aditya Singh >> >>

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread David Winsemius
> On 15-07-03 06:00 AM, r-help-requ...@r-project.org wrote: > >> Message: 40 >> Date: Thu, 2 Jul 2015 22:38:45 + >> From: Ravi Varadhan >> To: "'Richard M. Heiberger'" , Aditya Singh >> >> Cc: r-help >> Subject: Re: [R]

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread John Nash
/www.wolframalpha.com/ > > I am not sure that the precedence matters in Rmpfr. Even if it does, the > answer you get is still wrong as you showed. > > Thanks, > Ravi > > -Original Message- > From: Richard M. Heiberger [mailto:r...@temple.edu] > Sent: Thursday

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread RK
Also when I try the following with Rmpfr, it works jut fine. > exp(sqrt(mpfr(163, 120)) * Const("pi", 120)) 1 'mpfr' number of precision 120 bits [1] 262537412640768743.25007601 and > exp(sqrt(mpfr(163, 400)) * Const("pi", 400)) 1 'mpfr' number of precision 400 bits [1] 2625

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-03 Thread Ravi Varadhan
accuracy of floating point computations - using Rmpfr in R There is a precedence error in your R attempt. You need to convert 163 to 120 bits first, before taking its square root. > exp(sqrt(mpfr(163, 120)) * mpfr(pi, 120)) 1 'mpfr' number of precision

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread Nordlund, Dan (DSHS/RDA)
it does, >the answer you get is still wrong as you showed. >> >> Thanks, >> Ravi >> >> -----Original Message- >> From: Richard M. Heiberger [mailto:r...@temple.edu] >> Sent: Thursday, July 02, 2015 6:30 PM >> To: Aditya Singh >> Cc: Ravi V

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread Jeff Newmiller
Thanks, >> Ravi >> >> -Original Message- >> From: Richard M. Heiberger [mailto:r...@temple.edu] >> Sent: Thursday, July 02, 2015 6:30 PM >> To: Aditya Singh >> Cc: Ravi Varadhan; r-help >> Subject: Re: [R] : Ramanujan and the accuracy of floating p

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread Richard M. Heiberger
Even if it does, the > answer you get is still wrong as you showed. > > Thanks, > Ravi > > -Original Message- > From: Richard M. Heiberger [mailto:r...@temple.edu] > Sent: Thursday, July 02, 2015 6:30 PM > To: Aditya Singh > Cc: Ravi Varadhan; r-help &g

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread Richard M. Heiberger
There is a precedence error in your R attempt. You need to convert 163 to 120 bits first, before taking its square root. > exp(sqrt(mpfr(163, 120)) * mpfr(pi, 120)) 1 'mpfr' number of precision 120 bits [1] 262537412640768333.51635812597335712954 ## just the last four characters to the left o

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread jim holtman
This is the standard FAQ 7.31 and then read in detail the referenced paper. Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Thu, Jul 2, 2015 at 2:02 PM, Aditya Singh via R-help < r-help@r-project.org> wrot

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread Aditya Singh via R-help
Ravi I am a chemical engineer by training. Is there not something like law of corresponding states in numerical analysis? Aditya -- On Thu 2 Jul, 2015 7:28 AM PDT Ravi Varadhan wrote: >Hi, > >Ramanujan supposedly discovered that the number, 163, has this interest

Re: [R] Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread Aditya Singh via R-help
Ravi 1. You may want to check the sqrt too. 2. Why not take log and try? Aditya -- On Thu 2 Jul, 2015 10:18 AM PDT Boris Steipe wrote: >Just a wild guess, but did you check exactly which operations are actually >done to high precision? Obviously you will need hi

Re: [R] Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread Jeff Newmiller
I don't know much about Rmpfr, but it doesn't look like your "pi" or "sqrt" or "exp" are being handled by that package, so I am not really seeing why your result should be more accurate when you have loaded that package. ---

Re: [R] Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread Boris Steipe
Just a wild guess, but did you check exactly which operations are actually done to high precision? Obviously you will need high-resolution representations of pi and e to get an improved result. B. On Jul 2, 2015, at 10:28 AM, Ravi Varadhan wrote: > Hi, > > Ramanujan supposedly discovered t

[R] Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-02 Thread Ravi Varadhan
Hi, Ramanujan supposedly discovered that the number, 163, has this interesting property that exp(sqrt(163)*pi), which is obviously a transcendental number, is real close to an integer (close to 10^(-12)). If I compute this using the Wolfram alpha engine, I get: 262537412640768743.25