Average Error: 0.0 → 0.0
Time: 11.7s
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(c, i, a \cdot b\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 c i (* a b)))))
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(c, i, (a * b))));
}
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(c, i, Float64(a * b))))
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[(c * i + N[(a * b), $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(c, i, a \cdot b\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))))): 2 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))))): 1 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, 0 points decrease in error
  3. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, \mathsf{fma}\left(c, i, a \cdot b\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
Error22.2
Cost2268
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := c \cdot i + x \cdot y\\ t_3 := a \cdot b + z \cdot t\\ \mathbf{if}\;c \cdot i \leq -4 \cdot 10^{+26}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq -3.15 \cdot 10^{-261}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.25 \cdot 10^{-303}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq 2.4 \cdot 10^{-209}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.85 \cdot 10^{-51}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq 8.8 \cdot 10^{+71}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 10^{+217}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error22.1
Cost2268
\[\begin{array}{l} t_1 := z \cdot t + x \cdot y\\ t_2 := c \cdot i + x \cdot y\\ \mathbf{if}\;c \cdot i \leq -2.8 \cdot 10^{+58}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 2.85 \cdot 10^{-304}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.75 \cdot 10^{-251}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 1.7 \cdot 10^{-172}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 2.05 \cdot 10^{-51}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{+77}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 3 \cdot 10^{+219}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error21.7
Cost2008
\[\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.8 \cdot 10^{+19}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq -1.02 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 4.9 \cdot 10^{-296}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 2.3 \cdot 10^{-209}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 2.05 \cdot 10^{-51}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 3.2 \cdot 10^{+24}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \end{array} \]
Alternative 5
Error35.0
Cost1768
\[\begin{array}{l} t_1 := a \cdot b + c \cdot i\\ \mathbf{if}\;a \leq -6.4 \cdot 10^{+120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -7.2 \cdot 10^{+81}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \leq -1.3 \cdot 10^{+51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -5.5 \cdot 10^{+15}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \leq -6.5 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.75 \cdot 10^{-144}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \leq -2.75 \cdot 10^{-167}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.35 \cdot 10^{-257}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \leq 3.6 \cdot 10^{-304}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \leq 2.1 \cdot 10^{-123}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error22.4
Cost1748
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := a \cdot b + x \cdot y\\ t_3 := a \cdot b + c \cdot i\\ \mathbf{if}\;c \cdot i \leq -6.8 \cdot 10^{+43}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq 2.3 \cdot 10^{-302}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 4.4 \cdot 10^{-209}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 1.75 \cdot 10^{-51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.4 \cdot 10^{+25}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 7
Error42.3
Cost1512
\[\begin{array}{l} \mathbf{if}\;y \leq -1.35 \cdot 10^{-134}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-295}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-282}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-194}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;y \leq 1.32 \cdot 10^{-81}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-27}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{-5}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{+58}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{+84}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{+92}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 8
Error37.8
Cost1492
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -6.2 \cdot 10^{+44}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 3 \cdot 10^{-304}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{-252}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 1.9 \cdot 10^{-129}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 5.6 \cdot 10^{-57}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 9
Error27.4
Cost1372
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := a \cdot b + c \cdot i\\ \mathbf{if}\;c \leq -3.7 \cdot 10^{+237}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -7.8 \cdot 10^{+199}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -8 \cdot 10^{+77}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -1.45 \cdot 10^{+54}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \leq -8.5 \cdot 10^{-41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -3.7 \cdot 10^{-59}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 10
Error9.4
Cost1228
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+61}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 4.8 \cdot 10^{+25}:\\ \;\;\;\;a \cdot b + \left(z \cdot t + x \cdot y\right)\\ \mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{+218}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + x \cdot y\\ \end{array} \]
Alternative 11
Error0.0
Cost960
\[\left(a \cdot b + \left(z \cdot t + x \cdot y\right)\right) + c \cdot i \]
Alternative 12
Error38.0
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1 \cdot 10^{-42}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 1.75 \cdot 10^{+62}:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 13
Error47.5
Cost192
\[a \cdot b \]

Error

Reproduce

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