Herbie: Automatically improve imprecise floating point formulas

Herbie is a tool that automatically rewrites floating-point expressions to improve their accuracy and performance, helping developers fix mysterious numerical inaccuracies.
Herbie rewrites floating point expressions to make them more accurate. Floating point arithmetic is inaccurate; even 0.1 + 0.2 != 0.3 in floating-point. Herbie helps find and fix these mysterious inaccuracies.
To get started, download and install Herbie. You're then ready to begin using it. Start Herbie with racket -l herbie web. After a brief wait, your web browser should open and show you Herbie's main window.
Let's start by looking at an example: sqrt(x + 1) - sqrt(x) with x ranging from 0 to 1.79e308. After clicking "Improve with Herbie", you'll see results showing that Herbie's most accurate alternative has an accuracy of 99.7%, much better than the initial 53.2%, and is also 1.9x faster.
You can use Herbie on expressions from source code, mathematical models, or debugging tools. For instance, in bug 208 of math.js, Herbie was used to fix inaccurate square roots for complex numbers. By extracting the mathematical kernel and feeding it to Herbie, developers can identify where accuracy drops (e.g., when inputs exceed 1e150).
Herbie's suggested alternatives often use if statements to handle cancellation and functions like hypot to compute distances more accurately. The tool even allows translating the output directly into languages like JavaScript for easy integration.
Source: Hacker News












