| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6720 |
\[\mathsf{fma}\left(d1, 30, d1 \cdot d2\right)
\]

(FPCore (d1 d2) :precision binary64 (+ (+ (* d1 10.0) (* d1 d2)) (* d1 20.0)))
(FPCore (d1 d2) :precision binary64 (fma d1 30.0 (* d1 d2)))
double code(double d1, double d2) {
return ((d1 * 10.0) + (d1 * d2)) + (d1 * 20.0);
}
double code(double d1, double d2) {
return fma(d1, 30.0, (d1 * d2));
}
function code(d1, d2) return Float64(Float64(Float64(d1 * 10.0) + Float64(d1 * d2)) + Float64(d1 * 20.0)) end
function code(d1, d2) return fma(d1, 30.0, Float64(d1 * d2)) end
code[d1_, d2_] := N[(N[(N[(d1 * 10.0), $MachinePrecision] + N[(d1 * d2), $MachinePrecision]), $MachinePrecision] + N[(d1 * 20.0), $MachinePrecision]), $MachinePrecision]
code[d1_, d2_] := N[(d1 * 30.0 + N[(d1 * d2), $MachinePrecision]), $MachinePrecision]
\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20
\mathsf{fma}\left(d1, 30, d1 \cdot d2\right)
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 99.7% |
|---|---|
| Target | 100.0% |
| Herbie | 100.0% |
Initial program 99.8%
Simplified100.0%
[Start]99.8% | \[ \left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20
\] |
|---|---|
+-commutative [=>]99.8% | \[ \color{blue}{\left(d1 \cdot d2 + d1 \cdot 10\right)} + d1 \cdot 20
\] |
associate-+l+ [=>]99.8% | \[ \color{blue}{d1 \cdot d2 + \left(d1 \cdot 10 + d1 \cdot 20\right)}
\] |
distribute-lft-out [=>]100.0% | \[ d1 \cdot d2 + \color{blue}{d1 \cdot \left(10 + 20\right)}
\] |
distribute-lft-in [<=]100.0% | \[ \color{blue}{d1 \cdot \left(d2 + \left(10 + 20\right)\right)}
\] |
metadata-eval [=>]100.0% | \[ d1 \cdot \left(d2 + \color{blue}{30}\right)
\] |
Applied egg-rr100.0%
[Start]100.0% | \[ d1 \cdot \left(d2 + 30\right)
\] |
|---|---|
+-commutative [=>]100.0% | \[ d1 \cdot \color{blue}{\left(30 + d2\right)}
\] |
distribute-lft-in [=>]100.0% | \[ \color{blue}{d1 \cdot 30 + d1 \cdot d2}
\] |
*-commutative [<=]100.0% | \[ d1 \cdot 30 + \color{blue}{d2 \cdot d1}
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(d1, 30, d2 \cdot d1\right)}
\] |
*-commutative [=>]100.0% | \[ \mathsf{fma}\left(d1, 30, \color{blue}{d1 \cdot d2}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6720 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 456 |
| Alternative 3 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 320 |
| Alternative 4 | |
|---|---|
| Accuracy | 50.6% |
| Cost | 192 |
herbie shell --seed 2023178
(FPCore (d1 d2)
:name "FastMath test2"
:precision binary64
:herbie-target
(* d1 (+ 30.0 d2))
(+ (+ (* d1 10.0) (* d1 d2)) (* d1 20.0)))