Average Error: 0.0 → 0.0
Time: 6.2s
Precision: binary64
Cost: 13248
\[\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(a, b, \mathsf{fma}\left(c, a, a \cdot d\right)\right) \]
(FPCore (a b c d) :precision binary64 (* a (+ (+ b c) d)))
(FPCore (a b c d) :precision binary64 (fma a b (fma c a (* a d))))
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(a, b, fma(c, a, (a * d)));
}
function code(a, b, c, d)
	return Float64(a * Float64(Float64(b + c) + d))
end
function code(a, b, c, d)
	return fma(a, b, fma(c, a, Float64(a * d)))
end
code[a_, b_, c_, d_] := N[(a * N[(N[(b + c), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := N[(a * b + N[(c * a + N[(a * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
a \cdot \left(\left(b + c\right) + d\right)
\mathsf{fma}\left(a, b, \mathsf{fma}\left(c, a, a \cdot d\right)\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}{\mathsf{fma}\left(b + c, a, a \cdot d\right)} \]
  3. Taylor expanded in b around 0 0.0

    \[\leadsto \color{blue}{a \cdot b + \left(a \cdot d + c \cdot a\right)} \]
  4. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(a, b, \mathsf{fma}\left(c, a, a \cdot d\right)\right)} \]
    Proof
    (fma.f64 a b (fma.f64 c a (*.f64 a d))): 0 points increase in error, 0 points decrease in error
    (fma.f64 a b (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c a) (*.f64 a d)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a b) (+.f64 (*.f64 c a) (*.f64 a d)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 a b) (Rewrite=> +-commutative_binary64 (+.f64 (*.f64 a d) (*.f64 c a)))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost6848
\[\mathsf{fma}\left(b + c, a, a \cdot d\right) \]
Alternative 2
Error30.0
Cost852
\[\begin{array}{l} \mathbf{if}\;c \leq 2.25 \cdot 10^{-277}:\\ \;\;\;\;a \cdot d\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{-215}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{-211}:\\ \;\;\;\;a \cdot d\\ \mathbf{elif}\;c \leq 3.1 \cdot 10^{-180}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \leq 1.75 \cdot 10^{-120}:\\ \;\;\;\;a \cdot d\\ \mathbf{else}:\\ \;\;\;\;a \cdot c\\ \end{array} \]
Alternative 3
Error13.8
Cost717
\[\begin{array}{l} \mathbf{if}\;d \leq 1.7 \cdot 10^{-136} \lor \neg \left(d \leq 1.4 \cdot 10^{-125}\right) \land d \leq 1.56 \cdot 10^{-80}:\\ \;\;\;\;a \cdot \left(b + c\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot d\\ \end{array} \]
Alternative 4
Error9.5
Cost584
\[\begin{array}{l} \mathbf{if}\;b \leq 1.32 \cdot 10^{-147}:\\ \;\;\;\;a \cdot \left(c + d\right)\\ \mathbf{elif}\;b \leq 1.3 \cdot 10^{-130}:\\ \;\;\;\;a \cdot \left(b + d\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(b + c\right)\\ \end{array} \]
Alternative 5
Error0.0
Cost576
\[a \cdot \left(b + d\right) + a \cdot c \]
Alternative 6
Error9.5
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.35 \cdot 10^{-118}:\\ \;\;\;\;a \cdot \left(c + d\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(b + c\right)\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[a \cdot \left(d + \left(b + c\right)\right) \]
Alternative 8
Error30.5
Cost324
\[\begin{array}{l} \mathbf{if}\;c \leq 4.2 \cdot 10^{-103}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;a \cdot c\\ \end{array} \]
Alternative 9
Error41.2
Cost192
\[a \cdot b \]

Error

Reproduce

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