?

Average Accuracy: 99.9% → 99.9%
Time: 6.9s
Precision: binary64
Cost: 6848

?

\[\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3 \]
\[\mathsf{fma}\left(3 + d2, d1, d1 \cdot d3\right) \]
(FPCore (d1 d2 d3) :precision binary64 (+ (+ (* d1 3.0) (* d1 d2)) (* d1 d3)))
(FPCore (d1 d2 d3) :precision binary64 (fma (+ 3.0 d2) d1 (* d1 d3)))
double code(double d1, double d2, double d3) {
	return ((d1 * 3.0) + (d1 * d2)) + (d1 * d3);
}
double code(double d1, double d2, double d3) {
	return fma((3.0 + d2), d1, (d1 * d3));
}
function code(d1, d2, d3)
	return Float64(Float64(Float64(d1 * 3.0) + Float64(d1 * d2)) + Float64(d1 * d3))
end
function code(d1, d2, d3)
	return fma(Float64(3.0 + d2), d1, Float64(d1 * d3))
end
code[d1_, d2_, d3_] := N[(N[(N[(d1 * 3.0), $MachinePrecision] + N[(d1 * d2), $MachinePrecision]), $MachinePrecision] + N[(d1 * d3), $MachinePrecision]), $MachinePrecision]
code[d1_, d2_, d3_] := N[(N[(3.0 + d2), $MachinePrecision] * d1 + N[(d1 * d3), $MachinePrecision]), $MachinePrecision]
\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3
\mathsf{fma}\left(3 + d2, d1, d1 \cdot d3\right)

Error?

Target

Original99.9%
Target99.9%
Herbie99.9%
\[d1 \cdot \left(\left(3 + d2\right) + d3\right) \]

Derivation?

  1. Initial program 99.9%

    \[\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3 \]
  2. Simplified99.9%

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

    [Start]99.9

    \[ \left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3 \]

    distribute-lft-out [=>]99.9

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

    distribute-lft-out [=>]99.9

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

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

    [Start]99.9

    \[ d1 \cdot \left(\left(3 + d2\right) + d3\right) \]

    distribute-rgt-in [=>]99.9

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

    fma-def [=>]99.9

    \[ \color{blue}{\mathsf{fma}\left(3 + d2, d1, d3 \cdot d1\right)} \]

    *-commutative [=>]99.9

    \[ \mathsf{fma}\left(3 + d2, d1, \color{blue}{d1 \cdot d3}\right) \]
  4. Final simplification99.9%

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

Alternatives

Alternative 1
Accuracy48.8%
Cost985
\[\begin{array}{l} \mathbf{if}\;d3 \leq -2.6 \cdot 10^{-241}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d3 \leq -1.45 \cdot 10^{-277}:\\ \;\;\;\;3 \cdot d1\\ \mathbf{elif}\;d3 \leq 2.35 \cdot 10^{-256}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d3 \leq 3:\\ \;\;\;\;3 \cdot d1\\ \mathbf{elif}\;d3 \leq 5.2 \cdot 10^{+42} \lor \neg \left(d3 \leq 3.1 \cdot 10^{+60}\right):\\ \;\;\;\;d1 \cdot d3\\ \mathbf{else}:\\ \;\;\;\;d2 \cdot d1\\ \end{array} \]
Alternative 2
Accuracy75.4%
Cost717
\[\begin{array}{l} \mathbf{if}\;d3 \leq 6.2 \cdot 10^{-27}:\\ \;\;\;\;\left(3 + d2\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 5.1 \cdot 10^{+42} \lor \neg \left(d3 \leq 3.6 \cdot 10^{+60}\right):\\ \;\;\;\;d1 \cdot \left(3 + d3\right)\\ \mathbf{else}:\\ \;\;\;\;d2 \cdot d1\\ \end{array} \]
Alternative 3
Accuracy77.3%
Cost452
\[\begin{array}{l} \mathbf{if}\;d2 \leq -17000:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(3 + d3\right)\\ \end{array} \]
Alternative 4
Accuracy99.9%
Cost448
\[d1 \cdot \left(\left(3 + d2\right) + d3\right) \]
Alternative 5
Accuracy49.0%
Cost324
\[\begin{array}{l} \mathbf{if}\;d3 \leq 3:\\ \;\;\;\;3 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d3\\ \end{array} \]
Alternative 6
Accuracy33.0%
Cost192
\[3 \cdot d1 \]

Error

Reproduce?

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

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

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