Average Error: 0.0 → 0.0
Time: 7.1s
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

Original0.0
Target0.0
Herbie0.0
\[a \cdot b + a \cdot \left(c + d\right) \]

Derivation

  1. Initial program 0.0

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

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

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

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

Alternatives

Alternative 1
Error30.5
Cost1381
\[\begin{array}{l} \mathbf{if}\;b \leq 6.5 \cdot 10^{-297}:\\ \;\;\;\;c \cdot a\\ \mathbf{elif}\;b \leq 2.8 \cdot 10^{-276}:\\ \;\;\;\;d \cdot a\\ \mathbf{elif}\;b \leq 1.55 \cdot 10^{-257}:\\ \;\;\;\;c \cdot a\\ \mathbf{elif}\;b \leq 1.32 \cdot 10^{-239}:\\ \;\;\;\;d \cdot a\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-190}:\\ \;\;\;\;c \cdot a\\ \mathbf{elif}\;b \leq 1.95 \cdot 10^{-174}:\\ \;\;\;\;d \cdot a\\ \mathbf{elif}\;b \leq 2.9 \cdot 10^{-134} \lor \neg \left(b \leq 2.8 \cdot 10^{-97}\right) \land b \leq 5.2 \cdot 10^{-89}:\\ \;\;\;\;c \cdot a\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 2
Error13.9
Cost717
\[\begin{array}{l} \mathbf{if}\;d \leq 9.5 \cdot 10^{-70} \lor \neg \left(d \leq 2.3 \cdot 10^{-61}\right) \land d \leq 1.05 \cdot 10^{-57}:\\ \;\;\;\;a \cdot \left(c + b\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot a\\ \end{array} \]
Alternative 3
Error9.6
Cost717
\[\begin{array}{l} \mathbf{if}\;b \leq 3 \cdot 10^{-134} \lor \neg \left(b \leq 3.2 \cdot 10^{-97}\right) \land b \leq 5.8 \cdot 10^{-89}:\\ \;\;\;\;\left(c + d\right) \cdot a\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(d + b\right)\\ \end{array} \]
Alternative 4
Error30.4
Cost589
\[\begin{array}{l} \mathbf{if}\;b \leq 2.9 \cdot 10^{-134} \lor \neg \left(b \leq 5.2 \cdot 10^{-98}\right) \land b \leq 4 \cdot 10^{-89}:\\ \;\;\;\;c \cdot a\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 5
Error0.0
Cost576
\[\left(c + d\right) \cdot a + a \cdot b \]
Alternative 6
Error9.6
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.65 \cdot 10^{-106}:\\ \;\;\;\;\left(c + d\right) \cdot a\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(c + b\right)\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[a \cdot \left(d + \left(c + b\right)\right) \]
Alternative 8
Error41.4
Cost192
\[a \cdot b \]

Error

Reproduce

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