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

(FPCore (x y z t) :precision binary64 (- (* x y) (* z t)))
(FPCore (x y z t) :precision binary64 (fma (- z) t (* x y)))
double code(double x, double y, double z, double t) {
return (x * y) - (z * t);
}
double code(double x, double y, double z, double t) {
return fma(-z, t, (x * y));
}
function code(x, y, z, t) return Float64(Float64(x * y) - Float64(z * t)) end
function code(x, y, z, t) return fma(Float64(-z), t, Float64(x * y)) end
code[x_, y_, z_, t_] := N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[((-z) * t + N[(x * y), $MachinePrecision]), $MachinePrecision]
x \cdot y - z \cdot t
\mathsf{fma}\left(-z, t, x \cdot y\right)
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 98.8%
Applied egg-rr99.6%
[Start]98.8% | \[ x \cdot y - z \cdot t
\] |
|---|---|
sub-neg [=>]98.8% | \[ \color{blue}{x \cdot y + \left(-z \cdot t\right)}
\] |
distribute-rgt-neg-out [<=]98.8% | \[ x \cdot y + \color{blue}{z \cdot \left(-t\right)}
\] |
+-commutative [=>]98.8% | \[ \color{blue}{z \cdot \left(-t\right) + x \cdot y}
\] |
distribute-rgt-neg-out [=>]98.8% | \[ \color{blue}{\left(-z \cdot t\right)} + x \cdot y
\] |
distribute-lft-neg-in [=>]98.8% | \[ \color{blue}{\left(-z\right) \cdot t} + x \cdot y
\] |
fma-def [=>]99.6% | \[ \color{blue}{\mathsf{fma}\left(-z, t, x \cdot y\right)}
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 6784 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 6784 |
| Alternative 3 | |
|---|---|
| Accuracy | 67.7% |
| Cost | 521 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 448 |
| Alternative 5 | |
|---|---|
| Accuracy | 52.2% |
| Cost | 192 |
herbie shell --seed 2023263
(FPCore (x y z t)
:name "Linear.V3:cross from linear-1.19.1.3"
:precision binary64
(- (* x y) (* z t)))