| Alternative 1 | |
|---|---|
| Error | 36.19% |
| Cost | 324 |
\[\begin{array}{l}
\mathbf{if}\;d3 \leq 4 \cdot 10^{-83}:\\
\;\;\;\;d2 \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot d3\\
\end{array}
\]
(FPCore (d1 d2 d3) :precision binary64 (+ (* d1 d2) (* d1 d3)))
(FPCore (d1 d2 d3) :precision binary64 (fma d2 d1 (* d1 d3)))
double code(double d1, double d2, double d3) {
return (d1 * d2) + (d1 * d3);
}
double code(double d1, double d2, double d3) {
return fma(d2, d1, (d1 * d3));
}
function code(d1, d2, d3) return Float64(Float64(d1 * d2) + Float64(d1 * d3)) end
function code(d1, d2, d3) return fma(d2, d1, Float64(d1 * d3)) end
code[d1_, d2_, d3_] := N[(N[(d1 * d2), $MachinePrecision] + N[(d1 * d3), $MachinePrecision]), $MachinePrecision]
code[d1_, d2_, d3_] := N[(d2 * d1 + N[(d1 * d3), $MachinePrecision]), $MachinePrecision]
d1 \cdot d2 + d1 \cdot d3
\mathsf{fma}\left(d2, d1, d1 \cdot d3\right)
| Original | 0.02% |
|---|---|
| Target | 0.02% |
| Herbie | 0.01% |
Initial program 0.02
Simplified0.02
[Start]0.02 | \[ d1 \cdot d2 + d1 \cdot d3
\] |
|---|---|
distribute-lft-out [=>]0.02 | \[ \color{blue}{d1 \cdot \left(d2 + d3\right)}
\] |
Applied egg-rr0.01
Final simplification0.01
| Alternative 1 | |
|---|---|
| Error | 36.19% |
| Cost | 324 |
| Alternative 2 | |
|---|---|
| Error | 0.02% |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Error | 46.07% |
| Cost | 192 |
herbie shell --seed 2023090
(FPCore (d1 d2 d3)
:name "FastMath dist"
:precision binary64
:herbie-target
(* d1 (+ d2 d3))
(+ (* d1 d2) (* d1 d3)))