ISReal: A C++ Library for Floating-point Computation with Controlled Error

Introduction

ISReal, a C++ library, for floating-point computation with controlled error. Given a floating-point expression f and an expected upper bound of error e, ISReal automatically and dynamically adjusts precisions of all intermediate computations to produce the result y such that |y-f|<e. ISReal could potentially be combined with existing approaches for floating-point programs analysis to provide more informed result [1,2].

ISReal relies on GNU MP for big integer computation. ISReal supports the following operations with degree and radian modes for (inverse) trigonometric functions:

Example

Let us consider the expression f1 from [4]
f1=333.75b6+a2(11a2b2b6121b42)+5.5b8+a2b
where a = 77617.01, b=33096.0.

Its actual value: -0.82739605994682136814116509579816....

In ISReal form, it is:
333.75*33096.0^6+77617.0^2*(11*77617.0^2*33096.0^2-33096.0^6-121*33096.0^4-2) +5.5*33096.0^8+77617.0(2*33096.0)

Download

All the following tools have been tested on Windows XP/7/8. To build source code, we recommand to use Microsoft Visual Studio 2010 or later versions.

Usage of the library

To use our library real.dll, you have to link gmp.dll and real.dll, and include the head file real.h. real.h defines a type real and contains the the following 12 functions for computing, and a function for output. Here, the angles involved in calcs are in radians, and that of calcds are in degrees.

  1. The following 4 functions first calculate the values of the expression in str, and then assigns the results to r.
    1.1 real &calc(real &r, expr string4) &str); // correct to 10 decimal places
    1.2 real &calc(real &r, expr string &str, int n); // correct to n decimal places
    1.3 real &calcd(real &r, expr string &str); // correct to 10 decimal places
    1.4 real &calcd(real &r, expr string &str, int n); // correct to n decimal places
  2. The following 4 functions calculate the values of the expression in r, and the results are still in r.
    2.1 real &calc(real &r); // correct to 10 decimal places
    2.2 real &calc(real &r, int n); // correct to n decimal places
    2.3 real &calcd(real &r); // correct to 10 decimal places
    2.4 real &calcd(real &r, int n); // correct to n decimal places
  3. The following 4 functions calculate the values of the expression stored in the variable pointed to by str first, and then assigns the results
    to r.
    3.1 real &calc(real &r, char str); // correct to 10 decimal places
    3.2 real &calc(real &r, char
    str, int n); // correct to n decimal places
    3.3 real &calcd(real &r, char str); // correct to 10 decimal places
    3.4 real &calcd(real &r, char
    str, int n); // correct to n decimal places

    The ISReal GUI-based calculator demonstrates how to use real.dll.

Experiments

We conduct an experimental study to check accuracy and scalability using following expressions:

f1, f3 and f4 are token from [3,4], while others are manually created whose actual values are determined by axioms. The experiments were conducted on Win8 for ISReal. C++ programs using standard library (i.e., math.h) were also implemented to compute these expressions both on Win8 using VS2012 and Ubuntu using GCC 6.2.0 with all available precisions. C++ programs using MPFR [3] with precision 10000 bits and round to nearest mode on Ubuntu. Matlab R2012a and Maple 15 were tested with 16 significant bits. All the tested programs are available in Download Section.

Figure1

The results are shown in the above Table. We only present 10 significant digits of the results for C++ programs when they are sufficient to reveal inaccuracy. To analyze scalability of ISReal, we consider all the expressions f1,...,f15 parametrised by the precision n, where n ranges between 0 and 500 with step of 10. The results are shown in the following Figure.

Figure1

Reference

  1. Shizhong Zhao. 2016. A reliable computing algorithm and its software ISReal for arithmetic expressions (in Chinese). SCIENTIA SINICA Informationis 46, 6 (2016), 698–713.
  2. Shizhong Zhao and Fu Song. 2017. A reliable computing algorithm and its software ISReal for arithmetic expressions. Technical Report. East China Normal University, ShanghaiTech University.
  3. Paul Zimmermann. 2010. Reliable computing with GNU MPFR. In International Congress on Mathematical Software. Springer, 42–
  4. Siegfried M. Rump. 1988. Reliability in Computing: The Role of Interval Methods in Scientific Computing. Boston: Academic Press, Chapter Algorithms for verified inclusion: theory and practice, 109–126.
  5. Jean-Michel Muller, Nicolas Brisebarre, Florent de Dinechin, Claude-Pierre Jeannerod, Vincent Lefèvre, Guillaume Melquiond, Nathalie Revol, Damien Stehlé, and Serge Torres. 2010. Handbook of Floating-Point Arithmetic. Birkhäuser.
  6. Eugene Loh and G. William Walster. 2002. Rump’s Example Revisited. Reliable Computing 8, 3 (2002), 245–248.

Copyright © 2017-2018 Fu Song and Shizhong Zhao.