| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 13120 |
\[\mathsf{fma}\left(x, 3, \mathsf{fma}\left(y, 2, z\right)\right)
\]

(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
(FPCore (x y z) :precision binary64 (fma x 3.0 (fma y 2.0 z)))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
double code(double x, double y, double z) {
return fma(x, 3.0, fma(y, 2.0, z));
}
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function code(x, y, z) return fma(x, 3.0, fma(y, 2.0, z)) end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
code[x_, y_, z_] := N[(x * 3.0 + N[(y * 2.0 + z), $MachinePrecision]), $MachinePrecision]
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\mathsf{fma}\left(x, 3, \mathsf{fma}\left(y, 2, z\right)\right)
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 99.9%
Simplified100.0%
[Start]99.9% | \[ \left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\] |
|---|---|
+-commutative [=>]99.9% | \[ \color{blue}{x + \left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right)}
\] |
+-commutative [=>]99.9% | \[ x + \left(\color{blue}{\left(x + \left(\left(x + y\right) + y\right)\right)} + z\right)
\] |
associate-+l+ [=>]99.9% | \[ x + \left(\left(x + \color{blue}{\left(x + \left(y + y\right)\right)}\right) + z\right)
\] |
associate-+r+ [=>]99.9% | \[ x + \left(\color{blue}{\left(\left(x + x\right) + \left(y + y\right)\right)} + z\right)
\] |
count-2 [=>]99.9% | \[ x + \left(\left(\color{blue}{2 \cdot x} + \left(y + y\right)\right) + z\right)
\] |
associate-+l+ [=>]99.9% | \[ x + \color{blue}{\left(2 \cdot x + \left(\left(y + y\right) + z\right)\right)}
\] |
associate-+r+ [=>]99.9% | \[ \color{blue}{\left(x + 2 \cdot x\right) + \left(\left(y + y\right) + z\right)}
\] |
distribute-rgt1-in [=>]99.9% | \[ \color{blue}{\left(2 + 1\right) \cdot x} + \left(\left(y + y\right) + z\right)
\] |
*-commutative [=>]99.9% | \[ \color{blue}{x \cdot \left(2 + 1\right)} + \left(\left(y + y\right) + z\right)
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(x, 2 + 1, \left(y + y\right) + z\right)}
\] |
metadata-eval [=>]100.0% | \[ \mathsf{fma}\left(x, \color{blue}{3}, \left(y + y\right) + z\right)
\] |
count-2 [=>]100.0% | \[ \mathsf{fma}\left(x, 3, \color{blue}{2 \cdot y} + z\right)
\] |
*-commutative [=>]100.0% | \[ \mathsf{fma}\left(x, 3, \color{blue}{y \cdot 2} + z\right)
\] |
fma-def [=>]100.0% | \[ \mathsf{fma}\left(x, 3, \color{blue}{\mathsf{fma}\left(y, 2, z\right)}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 13120 |
| Alternative 2 | |
|---|---|
| Accuracy | 51.5% |
| Cost | 852 |
| Alternative 3 | |
|---|---|
| Accuracy | 52.3% |
| Cost | 852 |
| Alternative 4 | |
|---|---|
| Accuracy | 84.6% |
| Cost | 713 |
| Alternative 5 | |
|---|---|
| Accuracy | 85.6% |
| Cost | 585 |
| Alternative 6 | |
|---|---|
| Accuracy | 80.4% |
| Cost | 584 |
| Alternative 7 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 576 |
| Alternative 8 | |
|---|---|
| Accuracy | 52.8% |
| Cost | 456 |
| Alternative 9 | |
|---|---|
| Accuracy | 35.2% |
| Cost | 64 |
herbie shell --seed 2023272
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
:precision binary64
(+ (+ (+ (+ (+ x y) y) x) z) x))