Using Herbie from the Browser

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 browser.

The Herbie web shell

The Herbie web shell lets you interact with Herbie through your browser, featuring a convenient input format. Run the Herbie web shell:

herbie web

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.
The input page for the web shell.

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.

Herbie improvement in progress.

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.

Batch report generation

A report can also be generated directly from a file of input expressions:

$ herbie report input.fpcore output/
Starting Herbie on 3 problems...
Seed: 921081490
  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 expressions in input.fpcore and save the report in the directory output/, which ought not exist yet. The printed seed can be used to reproduce a run of Herbie.

Once generated, open the output/report.html page 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.

Input expressions

An example input file can be found in bench/tutorial.fpcore:

(FPCore (x)
  :name "Cancel like terms"
  (- (+ 1 x) x))

(FPCore (x)
  :name "Expanding a square"
  (- (* (+ x 1) (+ 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:

You can check out our input format documentation for more about the Herbie input format.