Let HERBIE Make Your Floating Point Better
Written by Mike James   
Tuesday, 26 January 2016

A new tool from the University of Washington will take your floating point expressions and convert them into something that does the same calculation, but more accurately. This is worth knowing about.


Floating point arithmetic is at the heart of a lot of computation, and especially in science and engineering. Most of the time, floating point does a good job, but because of the way that it works it usually entails some inaccuracy due to rounding errors. 

For example, if you try to add a very small number to a very large number then it is possible that the small number will be rounded to zero and your calculation becomes a+0 not a+something small. This sort of problem can even make algorithms fail. For example, if you add small values to a large value in a loop which stops when the large value is greater than a set limit then the loop might never end if rounding errors reduce the small values to effectively zero. 

However, if you arrange to add all the small values together and then add the bigger value that results to the bigger value you get a much smaller total error. With floating point arithmetic you can often improve the accuracy by altering the way the expression is written. 

If you are a programmer who occasionally works with floating point values that are problematic then you, at best, learn a few simple rules to protect yourself from this sort of thing. For example, don't ever test for equality of values, only use greater than and less than. Don't add small things to big things and so on. The problem is for any particular floating point expression, you can't be sure that your home spun rules are going to be good enough. 

Now you can ask HERBIE to try to find an alternative expression that reduces the rounding error. You provide the expression and HERBIE then uses a range of heuristic search techniques to find rewrites that reduce the error. It tests the expression with a range of floating point values and empirically determines the error. It can find rewrites that have good effects in different numerical ranges and combines these to produce a single result that works well.  

To demonstrate how good HERBIE is, the developers applied it to 28 test cases from Richard Hamming's Numerical Methods for Scientists and Engineers with impressive improvements:



Longer arrows are better. Each arrow measures an improvement in accuracy due to Herbie. Each arrow points from the accuracy of the original program, and to the accuracy of Herbie’s output, in each case on random double-precision inputs.

If you just want to try it out there is a web demo, but this has many drawbacks compared to the full program which you can download and install. 


More Information


Related Articles

GNU Octave 4

NAG Library Extended

CheckCell Detects Bugs In Spreadsheets

MathJS A Math Library For JavaScript

Free Sage Math Cloud - Python And Symbolic Math


To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on, Twitter, FacebookGoogle+ or Linkedin



Kotlin 2 Released With Multiplatform K2 Compiler

Kotlin 2.0 has been released. The new version is a major update with improvements including a stable K2 compiler, which is multiplatform from the ground up, and according to JetBrains understands your [ ... ]

SQL Turns 50

The first release of SQL was in June 1974. Designed at IBM by Donald D. Chamberlin and Raymond F. Boyce, it was based on the relational model proposed by E.F. Codd. SQL became the most widely used dat [ ... ]

More News


C book



or email your comment to: comments@i-programmer.info




Last Updated ( Tuesday, 26 January 2016 )