The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.
Herbie found 15 alternatives:
Alternative
Accuracy
Speedup
Accuracy vs Speed
The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.
\[\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\]
Simplified98.4%
\[\leadsto \color{blue}{\mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b\right)\right)\right)}
\]
Step-by-step derivation
[Start]93.3
\[ \left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\]
+-commutative [=>]93.3
\[ \color{blue}{c \cdot i + \left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right)}
\]
fma-def [=>]96.1
\[ \color{blue}{\mathsf{fma}\left(c, i, \left(x \cdot y + z \cdot t\right) + a \cdot b\right)}
\]
associate-+l+ [=>]96.1
\[ \mathsf{fma}\left(c, i, \color{blue}{x \cdot y + \left(z \cdot t + a \cdot b\right)}\right)
\]
fma-def [=>]96.9
\[ \mathsf{fma}\left(c, i, \color{blue}{\mathsf{fma}\left(x, y, z \cdot t + a \cdot b\right)}\right)
\]
fma-def [=>]98.4
\[ \mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, \color{blue}{\mathsf{fma}\left(z, t, a \cdot b\right)}\right)\right)
\]
Final simplification98.4%
\[\leadsto \mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b\right)\right)\right)
\]
Alternatives
Alternative 1
Accuracy
97.2%
Cost
7753
\[\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -\infty \lor \neg \left(c \cdot i \leq 5 \cdot 10^{+271}\right):\\
\;\;\;\;\mathsf{fma}\left(c, i, x \cdot y + z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z \cdot t\right) + \left(a \cdot b + c \cdot i\right)\\
\end{array}
\]
Alternative 2
Accuracy
96.8%
Cost
7752
\[\begin{array}{l}
t_1 := x \cdot y + z \cdot t\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+247}:\\
\;\;\;\;\mathsf{fma}\left(c, i, t_1\right)\\
\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+286}:\\
\;\;\;\;c \cdot i + \left(a \cdot b + t_1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z \cdot t\right)\\
\end{array}
\]
Alternative 3
Accuracy
64.9%
Cost
2268
\[\begin{array}{l}
t_1 := a \cdot b + c \cdot i\\
t_2 := x \cdot y + z \cdot t\\
t_3 := c \cdot i + x \cdot y\\
\mathbf{if}\;a \cdot b \leq -3.2 \cdot 10^{+172}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;a \cdot b \leq -7.2 \cdot 10^{+38}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;a \cdot b \leq -3.7:\\
\;\;\;\;t_1\\
\mathbf{elif}\;a \cdot b \leq -1.9 \cdot 10^{-307}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;a \cdot b \leq 6.3 \cdot 10^{-308}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;a \cdot b \leq 2.45 \cdot 10^{-197}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;a \cdot b \leq 1.55 \cdot 10^{+36}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\end{array}
\]
\[\begin{array}{l}
t_1 := c \cdot i + z \cdot t\\
t_2 := a \cdot b + x \cdot y\\
t_3 := c \cdot i + x \cdot y\\
\mathbf{if}\;a \cdot b \leq -1.1 \cdot 10^{+40}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;a \cdot b \leq -6 \cdot 10^{-307}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;a \cdot b \leq 0:\\
\;\;\;\;t_3\\
\mathbf{elif}\;a \cdot b \leq 1.1 \cdot 10^{-198}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;a \cdot b \leq 5.6 \cdot 10^{+50}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;a \cdot b \leq 1.12 \cdot 10^{+114}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\]
Alternative 6
Accuracy
97.3%
Cost
1988
\[\begin{array}{l}
t_1 := c \cdot i + \left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right)\\
\mathbf{if}\;t_1 \leq \infty:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\end{array}
\]
herbie shell --seed 2023160
(FPCore (x y z t a b c i)
:name "Linear.V4:$cdot from linear-1.19.1.3, C"
:precision binary64
(+ (+ (+ (* x y) (* z t)) (* a b)) (* c i)))