| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 6976 |
\[x \cdot \mathsf{fma}\left(x, 3, x \cdot \left(x \cdot -2\right)\right)
\]

(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
(FPCore (x) :precision binary64 (* x (fma x 3.0 (* x (* x -2.0)))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
double code(double x) {
return x * fma(x, 3.0, (x * (x * -2.0)));
}
function code(x) return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) end
function code(x) return Float64(x * fma(x, 3.0, Float64(x * Float64(x * -2.0)))) end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * N[(x * 3.0 + N[(x * N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x, 3, x \cdot \left(x \cdot -2\right)\right)
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 99.8% |
|---|---|
| Target | 99.8% |
| Herbie | 99.8% |
Initial program 99.8%
Simplified99.9%
[Start]99.8% | \[ \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\] |
|---|---|
associate-*l* [=>]99.9% | \[ \color{blue}{x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)}
\] |
Applied egg-rr99.9%
[Start]99.9% | \[ x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)
\] |
|---|---|
sub-neg [=>]99.9% | \[ x \cdot \left(x \cdot \color{blue}{\left(3 + \left(-x \cdot 2\right)\right)}\right)
\] |
distribute-lft-in [=>]99.8% | \[ x \cdot \color{blue}{\left(x \cdot 3 + x \cdot \left(-x \cdot 2\right)\right)}
\] |
fma-def [=>]99.9% | \[ x \cdot \color{blue}{\mathsf{fma}\left(x, 3, x \cdot \left(-x \cdot 2\right)\right)}
\] |
distribute-rgt-neg-in [=>]99.9% | \[ x \cdot \mathsf{fma}\left(x, 3, x \cdot \color{blue}{\left(x \cdot \left(-2\right)\right)}\right)
\] |
metadata-eval [=>]99.9% | \[ x \cdot \mathsf{fma}\left(x, 3, x \cdot \left(x \cdot \color{blue}{-2}\right)\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 6976 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 713 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 576 |
| Alternative 4 | |
|---|---|
| Accuracy | 61.4% |
| Cost | 320 |
| Alternative 5 | |
|---|---|
| Accuracy | 3.1% |
| Cost | 192 |
| Alternative 6 | |
|---|---|
| Accuracy | 2.5% |
| Cost | 64 |
herbie shell --seed 2023167
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:herbie-target
(* x (* x (- 3.0 (* x 2.0))))
(* (* x x) (- 3.0 (* x 2.0))))