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:
Special constants: e and pi;
Elementary operations: +, -, *, and /;
Trigonometry: sin, cos, tan, cot, sec and csc;
Inverse trigonometry: arcsin, arccos, arctan and arccot;
Logarithm and exponent: ln, log and ^;
Hyperbolic functions: sinh and cosh;
Rounding: floor and ceil;
Factorial: !.
Example
Let us consider the expression f1 from [4] f1=333.75b6+a2(11a2b2−b6−121b4−2)+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)
The results of our tool ISReal under three precisions 8, 16 and 20 were:
8 Precision: −0.82739606
16 Precision: −0.8273960599468214
20 Precision: −0.82739605994682136814
On an IBM S/370 computer, the results obtained by Rump 4] using Fortran program were:
single: 1.172603...
double: 1.1726039400531...
extended: 1.172603940053178...
On a Pentium4-based workstation, using GCC and the Linux system were [5]:
single: 2.0317×1029;
double: 5.960604×1020;
double-extended: −9.38724×10−323.
The results in the Forte Developer 6 Update 2 Fortran 95 compiler (IEEE 754) from Sun Microsystems Inc. were [6]:
single: −6.338253×1029;
double: −1.1805916207174113×1021;
quadruple: 1.1726039400531786318588349045201838.
The results on Windows 8.1 with 8GB RAM and AMD64 CPU A10-6700 3.70GHz (Win8 for short) using Microsoft VS2012 were (using all modes: precise, precise, fast, long double is mapped to double in Microsoft VS 2012):
single: −9.8750123322992547×1029;
double: −1.1805916207174113×1021.
The results on Ubuntu 16.10 and Intel CORE i7 (Ubuntu for short) using GCC 6.2.0 were:
single: −9.8750123322992547249669537792×1029;
double: −1.180591620717411303424×1021;
long double: 5.764607523034234891875×1017.
Maple 15 under three significant digits: 8, 16 and 20, the results were:
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.
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
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
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.
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.
Reference
Shizhong Zhao. 2016. A reliable computing algorithm and its software ISReal for arithmetic expressions (in Chinese). SCIENTIA SINICA Informationis 46, 6 (2016), 698–713.
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.
Paul Zimmermann. 2010. Reliable computing with GNU MPFR. In International Congress on Mathematical Software. Springer, 42–
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.
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.
Eugene Loh and G. William Walster. 2002. Rump’s Example Revisited. Reliable Computing 8, 3 (2002), 245–248.