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 18 alternatives:
Alternative
Accuracy
Speedup
Accuracy vs Speed
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.
\[\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\]
Simplified98.8%
\[\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]95.7%
\[ \left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\]
+-commutative [=>]95.7%
\[ \color{blue}{c \cdot i + \left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right)}
\]
fma-def [=>]96.8%
\[ \color{blue}{\mathsf{fma}\left(c, i, \left(x \cdot y + z \cdot t\right) + a \cdot b\right)}
\]
associate-+l+ [=>]96.8%
\[ \mathsf{fma}\left(c, i, \color{blue}{x \cdot y + \left(z \cdot t + a \cdot b\right)}\right)
\]
fma-def [=>]98.0%
\[ \mathsf{fma}\left(c, i, \color{blue}{\mathsf{fma}\left(x, y, z \cdot t + a \cdot b\right)}\right)
\]
fma-def [=>]98.8%
\[ \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.8%
\[\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
98.2%
Cost
19776
\[\mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b\right)\right)\right)
\]
Alternative 2
Accuracy
97.9%
Cost
13504
\[\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b + c \cdot i\right)\right)
\]
Alternative 3
Accuracy
98.0%
Cost
8260
\[\begin{array}{l}
\mathbf{if}\;c \cdot i + \left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) \leq \infty:\\
\;\;\;\;\left(x \cdot y + \mathsf{fma}\left(a, b, c \cdot i\right)\right) + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\end{array}
\]
Alternative 4
Accuracy
98.0%
Cost
7748
\[\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}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\end{array}
\]
Alternative 5
Accuracy
97.6%
Cost
7492
\[\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, a \cdot b + \left(c \cdot i + z \cdot t\right)\right)\\
\end{array}
\]
Alternative 6
Accuracy
65.0%
Cost
2269
\[\begin{array}{l}
t_1 := a \cdot b + x \cdot y\\
t_2 := a \cdot b + z \cdot t\\
t_3 := a \cdot b + c \cdot i\\
\mathbf{if}\;c \cdot i \leq -5.4 \cdot 10^{+191}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;c \cdot i \leq -1.2 \cdot 10^{+80}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -2.3 \cdot 10^{-116}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq -2.15 \cdot 10^{-145}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 1.25 \cdot 10^{+59} \lor \neg \left(c \cdot i \leq 4.4 \cdot 10^{+112}\right) \land c \cdot i \leq 9.25 \cdot 10^{+153}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}
\]
Alternative 7
Accuracy
64.9%
Cost
2269
\[\begin{array}{l}
t_1 := a \cdot b + x \cdot y\\
t_2 := a \cdot b + z \cdot t\\
\mathbf{if}\;c \cdot i \leq -1.6 \cdot 10^{+191}:\\
\;\;\;\;c \cdot i + z \cdot t\\
\mathbf{elif}\;c \cdot i \leq -8.2 \cdot 10^{+78}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -5.4 \cdot 10^{-114}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-147}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 5.5 \cdot 10^{+60} \lor \neg \left(c \cdot i \leq 1.4 \cdot 10^{+110}\right) \land c \cdot i \leq 9.25 \cdot 10^{+153}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + c \cdot i\\
\end{array}
\]
Alternative 8
Accuracy
64.7%
Cost
2268
\[\begin{array}{l}
t_1 := a \cdot b + x \cdot y\\
t_2 := a \cdot b + z \cdot t\\
\mathbf{if}\;c \cdot i \leq -4.9 \cdot 10^{+191}:\\
\;\;\;\;c \cdot i + z \cdot t\\
\mathbf{elif}\;c \cdot i \leq -1.8 \cdot 10^{+80}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -4.6 \cdot 10^{-114}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq -2.05 \cdot 10^{-147}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 3.3 \cdot 10^{+61}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 2.2 \cdot 10^{+114}:\\
\;\;\;\;a \cdot b + c \cdot i\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{+160}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + x \cdot y\\
\end{array}
\]
Alternative 9
Accuracy
97.6%
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}
\]
\[\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -6 \cdot 10^{+193}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;c \cdot i \leq -9 \cdot 10^{+79}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;c \cdot i \leq 7 \cdot 10^{+163}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;c \cdot i\\
\end{array}
\]
Alternative 15
Accuracy
85.4%
Cost
1224
\[\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1.7 \cdot 10^{+191}:\\
\;\;\;\;c \cdot i + z \cdot t\\
\mathbf{elif}\;c \cdot i \leq 5.1 \cdot 10^{+163}:\\
\;\;\;\;a \cdot b + \left(x \cdot y + z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + x \cdot y\\
\end{array}
\]
Alternative 16
Accuracy
86.0%
Cost
1224
\[\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1.85 \cdot 10^{+191}:\\
\;\;\;\;c \cdot i + \left(a \cdot b + z \cdot t\right)\\
\mathbf{elif}\;c \cdot i \leq 3.2 \cdot 10^{+160}:\\
\;\;\;\;a \cdot b + \left(x \cdot y + z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + x \cdot y\\
\end{array}
\]
herbie shell --seed 2023272
(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)))