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

(FPCore (x y z) :precision binary64 (- (* (* x 3.0) y) z))
(FPCore (x y z) :precision binary64 (fma (* x y) 3.0 (- z)))
double code(double x, double y, double z) {
return ((x * 3.0) * y) - z;
}
double code(double x, double y, double z) {
return fma((x * y), 3.0, -z);
}
function code(x, y, z) return Float64(Float64(Float64(x * 3.0) * y) - z) end
function code(x, y, z) return fma(Float64(x * y), 3.0, Float64(-z)) end
code[x_, y_, z_] := N[(N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] * 3.0 + (-z)), $MachinePrecision]
\left(x \cdot 3\right) \cdot y - z
\mathsf{fma}\left(x \cdot y, 3, -z\right)
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 99.8% |
|---|---|
| Target | 99.8% |
| Herbie | 99.8% |
Initial program 99.8%
Simplified99.8%
[Start]99.8% | \[ \left(x \cdot 3\right) \cdot y - z
\] |
|---|---|
associate-*l* [=>]99.8% | \[ \color{blue}{x \cdot \left(3 \cdot y\right)} - z
\] |
fma-neg [=>]99.8% | \[ \color{blue}{\mathsf{fma}\left(x, 3 \cdot y, -z\right)}
\] |
Applied egg-rr99.8%
[Start]99.8% | \[ \mathsf{fma}\left(x, 3 \cdot y, -z\right)
\] |
|---|---|
fma-neg [<=]99.8% | \[ \color{blue}{x \cdot \left(3 \cdot y\right) - z}
\] |
Applied egg-rr99.8%
[Start]99.8% | \[ x \cdot \left(3 \cdot y\right) - z
\] |
|---|---|
*-commutative [=>]99.8% | \[ \color{blue}{\left(3 \cdot y\right) \cdot x} - z
\] |
associate-*r* [<=]99.8% | \[ \color{blue}{3 \cdot \left(y \cdot x\right)} - z
\] |
*-commutative [=>]99.8% | \[ \color{blue}{\left(y \cdot x\right) \cdot 3} - z
\] |
fma-neg [=>]99.8% | \[ \color{blue}{\mathsf{fma}\left(y \cdot x, 3, -z\right)}
\] |
*-commutative [=>]99.8% | \[ \mathsf{fma}\left(\color{blue}{x \cdot y}, 3, -z\right)
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 6784 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 448 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 448 |
| Alternative 5 | |
|---|---|
| Accuracy | 50.6% |
| Cost | 128 |
| Alternative 6 | |
|---|---|
| Accuracy | 2.3% |
| Cost | 64 |
herbie shell --seed 2023258
(FPCore (x y z)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B"
:precision binary64
:herbie-target
(- (* x (* 3.0 y)) z)
(- (* (* x 3.0) y) z))