Herbie rewrites floating point expressions to make them more accurate. The expressions could come from anywhere—your source code, mathematical papers, or even the output of Herbgrind, our tool for finding inaccurate expressions in binaries. This tutorial runs Herbie on the benchmark programs that Herbie ships with.
Herbie can be used from the command-line and from the browser. This page covers using Herbie from the command line.
The Herbie web shell lets you interact with Herbie through your browser, featuring a convenient input format. Run the Herbie web shell:
After a few seconds, the web shell will rev up and direct your browser to the main web shell page:
$ herbie web Your Web application is running at http://localhost:8000/. Stop this program at any time to terminate the Web Server.
As in the screenshot, you can type expressions, in standard mathematical syntax (parsed by Math.js), and hit Enter to have Herbie attempt to improve them.
The web shell will print Herbie's progress, and redirect to a report once Herbie is done.
Interactive use of the web shell is the friendliest and easiest way to use Herbie. The web shell has many options, including automatically saving the generated reports.
A report can also be generated directly from a file of input expressions:
$ herbie report input.fpcore output/ Starting Herbie on 3 problems... Seed: #(327732824 4211992217 3609811086 1098847098 2827724810 3610427321) 1/3 [ 7108.190ms] (39→ 0) Expanding a square 2/3 [ 1894.348ms] ( 0→ 0) Commute and associate 3/3 [ 873.3889ms] (29→ 0) Cancel like terms
This command asks Herbie to generate a report from the input
input.fpcore and save the report in
output/, which ought not exist yet.
The printed seed can be used to reproduce a run of Herbie.
Once generated, open the
in your favorite browser (but see the FAQ
if you're using Chrome). From that page, you can click on the rows
in the table at the bottom to see the report for that expression.
Batch report generation is the most informative way to run Herbie on a large collection of inputs. Like the web shell, it can be customized through command-line options, including running Herbie in multiple threads at once.
An example input file can be found in
(FPCore (x) :name "Cancel like terms" (- (+ 1 x) x)) (FPCore (x) :name "Expanding a square" (- (sqr (+ x 1)) 1)) (FPCore (x y z) :name "Commute and associate" (- (+ (+ x y) z) (+ x (+ y z))))
This code defines three floating point expressions that we want to run Herbie on:
(1 + x) - x, titled “Cancel like terms”
(x + 1)² - 1, titled “Expanding a square”
((x + y) + z) - (x + (y + z)), titled “Commute and associate”
You can check out our input format documentation for more about the Herbie input format.