Average Error: 0.0 → 0.0
Time: 14.8s
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(c, i, \mathsf{fma}\left(a, b, z \cdot t\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 c i (fma a b (* z t)))))
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(c, i, fma(a, b, (z * t))));
}
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(c, i, fma(a, b, Float64(z * t))))
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[(c * i + N[(a * b + N[(z * t), $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(c, i, \mathsf{fma}\left(a, b, z \cdot t\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(c, i, \mathsf{fma}\left(a, b, z \cdot t\right)\right)\right)} \]
    Proof

    [Start]0.0

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

    associate-+l+ [=>]0.0

    \[ \color{blue}{\left(x \cdot y + z \cdot t\right) + \left(a \cdot b + c \cdot i\right)} \]

    associate-+l+ [=>]0.0

    \[ \color{blue}{x \cdot y + \left(z \cdot t + \left(a \cdot b + c \cdot i\right)\right)} \]

    fma-def [=>]0.0

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

    associate-+r+ [=>]0.0

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

    +-commutative [=>]0.0

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

    fma-def [=>]0.0

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

    +-commutative [=>]0.0

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

    fma-def [=>]0.0

    \[ \mathsf{fma}\left(x, y, \mathsf{fma}\left(c, i, \color{blue}{\mathsf{fma}\left(a, b, z \cdot t\right)}\right)\right) \]
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost7232
\[\mathsf{fma}\left(x, y, z \cdot t\right) + \left(a \cdot b + c \cdot i\right) \]
Alternative 2
Error26.5
Cost1900
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := a \cdot b + x \cdot y\\ t_3 := c \cdot i + x \cdot y\\ t_4 := c \cdot i + z \cdot t\\ \mathbf{if}\;x \leq -3.8 \cdot 10^{+228}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{+80}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.6 \cdot 10^{+59}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-65}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-111}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{-206}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-242}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-145}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{-78}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-36}:\\ \;\;\;\;z \cdot t + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error30.5
Cost1636
\[\begin{array}{l} t_1 := a \cdot b + c \cdot i\\ t_2 := a \cdot b + z \cdot t\\ \mathbf{if}\;y \leq -2.35 \cdot 10^{-14}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -6.8 \cdot 10^{-162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-263}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-259}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-222}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.22 \cdot 10^{+48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7 \cdot 10^{+95}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \end{array} \]
Alternative 4
Error26.7
Cost1636
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := c \cdot i + z \cdot t\\ \mathbf{if}\;a \leq -3.85 \cdot 10^{+174}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.32 \cdot 10^{+58}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{elif}\;a \leq -1.15 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.3 \cdot 10^{-78}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -1.9 \cdot 10^{-111}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -4.1 \cdot 10^{-125}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -4.3 \cdot 10^{-156}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 1.4 \cdot 10^{-87}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 5.2 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \end{array} \]
Alternative 5
Error27.1
Cost1636
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := a \cdot b + x \cdot y\\ t_3 := c \cdot i + x \cdot y\\ t_4 := c \cdot i + z \cdot t\\ \mathbf{if}\;x \leq -6.5 \cdot 10^{+228}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -3 \cdot 10^{+79}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{+59}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.7 \cdot 10^{-65}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.45 \cdot 10^{-205}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-243}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-146}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error22.7
Cost1488
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := a \cdot b + c \cdot i\\ \mathbf{if}\;c \cdot i \leq -2.36 \cdot 10^{+55}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -1.5 \cdot 10^{-236}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -2.7 \cdot 10^{-288}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 4.2 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error42.5
Cost1380
\[\begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{-21}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -2.7 \cdot 10^{-162}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;y \leq -1.75 \cdot 10^{-266}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{-264}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;y \leq 8.4 \cdot 10^{-212}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{-100}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+47}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{+71}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+97}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 8
Error32.5
Cost1240
\[\begin{array}{l} t_1 := a \cdot b + c \cdot i\\ \mathbf{if}\;y \leq -2.35 \cdot 10^{-14}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -9.8 \cdot 10^{-224}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;y \leq 9.6 \cdot 10^{-14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 0.00035:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+97}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 9
Error37.5
Cost1232
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -6.8 \cdot 10^{+55}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 6 \cdot 10^{-109}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 4.9 \cdot 10^{-63}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 1.1 \cdot 10^{+49}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 10
Error9.0
Cost1225
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -5.5 \cdot 10^{+56} \lor \neg \left(c \cdot i \leq 4.5 \cdot 10^{+67}\right):\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + \left(z \cdot t + x \cdot y\right)\\ \end{array} \]
Alternative 11
Error0.0
Cost960
\[c \cdot i + \left(a \cdot b + \left(z \cdot t + x \cdot y\right)\right) \]
Alternative 12
Error37.7
Cost712
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -1.8 \cdot 10^{+52}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 2000:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 13
Error47.3
Cost192
\[a \cdot b \]

Error

Reproduce

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