?

Average Error: 0.02% → 0.01%
Time: 2.3s
Precision: binary64
Cost: 6720

?

\[d1 \cdot d2 + d1 \cdot d3 \]
\[\mathsf{fma}\left(d2, d1, d1 \cdot d3\right) \]
(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)

Error?

Target

Original0.02%
Target0.02%
Herbie0.01%
\[d1 \cdot \left(d2 + d3\right) \]

Derivation?

  1. Initial program 0.02

    \[d1 \cdot d2 + d1 \cdot d3 \]
  2. Simplified0.02

    \[\leadsto \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
    Proof

    [Start]0.02

    \[ d1 \cdot d2 + d1 \cdot d3 \]

    distribute-lft-out [=>]0.02

    \[ \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
  3. Applied egg-rr0.01

    \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, d1 \cdot d3\right)} \]
  4. Final simplification0.01

    \[\leadsto \mathsf{fma}\left(d2, d1, d1 \cdot d3\right) \]

Alternatives

Alternative 1
Error36.19%
Cost324
\[\begin{array}{l} \mathbf{if}\;d3 \leq 4 \cdot 10^{-83}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d3\\ \end{array} \]
Alternative 2
Error0.02%
Cost320
\[d1 \cdot \left(d2 + d3\right) \]
Alternative 3
Error46.07%
Cost192
\[d1 \cdot d3 \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (d1 d2 d3)
  :name "FastMath dist"
  :precision binary64

  :herbie-target
  (* d1 (+ d2 d3))

  (+ (* d1 d2) (* d1 d3)))