Command-line Options

The herbie command has subcommands and options that influence both its user interface and the quality of its output.

Herbie commands

Herbie can be run both interactively and in batch mode, and can generate output intended either for the command line or the web. We call these different ways of running Herbie different tools. Herbie provides four tools:

herbie web
Use Herbie through your browser. The herbie web command runs Herbie on your local machine and opens your browser to its main page.
herbie shell
Use Herbie via a command-line shell. Enter an FPCore expression and Herbie will print its more-accurate version.
herbie improve input output
Run Herbie on the expressions in the file or directory input. The results are written to output, a single file in FPCore format.
herbie report input output
Run Herbie on the expressions in the file or directory input. The results are written to output, a directory of HTML reports. These pages can be viewed in any browser (though with a quirk for Chrome).

We recommend using web and report, which produce reports with lots of information about floating-point accuracy, including graphs it of error versus input values. This can help you understand whether Herbie's improvements matter for your use case.

Use herbie tool --help to available command-line options for a tool. This command also shows unsupported options not listed on this page.

General options

These options can be set on any tool. Pass them after the tool name but before other arguments, like this:

herbie report --timeout 60 in.fpcore out/

Arguments cannot go before options.

--seed S
The random seed, which changes the randomly-selected points that Herbie evaluates candidate expressions on. The seed is a number between 0 and 231 (exclusive both ends). This option can be used to make Herbie's results reproducible or to compare two different runs. Seeds are not preserved across runs.
--num-points N
The number of input points Herbie uses to evaluate candidate expressions. The default, 256, is a good balance for most programs. Increasing this option, say to 512 or 1024, will slow Herbie down but may make its results more consistent.
--num-iters N
The number of times Herbie attempts to improve accuracy. The default, 4, suffices for most programs and helps keep Herbie fast; in practice iterations beyond the first few rarely lead to lower error. Increase this option, say to 6, to check that there aren't further improvements that Herbie could seek out.
--num-analysis N
The number of input subdivisions to use when searching for valid input points. The default is 14. Increasing this option will slow Herbie down, but may fix the "Cannot sample enough valid points" error.
--timeout T
The timeout to use per-input, in seconds. A fractional number of seconds can be given.
--threads N (for the improve and report tools)
Enables multi-threaded operation. By default, no threads are used. A number can be passed to this option to use that many threads, or yes can be passed to tell Herbie to use all of the hardware threads.
--pareto
Enables multi-objective improvement. Herbie will attempt to simultaneously optimize for both accuracy and expression cost. Rather than generating a single "ideal" output expression, Herbie will generate many output expressions. This mode is still considered experimental. With this option, Herbie will take a long time to run. We recommend timeouts measured in hours.

Web shell options

The web tool runs Herbie and connects to it from your browser. It has options to control the underlying web server.

--port N
The port the Herbie server runs on. The default port is 8000.
--save-session dir
Save all the reports to this directory. The directory also caches previously-computed expressions.
--log file
Write an access log to this file, formatted like an Apache log. This log does not contain crash tracebacks.
--quiet
By default, but not when this option is set, a browser is automatically started to show the Herbie page. This option also shrinks the text printed on start up.
--public
When set, users on other computers can connect to the demo and use it. (In other words, the server listens on 0.0.0.0.). Essential when Herbie is run from Docker.

Rulesets

Herbie uses rewrite rules to change programs and improve accuracy. The --disable rules:group and --enable rules:group options turn rule sets on and off. In general, turning a ruleset on makes Herbie produce more accurate but more confusing programs.

The full list of rule groups is:

Rule GroupTopic of rewrite rules
arithmeticBasic arithmetic facts
polynomialsFactoring and powers
fractionsFraction arithmetic
exponentsExponentiation identities
trigonometryTrigonometric identities
hyperbolicHyperbolic trigonometric identities
boolsBoolean operator identities
branchesif statement simplification
specialThe gamma, Bessel, and error functions
numericsNumerical compounds expm1, log1p, fma, and hypot

Search options

These options change the types of transformations that Herbie uses to find candidate programs. We recommend sticking to the defaults.

Each option can be turned off with the -o or --disable command-line flag and on with +o or --enable. Turning an option off typically results in less-accurate results, while turning a option on typically results in more confusing output expressions.

precision:fallback
This option, on by default, tells Herbie to use fallback functions if a native implementation is not found for an operation (and print a warning). If turned off, operations with no native implementation will be disabled entirely. To our knowledge, this option only affects the Bessel functions on Windows.
setup:simplify
This option, on by default, simplifies the expression before passing it to Herbie. If turned off, Herbie will not simplify input programs before improving them.
generate:rr
This option, on by default, uses Herbie's recursive rewriting algorithm to generate candidate programs. If turned off, Herbie will use a non-recursive rewriting algorithm, which will substantially limit Herbie's creativity.
generate:taylor
This option, on by default, uses series expansion to produce new candidates during the main improvement loop. If turned off, Herbie will not use series expansion. Turn this option off if you want to avoid series-expansion-based rewrites, such as if you need to preserve the equivalence of the input and output expressions as real-number formulas.
generate:simplify
This option, on by default, simplifies candidates during the main improvement loop. If turned off, candidates will not be simplified, which typically results in much less accurate expressions.
reduce:regimes
This option, on by default, uses Herbie's regime inference algorithm to branch between several program candidates. If turned off, branches will not be inferred and the output program will be straight-line code (if the input was). Turn this option off if your programming environment makes branches very expensive, such as on a GPU.
reduce:avg-error
This option, on by default, causes Herbie to output the candidate with the best average error over the chosen inputs. If turned off, Herbie will choose the candidate with the least maximum error instead. This usually produces programs with worse overall accuracy. Turn this option off if worst-case accuracy is more important to you than overall accuracy.
reduce:binary-search
This option, on by default, uses binary search to refine the values used in inferred branches. If turned off, different runs of Herbie will be less consistent, and accuracy near branches will suffer.
reduce:branch-expressions
This option, on by default, allows Herbie to branch on expressions, not just variables. This slows Herbie down, particularly for large programs. If turned off, Herbie will only try to branch on variables.

Upgrading from Herbie 1.0

Herbie 1.0 used a different command line syntax, without multiple tools. Translate like so:

The new syntax somewhat changes Herbie's behavior, such as by using the input expression as the output if Herbie times out. It also makes it easier to write Herbie's output to a file without using command-line redirection.