| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 13248 |
\[\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b\right)\right)
\]

(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
(FPCore (x y z t a b) :precision binary64 (fma x y (fma z t (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
double code(double x, double y, double z, double t, double a, double b) {
return fma(x, y, fma(z, t, (a * b)));
}
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function code(x, y, z, t, a, b) return fma(x, y, fma(z, t, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := N[(x * y + N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot y + z \cdot t\right) + a \cdot b
\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b\right)\right)
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 97.6%
Simplified98.4%
[Start]97.6% | \[ \left(x \cdot y + z \cdot t\right) + a \cdot b
\] |
|---|---|
associate-+l+ [=>]97.6% | \[ \color{blue}{x \cdot y + \left(z \cdot t + a \cdot b\right)}
\] |
fma-def [=>]98.4% | \[ \color{blue}{\mathsf{fma}\left(x, y, z \cdot t + a \cdot b\right)}
\] |
fma-def [=>]98.4% | \[ \mathsf{fma}\left(x, y, \color{blue}{\mathsf{fma}\left(z, t, a \cdot b\right)}\right)
\] |
Final simplification98.4%
| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 6976 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 6976 |
| Alternative 4 | |
|---|---|
| Accuracy | 47.3% |
| Cost | 1116 |
| Alternative 5 | |
|---|---|
| Accuracy | 78.1% |
| Cost | 978 |
| Alternative 6 | |
|---|---|
| Accuracy | 84.5% |
| Cost | 968 |
| Alternative 7 | |
|---|---|
| Accuracy | 53.8% |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Accuracy | 70.8% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 704 |
| Alternative 10 | |
|---|---|
| Accuracy | 35.1% |
| Cost | 192 |
herbie shell --seed 2023229
(FPCore (x y z t a b)
:name "Linear.V3:$cdot from linear-1.19.1.3, B"
:precision binary64
(+ (+ (* x y) (* z t)) (* a b)))