| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 7492 |
\[\begin{array}{l}
t_1 := a \cdot b + \left(x \cdot y + z \cdot t\right)\\
\mathbf{if}\;t_1 \leq \infty:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\end{array}
\]

(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (* a b) (+ (* x y) (* z t))))) (if (<= t_1 INFINITY) t_1 (fma t z (* x y)))))
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) {
double t_1 = (a * b) + ((x * y) + (z * t));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = fma(t, z, (x * y));
}
return tmp;
}
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) t_1 = Float64(Float64(a * b) + Float64(Float64(x * y) + Float64(z * t))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = fma(t, z, Float64(x * y)); end return tmp 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_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\left(x \cdot y + z \cdot t\right) + a \cdot b
\begin{array}{l}
t_1 := a \cdot b + \left(x \cdot y + z \cdot t\right)\\
\mathbf{if}\;t_1 \leq \infty:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) < +inf.0Initial program 100.0%
if +inf.0 < (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) Initial program 0.0%
Taylor expanded in a around 0 33.3%
Simplified66.7%
[Start]33.3% | \[ y \cdot x + t \cdot z
\] |
|---|---|
+-commutative [=>]33.3% | \[ \color{blue}{t \cdot z + y \cdot x}
\] |
*-commutative [=>]33.3% | \[ t \cdot z + \color{blue}{x \cdot y}
\] |
fma-udef [<=]66.7% | \[ \color{blue}{\mathsf{fma}\left(t, z, x \cdot y\right)}
\] |
*-commutative [<=]66.7% | \[ \mathsf{fma}\left(t, z, \color{blue}{y \cdot x}\right)
\] |
Final simplification99.2%
| Alternative 1 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 7492 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 13248 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 6976 |
| Alternative 4 | |
|---|---|
| Accuracy | 53.7% |
| Cost | 2272 |
| Alternative 5 | |
|---|---|
| Accuracy | 84.4% |
| Cost | 1489 |
| Alternative 6 | |
|---|---|
| Accuracy | 53.9% |
| Cost | 1233 |
| Alternative 7 | |
|---|---|
| Accuracy | 77.1% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Accuracy | 70.4% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 704 |
| Alternative 10 | |
|---|---|
| Accuracy | 35.8% |
| Cost | 192 |
herbie shell --seed 2023277
(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)))