?

Average Error: 0.03% → 0.02%
Time: 14.4s
Precision: binary64
Cost: 19776

?

\[\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i \]
\[\mathsf{fma}\left(a, b, \mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, 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 a b (fma c i (fma x y (* 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(a, b, fma(c, i, fma(x, y, (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(a, b, fma(c, i, fma(x, y, 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[(a * b + N[(c * i + N[(x * y + 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(a, b, \mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, z \cdot t\right)\right)\right)

Error?

Derivation?

  1. Initial program 0.03

    \[\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(a, b, \mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, z \cdot t\right)\right)\right)} \]
    Proof

    [Start]0.03

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

    +-commutative [=>]0.03

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

    associate-+l+ [=>]0.03

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

    fma-def [=>]0.03

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

    +-commutative [=>]0.03

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

    fma-def [=>]0.02

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

    fma-def [=>]0.02

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

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

Alternatives

Alternative 1
Error0.03%
Cost7232
\[\left(\mathsf{fma}\left(z, t, x \cdot y\right) + a \cdot b\right) + c \cdot i \]
Alternative 2
Error41.74%
Cost2164
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := c \cdot i + z \cdot t\\ t_3 := a \cdot b + x \cdot y\\ t_4 := c \cdot i + x \cdot y\\ \mathbf{if}\;t \leq -6.8 \cdot 10^{-132}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.55 \cdot 10^{-163}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -1.6 \cdot 10^{-184}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 7.6 \cdot 10^{-224}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{-173}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 1.05 \cdot 10^{-142}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 2.4 \cdot 10^{-138}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{elif}\;t \leq 2.45 \cdot 10^{-60}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 3.5 \cdot 10^{-24}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{+14}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 4.1 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.25 \cdot 10^{+89}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 1.05 \cdot 10^{+190}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error52.38%
Cost2032
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ \mathbf{if}\;a \leq -6.8 \cdot 10^{+190}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -4.8 \cdot 10^{+177}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \leq -2.45 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -9.5 \cdot 10^{-25}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \leq -1 \cdot 10^{-44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -6 \cdot 10^{-69}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \leq -1.85 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.85 \cdot 10^{-98}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \leq -1.42 \cdot 10^{-214}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \leq -4 \cdot 10^{-225}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \leq 7.2 \cdot 10^{-237}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \leq 1.42 \cdot 10^{-214}:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error40.93%
Cost2032
\[\begin{array}{l} t_1 := c \cdot i + x \cdot y\\ t_2 := a \cdot b + x \cdot y\\ t_3 := a \cdot b + c \cdot i\\ t_4 := x \cdot y + z \cdot t\\ t_5 := a \cdot b + z \cdot t\\ \mathbf{if}\;a \leq -1.35 \cdot 10^{+191}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.2 \cdot 10^{+177}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -5 \cdot 10^{+113}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.3 \cdot 10^{+38}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -7.4 \cdot 10^{+31}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq -6.8:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -3 \cdot 10^{-10}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;a \leq -3.7 \cdot 10^{-35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -9.6 \cdot 10^{-40}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;a \leq 1.15 \cdot 10^{-235}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 2.55 \cdot 10^{-119}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{elif}\;a \leq 2.9 \cdot 10^{-65}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_5\\ \end{array} \]
Alternative 5
Error58.03%
Cost2012
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -6.7 \cdot 10^{+69}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -8.8 \cdot 10^{-10}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq -7.4 \cdot 10^{-56}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -7.7 \cdot 10^{-144}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq -1.25 \cdot 10^{-254}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 8.5 \cdot 10^{-274}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 310000000000:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 6
Error34.19%
Cost1489
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -2.4 \cdot 10^{+29}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 1.02 \cdot 10^{-19} \lor \neg \left(c \cdot i \leq 2100000000000\right) \land c \cdot i \leq 6.1 \cdot 10^{+35}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \end{array} \]
Alternative 7
Error11.48%
Cost1484
\[\begin{array}{l} t_1 := c \cdot i + \left(a \cdot b + z \cdot t\right)\\ \mathbf{if}\;a \cdot b \leq -1.32 \cdot 10^{+226}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq -6 \cdot 10^{+61}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 5.2 \cdot 10^{+24}:\\ \;\;\;\;c \cdot i + \left(x \cdot y + z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error58.33%
Cost1232
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -5.1 \cdot 10^{+63}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -4.5 \cdot 10^{-142}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq -1.05 \cdot 10^{-253}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 410000000000:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 9
Error10.02%
Cost1225
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -7 \cdot 10^{+58} \lor \neg \left(a \cdot b \leq 7.2 \cdot 10^{-13}\right):\\ \;\;\;\;c \cdot i + \left(a \cdot b + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + \left(x \cdot y + z \cdot t\right)\\ \end{array} \]
Alternative 10
Error14.41%
Cost1224
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -7 \cdot 10^{+70}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 2.1 \cdot 10^{+25}:\\ \;\;\;\;c \cdot i + \left(x \cdot y + z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \end{array} \]
Alternative 11
Error41.25%
Cost1108
\[\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}\;y \leq -8.4 \cdot 10^{-41}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-230}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-278}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-187}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{+60}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 12
Error38.01%
Cost968
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -2.9 \cdot 10^{+108}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 7.8 \cdot 10^{+104}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 13
Error0.03%
Cost960
\[c \cdot i + \left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) \]
Alternative 14
Error58.69%
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -2.1 \cdot 10^{+62}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 480000000000:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 15
Error73.18%
Cost192
\[a \cdot b \]

Error

Reproduce?

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