Herbie is a tool that automatically rewrites floating-point expressions to improve their numerical accuracy. This walkthrough covers installing and launching Herbie's web interface, running a built-in example to see how it improves accuracy, and then applying it to a real-world bug in the math.js JavaScript library involving inaccurate complex number square roots. The tutorial explains how to extract the mathematical core from source code, inline intermediate variables, split branches, and interpret Herbie's results including accuracy graphs and multiple alternatives. It also shows how to integrate Herbie's suggested rewrite (using hypot and conditional branches to avoid cancellation) back into the original codebase.

8m read timeFrom herbie.uwplse.org
Post cover image
Table of contents
Giving Herbie expressionsProgramming with HerbieFinding the problematic expressionConverting problematic code to Herbie inputHerbie's resultsUsing Herbie's alternativesNext steps

Sort: