?

Average Error: 0.04% → 0.02%
Time: 14.5s
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.04

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

    \[\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.04

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

    associate-+l+ [=>]0.04

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

    associate-+l+ [=>]0.04

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

    fma-def [=>]0.03

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

    associate-+r+ [=>]0.03

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

    +-commutative [=>]0.03

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

    fma-def [=>]0.02

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

    +-commutative [=>]0.02

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

    fma-def [=>]0.02

    \[ \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.02

    \[\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.04%
Cost7232
\[\left(a \cdot b + c \cdot i\right) + \mathsf{fma}\left(x, y, z \cdot t\right) \]
Alternative 2
Error0.04%
Cost7232
\[\mathsf{fma}\left(z, t, x \cdot y\right) + \left(a \cdot b + c \cdot i\right) \]
Alternative 3
Error42.27%
Cost2560
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := x \cdot y + a \cdot b\\ t_3 := c \cdot i + z \cdot t\\ t_4 := x \cdot y + c \cdot i\\ t_5 := x \cdot y + z \cdot t\\ \mathbf{if}\;i \leq -9 \cdot 10^{-74}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;i \leq -8.4 \cdot 10^{-139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq -3.15 \cdot 10^{-198}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;i \leq 1.95 \cdot 10^{-304}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 3 \cdot 10^{-183}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq 5 \cdot 10^{-174}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;i \leq 1.95 \cdot 10^{-83}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;i \leq 1.95 \cdot 10^{-34}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 0.34:\\ \;\;\;\;t_4\\ \mathbf{elif}\;i \leq 8.5 \cdot 10^{+24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 5.6 \cdot 10^{+33}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;i \leq 1.55 \cdot 10^{+87}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{elif}\;i \leq 2.75 \cdot 10^{+134}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;i \leq 9.5 \cdot 10^{+152}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq 2.05 \cdot 10^{+189}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;i \leq 2.1 \cdot 10^{+208}:\\ \;\;\;\;t_5\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array} \]
Alternative 4
Error34.88%
Cost2268
\[\begin{array}{l} t_1 := x \cdot y + a \cdot b\\ t_2 := a \cdot b + z \cdot t\\ t_3 := a \cdot b + c \cdot i\\ \mathbf{if}\;c \cdot i \leq -6.8 \cdot 10^{+74}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq -3.1 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -1.6 \cdot 10^{-168}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-315}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 2.7 \cdot 10^{-36}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 3.1 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 2.5 \cdot 10^{+51}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 5
Error34.92%
Cost2268
\[\begin{array}{l} t_1 := x \cdot y + a \cdot b\\ t_2 := c \cdot i + z \cdot t\\ t_3 := a \cdot b + z \cdot t\\ \mathbf{if}\;c \cdot i \leq -4.5 \cdot 10^{+75}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -3.4 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -7.2 \cdot 10^{-169}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-315}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.65 \cdot 10^{-32}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq 3.1 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 5.8 \cdot 10^{+65}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error42.49%
Cost2032
\[\begin{array}{l} t_1 := c \cdot i + z \cdot t\\ t_2 := a \cdot b + z \cdot t\\ t_3 := x \cdot y + c \cdot i\\ t_4 := x \cdot y + a \cdot b\\ \mathbf{if}\;i \leq -4.4 \cdot 10^{-63}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;i \leq 1.02 \cdot 10^{-304}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq 7.2 \cdot 10^{-188}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;i \leq 1.25 \cdot 10^{-127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 3.8 \cdot 10^{-53}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;i \leq 4.2 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq 0.3:\\ \;\;\;\;t_3\\ \mathbf{elif}\;i \leq 1.65 \cdot 10^{+25}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq 3 \cdot 10^{+37}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;i \leq 4.3 \cdot 10^{+163}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{elif}\;i \leq 2.8 \cdot 10^{+208}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq 2.35 \cdot 10^{+265}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error58.47%
Cost1752
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -1.02 \cdot 10^{+73}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq -4.4 \cdot 10^{-143}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 1.42 \cdot 10^{-182}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 1.4 \cdot 10^{-25}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 4.5 \cdot 10^{-7}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 2.8 \cdot 10^{+46}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 8
Error37.12%
Cost1748
\[\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 -8.5 \cdot 10^{+72}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -1.85 \cdot 10^{-23}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 1.25 \cdot 10^{-24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 10^{-7}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 1.12 \cdot 10^{+52}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error58.46%
Cost1232
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -0.05:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq -2.4 \cdot 10^{-145}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 3.6 \cdot 10^{-180}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 3.3 \cdot 10^{+46}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 10
Error13.75%
Cost1225
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -1.5 \cdot 10^{+58} \lor \neg \left(c \cdot i \leq 2.2 \cdot 10^{+67}\right):\\ \;\;\;\;x \cdot y + c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + \left(x \cdot y + z \cdot t\right)\\ \end{array} \]
Alternative 11
Error9.6%
Cost1225
\[\begin{array}{l} t_1 := x \cdot y + z \cdot t\\ \mathbf{if}\;c \cdot i \leq -6.5 \cdot 10^{+57} \lor \neg \left(c \cdot i \leq 3.5 \cdot 10^{+66}\right):\\ \;\;\;\;c \cdot i + t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + t_1\\ \end{array} \]
Alternative 12
Error0.04%
Cost960
\[c \cdot i + \left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) \]
Alternative 13
Error58.96%
Cost712
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -4.8 \cdot 10^{-16}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 1.9 \cdot 10^{+39}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 14
Error49.05%
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{+104}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;z \leq 0.00014:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
Alternative 15
Error73.5%
Cost192
\[a \cdot b \]

Error

Reproduce?

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