?

Average Accuracy: 99.9% → 100.0%
Time: 7.2s
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)\]
\[a \cdot \left(\left(b + c\right) + d\right) \]
\[\mathsf{fma}\left(c + d, a, a \cdot b\right) \]
(FPCore (a b c d) :precision binary64 (* a (+ (+ b c) d)))
(FPCore (a b c d) :precision binary64 (fma (+ c d) a (* a b)))
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((c + d), a, (a * b));
}
function code(a, b, c, d)
	return Float64(a * Float64(Float64(b + c) + d))
end
function code(a, b, c, d)
	return fma(Float64(c + d), a, Float64(a * b))
end
code[a_, b_, c_, d_] := N[(a * N[(N[(b + c), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := N[(N[(c + d), $MachinePrecision] * a + N[(a * b), $MachinePrecision]), $MachinePrecision]
a \cdot \left(\left(b + c\right) + d\right)
\mathsf{fma}\left(c + d, a, a \cdot b\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-rr99.9%

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

    [Start]99.9

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

    associate-+l+ [=>]99.9

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

    +-commutative [=>]99.9

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

    distribute-lft-in [=>]99.9

    \[ \color{blue}{a \cdot \left(c + d\right) + a \cdot b} \]
  3. Applied egg-rr100.0%

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

    [Start]99.9

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

    *-commutative [=>]99.9

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

    fma-def [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy51.5%
Cost984
\[\begin{array}{l} \mathbf{if}\;c \leq 6.5 \cdot 10^{-279}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \leq 1.18 \cdot 10^{-272}:\\ \;\;\;\;d \cdot a\\ \mathbf{elif}\;c \leq 3.7 \cdot 10^{-196}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{-173}:\\ \;\;\;\;d \cdot a\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-138}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{-109}:\\ \;\;\;\;d \cdot a\\ \mathbf{else}:\\ \;\;\;\;c \cdot a\\ \end{array} \]
Alternative 2
Accuracy83.6%
Cost717
\[\begin{array}{l} \mathbf{if}\;d \leq 2 \cdot 10^{-164} \lor \neg \left(d \leq 5.7 \cdot 10^{-124}\right) \land d \leq 4.2 \cdot 10^{-104}:\\ \;\;\;\;a \cdot \left(c + b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(c + d\right) \cdot a\\ \end{array} \]
Alternative 3
Accuracy84.8%
Cost716
\[\begin{array}{l} t_0 := \left(c + d\right) \cdot a\\ \mathbf{if}\;b \leq 3.2 \cdot 10^{-197}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 5.8 \cdot 10^{-192}:\\ \;\;\;\;a \cdot \left(d + b\right)\\ \mathbf{elif}\;b \leq 1.1 \cdot 10^{-111}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(c + b\right)\\ \end{array} \]
Alternative 4
Accuracy79.4%
Cost452
\[\begin{array}{l} \mathbf{if}\;d \leq 1.5 \cdot 10^{-88}:\\ \;\;\;\;a \cdot \left(c + b\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot a\\ \end{array} \]
Alternative 5
Accuracy99.9%
Cost448
\[a \cdot \left(d + \left(c + b\right)\right) \]
Alternative 6
Accuracy52.4%
Cost324
\[\begin{array}{l} \mathbf{if}\;c \leq 3.5 \cdot 10^{-138}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;c \cdot a\\ \end{array} \]
Alternative 7
Accuracy35.7%
Cost192
\[a \cdot b \]

Error

Reproduce?

herbie shell --seed 2023138 
(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)))