Arbitrarily Accurate Computation with R: Package ’Rmpfr’

Corrected abstract for “late-breaking poster” and “Lightning talk” to be held at “UseR! 2011”, U. Warwick, 16th Aug. 2011
 

Martin Mächler1,2,⋆

1. ETH Zurich (Seminar for Statistics), Switzerland
2. R Core Development Team
⋆Contact author: maechler@stat.math.ethz.ch

Keywords:

Arbitrary Precision, High Accuracy, Multiple Precision Floating-Point, Rmpfr

The R package Rmpfr allows to use arbitrarily precise numbers instead of R’s double precision numbers in many R computations and functions.

This is achieved by defining S4 classes of such numbers and vectors, matrices, and arrays thereof, where all arithmetic and mathematical functions work via the (GNU) MPFR C library, where MPFR is acronym for “Multiple Precision Floating-Point Reliably”. MPFR is Free Software, available under the LGPL license, and itself is built on the free GNU Multiple Precision arithmetic library (GMP).

Consequently, by using Rmpfr, you can often call your R function or numerical code with mpfr–numbers instead of simple numbers, and all results will automatically be much more accurate.

> options(digits = 17)# to print to full "standard R" precision> .N <- function(.) mpfr(., precBits = 200)> exp( 1 )

[1] 2.7182818284590451

> exp(.N(1))

1 'mpfr' number of precision 200 bits[1] 2.7182818284590452353602874713526624977572470936999595749669679Applications by the package author include testing of Bessel or polylog functions and distribution computations, e.g. for stable distributions. In addition, the Rmpfr has been used on the R-help or R-devel mailing list for high-accuracy computations, e.g., in comparison with results from commercial software such as Maple, and in private communications with Petr Savicky about fixing R bug PR#14491.

We expect the package to be used in more situations for easy comparison studies about the accuracy of algorithms implemented in R, both for “standard R” and extension packages.

References

  • Fousse et al. (2007) L. Fousse, G. Hanrot, V. Lefèvre, P. Pélissier, and P. Zimmermann MPFR: a multiple-precision binary floating-point library with correct rounding. ACM Trans. Math. Softw. 33 (2), pp. 13. External Links: ISSN 0098-3500, Link
  • Fousse et al. (2011) L. Fousse, G. Hanrot, V. Lefèvre, P. Pélissier, and P. Zimmermann MPFR: a multiple-precision binary floating-point library with correct rounding. External Links: Link
  • Granlund and the GMP development team (2011) T. Granlund and the GMP development team GNU mp - the gnu multiple precision arithmetic library. External Links: Link
  • Maechler (2011) M. Maechler Rmpfr: r mpfr - multiple precision floating-point reliable. Note: R package version 0.4-2 External Links: Link