Herbie's input format is designed for expressing mathematical functions, which Herbie can then search for accurate implementations of. It also allows specifying the distribution that Herbie draws inputs from when evaluating the accuracy of an expression.
The general format of an input expression is:
(herbie-test (inputs ...) "title" expression)
Each input is a variable, like
x, or a variable and a
The title is any text that describes the expression and the input
is the expression to improve the accuracy of.
The expression is written in prefix form, with every function call parenthesized, as in Lisp. For example, the formula for the hypotenuse of a triangle with legs a and b is
(herbie-test (a b) "hypotenuse" (sqrt (+ (sqr a) (sqr b))))
The full list of supported functions and is as follows:
-is both negation and subtraction
atan2is the two-argument inverse tangent
Herbie allows the
/ functions to be passed more than two arguments,
and all of these functions are taken as left-associative.
Herbie allows conditional expressions
(if cond a b) evaluates the
cond and returns either
it is true or
b if it is not. Conditionals may use:
Intermediate variables can be defined using
(let* ([variable value] ...) body)
Each variable is bound to the associated value, in order, with later values allowed to reference prior values. All the defined values are bound in the body. Note that Herbie treats these intermediate values only as a notational convenience, and inlines their values before improving the formula's accuracy.
Herbie also supports the constants
Herbie allows each variable to specify the distribution it is drawn from. These distributions can be:
(uniform a b)
Each of these distributions can also be modified:
(< a dist b)