Re: [R] MASS::mvrnorm() on MKL may produce different numbers even when the seed is the same?

2023-08-18 Thread Martin Maechler
> Bill Dunlap > on Thu, 17 Aug 2023 07:31:12 -0700 writes: > MKL's results can depend on the number of threads running and perhaps other > things. They blame it on the non-associativity of floating point > arithmetic. This article gives a way to make results repeatable:

Re: [R] X11 font

2023-08-18 Thread Ivan Krylov
В Wed, 16 Aug 2023 16:08:57 -0500 "Therneau, Terry M., Ph.D. via R-help" пишет: > I get the following error out of R, on a newer Ubuntu installation. > ! X11 font -adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*, face 1 at > size 12 could not be loaded > Version: > R Under development (unstable) (20

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-18 Thread Leonard Mada via R-help
Dear Martin, Thank you very much for your analysis. I add only a small comment: - the purpose of the modified formula was to apply l'Hospital; - there are other ways to transform the formula; although applying l'Hospital once is probably more robust than simple transformations (but the computa

Re: [R] MASS::mvrnorm() on MKL may produce different numbers even when the seed is the same?

2023-08-18 Thread Rolf Turner
On Fri, 18 Aug 2023 12:17:51 +0200 Martin Maechler wrote: > I think it would be nice to provide the average R user with a > (possibly super small) R package that allows to turn on (and off) > such CNR reproducibility. Would it be possible to effect this on/off via options()? cheers, Rolf

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-18 Thread Leonard Mada via R-help
I have added some clarifications below. On 8/18/2023 10:20 PM, Leonard Mada wrote: [...] After more careful thinking, I believe that it is a limitation due to floating points: [...] The problem really stems from the representation of 1 - x^2/2 as shown below: x = 1E-4 print(1 - x^2/2, digit

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-18 Thread Bert Gunter
"The ugly thing is that the error only gets worse as x decreases. The value neither drops to 0, nor does it blow up to infinity; but it gets worse in a continuous manner." If I understand you correctly, this is wrong: > x <- 2^(-20) ## considerably less then 1e-4 !! > y <- 1 - x^2/2; > 1/(1 - y)

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-18 Thread Leonard Mada via R-help
Dear Bert, Values of type 2^(-n) (and its binary complement) are exactly represented as floating point numbers and do not generate the error. However, values away from such special x-values will generate errors: # exactly represented: x = 9.53674316406250e-07 y <- 1 - x^2/2; 1/(1 - y) - 2/x^2

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-18 Thread Bert Gunter
"Values of type 2^(-n) (and its binary complement) are exactly represented as floating point numbers and do not generate the error. However, values away from such special x-values will generate errors:" That was exactly my point: The size of errors depends on the accuracy of binary representation

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-18 Thread Leonard Mada via R-help
Dear Bert, On 8/19/2023 2:47 AM, Bert Gunter wrote: > "Values of type 2^(-n) (and its binary complement) are exactly > represented as floating point numbers and do not generate the error. > However, values away from such special x-values will generate errors:" > > That was exactly my point: The

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-18 Thread avi.e.gross
This discussion is sooo familiar. If you want indefinite precision arithmetic, feel free to use a language and data type that supports it. Otherwise, only do calculations that fit in a safe zone. This is not just about this scenario. Floating point can work well when adding (or subtracting) tw

Re: [R] Numerical stability of: 1/(1 - cos(x)) - 2/x^2

2023-08-18 Thread Bert Gunter
"Are there any good indefinite (or much higher) precision packages" A simple search on "arbitrary precision arithmetic in R" would have immediately gotten you to the Rmpfr package. See also: https://cran.r-project.org/web/packages/Ryacas/vignettes/arbitrary-precision.html -- Bert On Fri, Aug 18