?

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

?

\[\left(\left(\left(56789 \leq a \land a \leq 98765\right) \land \left(0 \leq b \land b \leq 1\right)\right) \land \left(0 \leq c \land c \leq 0.0016773\right)\right) \land \left(0 \leq d \land d \leq 0.0016773\right)\]
\[ \begin{array}{c}[b, c, d] = \mathsf{sort}([b, c, d])\\ \end{array} \]
\[a \cdot \left(\left(b + c\right) + d\right) \]
\[\mathsf{fma}\left(d, a, a \cdot \left(b + c\right)\right) \]
(FPCore (a b c d) :precision binary64 (* a (+ (+ b c) d)))
(FPCore (a b c d) :precision binary64 (fma d a (* a (+ b c))))
double code(double a, double b, double c, double d) {
	return a * ((b + c) + d);
}
double code(double a, double b, double c, double d) {
	return fma(d, a, (a * (b + c)));
}
function code(a, b, c, d)
	return Float64(a * Float64(Float64(b + c) + d))
end
function code(a, b, c, d)
	return fma(d, a, Float64(a * Float64(b + c)))
end
code[a_, b_, c_, d_] := N[(a * N[(N[(b + c), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := N[(d * a + N[(a * N[(b + c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
a \cdot \left(\left(b + c\right) + d\right)
\mathsf{fma}\left(d, a, a \cdot \left(b + c\right)\right)

Error?

Target

Original99.9%
Target99.9%
Herbie100.0%
\[a \cdot b + a \cdot \left(c + d\right) \]

Derivation?

  1. Initial program 99.9%

    \[a \cdot \left(\left(b + c\right) + d\right) \]
  2. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(d, a, a \cdot \left(b + c\right)\right)} \]
    Proof

    [Start]99.9

    \[ a \cdot \left(\left(b + c\right) + d\right) \]

    +-commutative [=>]99.9

    \[ a \cdot \color{blue}{\left(d + \left(b + c\right)\right)} \]

    distribute-rgt-in [=>]99.9

    \[ \color{blue}{d \cdot a + \left(b + c\right) \cdot a} \]

    fma-def [=>]100.0

    \[ \color{blue}{\mathsf{fma}\left(d, a, \left(b + c\right) \cdot a\right)} \]

    *-commutative [=>]100.0

    \[ \mathsf{fma}\left(d, a, \color{blue}{a \cdot \left(b + c\right)}\right) \]
  3. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(d, a, a \cdot \left(b + c\right)\right) \]

Alternatives

Alternative 1
Accuracy99.9%
Cost576
\[a \cdot b + a \cdot \left(d + c\right) \]
Alternative 2
Accuracy99.9%
Cost448
\[a \cdot \left(d + \left(b + c\right)\right) \]
Alternative 3
Accuracy99.8%
Cost320
\[a \cdot \left(d + c\right) \]
Alternative 4
Accuracy94.1%
Cost192
\[d \cdot a \]

Error

Reproduce?

herbie shell --seed 2023147 
(FPCore (a b c d)
  :name "Expression, p14"
  :precision binary64
  :pre (and (and (and (and (<= 56789.0 a) (<= a 98765.0)) (and (<= 0.0 b) (<= b 1.0))) (and (<= 0.0 c) (<= c 0.0016773))) (and (<= 0.0 d) (<= d 0.0016773)))

  :herbie-target
  (+ (* a b) (* a (+ c d)))

  (* a (+ (+ b c) d)))