| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| 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
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b\right)\right)
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 97.3%
Simplified98.8%
[Start]97.3% | \[ \left(x \cdot y + z \cdot t\right) + a \cdot b
\] |
|---|---|
associate-+l+ [=>]97.3% | \[ \color{blue}{x \cdot y + \left(z \cdot t + a \cdot b\right)}
\] |
fma-def [=>]97.7% | \[ \color{blue}{\mathsf{fma}\left(x, y, z \cdot t + a \cdot b\right)}
\] |
fma-def [=>]98.8% | \[ \mathsf{fma}\left(x, y, \color{blue}{\mathsf{fma}\left(z, t, a \cdot b\right)}\right)
\] |
Final simplification98.8%
| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 6976 |
| Alternative 3 | |
|---|---|
| Accuracy | 54.2% |
| Cost | 2532 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 1476 |
| Alternative 5 | |
|---|---|
| Accuracy | 82.7% |
| Cost | 968 |
| Alternative 6 | |
|---|---|
| Accuracy | 54.6% |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Accuracy | 72.1% |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Accuracy | 36.6% |
| Cost | 192 |
herbie shell --seed 2023167
(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)))