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.

herbielogo

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:

 

herbie1

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. 

herbielogo

More Information

HERBIE

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

 

Banner


Meta Releases OpenSource Podcast Generating Tool
28/11/2024

Meta has released an open source project that can be used to automatically convert a PDF file into a podcast. Meta says Notebook Llama can be considered an open-source version of Google's NotebookLM.

 [ ... ]



CSS Ecosystem In the Spotlight
06/11/2024

The 2024 edition of the State of CSS has been posted, revealing that the latest features of the language not only do away with extra tooling, but even start taking on tasks that previously requir [ ... ]


More News

 

espbook

 

Comments




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

 

 

 

Last Updated ( Tuesday, 26 January 2016 )