Average Error: 0.0 → 0.0
Time: 13.6s
Precision: binary64
Cost: 19776
\[\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i \]
\[\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, \mathsf{fma}\left(a, b, c \cdot i\right)\right)\right) \]
(FPCore (x y z t a b c i)
 :precision binary64
 (+ (+ (+ (* x y) (* z t)) (* a b)) (* c i)))
(FPCore (x y z t a b c i)
 :precision binary64
 (fma x y (fma z t (fma a b (* c i)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
	return (((x * y) + (z * t)) + (a * b)) + (c * i);
}
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
	return fma(x, y, fma(z, t, fma(a, b, (c * i))));
}
function code(x, y, z, t, a, b, c, i)
	return Float64(Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) + Float64(c * i))
end
function code(x, y, z, t, a, b, c, i)
	return fma(x, y, fma(z, t, fma(a, b, Float64(c * i))))
end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision] + N[(c * i), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(x * y + N[(z * t + N[(a * b + N[(c * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, \mathsf{fma}\left(a, b, c \cdot i\right)\right)\right)

Error

Derivation

  1. Initial program 0.0

    \[\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, \mathsf{fma}\left(c, i, a \cdot b\right)\right)\right)} \]
    Proof
    (fma.f64 x y (fma.f64 z t (fma.f64 c i (*.f64 a b)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x y (fma.f64 z t (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c i) (*.f64 a b))))): 1 points increase in error, 0 points decrease in error
    (fma.f64 x y (fma.f64 z t (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 a b) (*.f64 c i))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x y (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z t) (+.f64 (*.f64 a b) (*.f64 c i))))): 1 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x y) (+.f64 (*.f64 z t) (+.f64 (*.f64 a b) (*.f64 c i))))): 3 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (+.f64 (*.f64 a b) (*.f64 c i)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) (*.f64 c i))): 0 points increase in error, 1 points decrease in error
  3. Taylor expanded in c around 0 0.0

    \[\leadsto \mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, \color{blue}{c \cdot i + a \cdot b}\right)\right) \]
  4. Simplified0.0

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

    \[\leadsto \mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, \mathsf{fma}\left(a, b, c \cdot i\right)\right)\right) \]

Alternatives

Alternative 1
Error0.0
Cost19776
\[\mathsf{fma}\left(c, i, \mathsf{fma}\left(a, b, \mathsf{fma}\left(x, y, z \cdot t\right)\right)\right) \]
Alternative 2
Error23.4
Cost2528
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := a \cdot b + z \cdot t\\ \mathbf{if}\;c \cdot i \leq -3.45 \cdot 10^{+115}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq -1150:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -1.15 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -1.3 \cdot 10^{-95}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -2.1 \cdot 10^{-153}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 5.4 \cdot 10^{-291}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 7.5 \cdot 10^{-184}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 2.1 \cdot 10^{+134}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + a \cdot b\\ \end{array} \]
Alternative 3
Error22.7
Cost2268
\[\begin{array}{l} t_1 := x \cdot y + z \cdot t\\ t_2 := c \cdot i + z \cdot t\\ t_3 := a \cdot b + x \cdot y\\ \mathbf{if}\;a \cdot b \leq -1.75 \cdot 10^{+79}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \cdot b \leq -6 \cdot 10^{-134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 1.15 \cdot 10^{-201}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq 1.05 \cdot 10^{-83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 1.6 \cdot 10^{-72}:\\ \;\;\;\;c \cdot i + a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 7.5 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 1.05 \cdot 10^{+93}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error33.2
Cost2164
\[\begin{array}{l} t_1 := c \cdot i + a \cdot b\\ t_2 := a \cdot b + z \cdot t\\ \mathbf{if}\;x \leq -8 \cdot 10^{+277}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{+241}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.08 \cdot 10^{+214}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{+192}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -5.7 \cdot 10^{+128}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{+25}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -620000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.82 \cdot 10^{-75}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-221}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-233}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-132}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 5
Error33.7
Cost2032
\[\begin{array}{l} t_1 := c \cdot i + a \cdot b\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{+274}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -7 \cdot 10^{+242}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{+214}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -5.5 \cdot 10^{+180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{+128}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{+63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{+25}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -3.1 \cdot 10^{-185}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-212}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-200}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{-160}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 6
Error38.3
Cost2012
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -3.1 \cdot 10^{+105}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-44}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq -3.25 \cdot 10^{-97}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq -2.8 \cdot 10^{-155}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 2.65 \cdot 10^{-281}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 1.36 \cdot 10^{-140}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 1.95 \cdot 10^{+134}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 7
Error27.2
Cost1768
\[\begin{array}{l} t_1 := c \cdot i + x \cdot y\\ t_2 := a \cdot b + x \cdot y\\ t_3 := a \cdot b + z \cdot t\\ \mathbf{if}\;z \leq -1.96 \cdot 10^{+210}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.46 \cdot 10^{+175}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{+106}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{+63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{+31}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{+18}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{-116}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-256}:\\ \;\;\;\;c \cdot i + a \cdot b\\ \mathbf{elif}\;z \leq 7.4 \cdot 10^{-66}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 8
Error26.3
Cost1240
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := a \cdot b + x \cdot y\\ t_3 := c \cdot i + a \cdot b\\ \mathbf{if}\;y \leq -1.4 \cdot 10^{-44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -8.2 \cdot 10^{-301}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-289}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{-271}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-129}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error37.9
Cost1232
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -4.2 \cdot 10^{+104}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 7.4 \cdot 10^{-236}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 6 \cdot 10^{-114}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{+102}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 10
Error15.9
Cost1232
\[\begin{array}{l} t_1 := c \cdot i + \left(a \cdot b + z \cdot t\right)\\ t_2 := a \cdot b + x \cdot y\\ \mathbf{if}\;y \leq -2.25 \cdot 10^{-37}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{+69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+88}:\\ \;\;\;\;c \cdot i + x \cdot y\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{+150}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 11
Error6.3
Cost1224
\[\begin{array}{l} t_1 := c \cdot i + \left(a \cdot b + x \cdot y\right)\\ \mathbf{if}\;a \cdot b \leq -2.4 \cdot 10^{+79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 1.15 \cdot 10^{+60}:\\ \;\;\;\;c \cdot i + \left(x \cdot y + z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error13.8
Cost968
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ \mathbf{if}\;y \leq -2.25 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{+14}:\\ \;\;\;\;c \cdot i + \left(a \cdot b + z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + t_1\\ \end{array} \]
Alternative 13
Error0.0
Cost960
\[c \cdot i + \left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) \]
Alternative 14
Error38.4
Cost712
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -8 \cdot 10^{+135}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 0.000106:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 15
Error47.2
Cost192
\[a \cdot b \]

Error

Reproduce

herbie shell --seed 2022325 
(FPCore (x y z t a b c i)
  :name "Linear.V4:$cdot from linear-1.19.1.3, C"
  :precision binary64
  (+ (+ (+ (* x y) (* z t)) (* a b)) (* c i)))