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.

Herbie can be used from the command-line or from the browser. This page covers using Herbie from the command line.

Herbie takes file and command-line input
in FPCore syntax. You can find example
FPCore files in the `bench/`

directory in the source
code. For example, `bench/tutorial.fpcore`

contains:

(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”

The input format documentation contains more details.

The Herbie shell lets you interact with Herbie, typing in benchmark expressions and seeing the outputs. Run the Herbie shell:

herbie shell

After a few seconds, Herbie will start up and wait for input:

herbie shell Herbie 1.3 with seed 2098242187 Find help on https://herbie.uwplse.org/, exit with Ctrl-D herbie>

The printed seed can be used to reproduce a Herbie run. You can now paste inputs directly into your terminal for Herbie to improve:

herbie>(FPCore (x) :name "Cancel like terms" (- (+ 1 x) x)) (FPCore (x)...1.0)

The output suggests the expression `1`

as a more
accurate variant of the original expression. Note that
the `...` hides lots
of additional
information from Herbie, including error estimates and runtime
information.

The Herbie shell makes it easy to play with different expressions and try multiple variants, informed by Herbie's advice.

Alternatively, you can run Herbie on a file with multiple expressions in it, producing the output expressions to a file. This mode is intended for use by scripts.

herbie improve bench/tutorial.fpcore out.fpcore Starting Herbie on 3 problems (seed: 1809676410)... 1/3 [ 2.202s] 29→ 0 Cancel like terms 2/3 [ 14.875s] 39→ 0 Expanding a square 3/3 [ 8.546s] 0→ 0 Commute and associate

The output file `out.fpcore`

contains more accurate
versions of each program:

;; seed: 1809676410 (FPCore (x)...1.0) (FPCore (x)...(+ (* x x) (* 2.0 x))) (FPCore (x y z)...0.0)

Note that the order of expressions is identical. For more control over Herbie, see the documentation of Herbie's command-line options.