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

(FPCore (x y z t a b c i) :precision binary64 (+ (+ (+ (* x y) (* z t)) (* a b)) (* c i)))
(FPCore (x y z t a b c i) :precision binary64 (fma c i (fma x y (fma z t (* a b)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((x * y) + (z * t)) + (a * b)) + (c * i);
}
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return fma(c, i, fma(x, y, fma(z, t, (a * b))));
}
function code(x, y, z, t, a, b, c, i) return Float64(Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) + Float64(c * i)) end
function code(x, y, z, t, a, b, c, i) return fma(c, i, fma(x, y, fma(z, t, Float64(a * b)))) end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision] + N[(c * i), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(c * i + N[(x * y + N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b\right)\right)\right)
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 97.6%
Simplified99.2%
[Start]97.6% | \[ \left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\] |
|---|---|
+-commutative [=>]97.6% | \[ \color{blue}{c \cdot i + \left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right)}
\] |
fma-def [=>]98.0% | \[ \color{blue}{\mathsf{fma}\left(c, i, \left(x \cdot y + z \cdot t\right) + a \cdot b\right)}
\] |
associate-+l+ [=>]98.0% | \[ \mathsf{fma}\left(c, i, \color{blue}{x \cdot y + \left(z \cdot t + a \cdot b\right)}\right)
\] |
fma-def [=>]98.8% | \[ \mathsf{fma}\left(c, i, \color{blue}{\mathsf{fma}\left(x, y, z \cdot t + a \cdot b\right)}\right)
\] |
fma-def [=>]99.2% | \[ \mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, \color{blue}{\mathsf{fma}\left(z, t, a \cdot b\right)}\right)\right)
\] |
Final simplification99.2%
| Alternative 1 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 19776 |
| Alternative 2 | |
|---|---|
| Accuracy | 96.0% |
| Cost | 7232 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.0% |
| Cost | 1988 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 1746 |
| Alternative 5 | |
|---|---|
| Accuracy | 43.1% |
| Cost | 1232 |
| Alternative 6 | |
|---|---|
| Accuracy | 87.7% |
| Cost | 1225 |
| Alternative 7 | |
|---|---|
| Accuracy | 87.6% |
| Cost | 1225 |
| Alternative 8 | |
|---|---|
| Accuracy | 60.7% |
| Cost | 1108 |
| Alternative 9 | |
|---|---|
| Accuracy | 42.6% |
| Cost | 972 |
| Alternative 10 | |
|---|---|
| Accuracy | 65.3% |
| Cost | 969 |
| Alternative 11 | |
|---|---|
| Accuracy | 65.2% |
| Cost | 968 |
| Alternative 12 | |
|---|---|
| Accuracy | 42.4% |
| Cost | 712 |
| Alternative 13 | |
|---|---|
| Accuracy | 51.8% |
| Cost | 712 |
| Alternative 14 | |
|---|---|
| Accuracy | 27.2% |
| Cost | 192 |
herbie shell --seed 2023263
(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)))