?

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

?

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

    fma-def [=>]0.03

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

    +-commutative [=>]0.03

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

    fma-def [=>]0.02

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

    fma-def [=>]0.02

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

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

Alternatives

Alternative 1
Error0.02%
Cost19776
\[\mathsf{fma}\left(a, b, \mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, z \cdot t\right)\right)\right) \]
Alternative 2
Error0.03%
Cost7232
\[\left(\mathsf{fma}\left(z, t, x \cdot y\right) + a \cdot b\right) + c \cdot i \]
Alternative 3
Error59.01%
Cost3572
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -1.45 \cdot 10^{+108}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq -580000:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq -3.2 \cdot 10^{-107}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq -9.5 \cdot 10^{-162}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq -5 \cdot 10^{-323}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 2.7 \cdot 10^{-294}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 7.6 \cdot 10^{-187}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 4.5 \cdot 10^{-108}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 1.26 \cdot 10^{-46}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 6.4 \cdot 10^{-24}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 0.13:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 2300000000000:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 7.5 \cdot 10^{+20}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 4
Error36.2%
Cost2788
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := c \cdot i + z \cdot t\\ t_3 := c \cdot i + x \cdot y\\ \mathbf{if}\;a \cdot b \leq -1.9 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq -1.6 \cdot 10^{-59}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq -4 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq -2.1 \cdot 10^{-185}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq -5.5 \cdot 10^{-301}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \cdot b \leq 2.56 \cdot 10^{-253}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq 5.9 \cdot 10^{-152}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \cdot b \leq 1.4 \cdot 10^{-44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq 1.15 \cdot 10^{+54}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
Alternative 5
Error39.76%
Cost2268
\[\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 -1.8 \cdot 10^{+151}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq -192000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -1.1 \cdot 10^{-106}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -3.6 \cdot 10^{-215}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -5 \cdot 10^{-323}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 3.5 \cdot 10^{-114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.3 \cdot 10^{+33}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 6
Error35.11%
Cost2268
\[\begin{array}{l} t_1 := x \cdot y + z \cdot t\\ \mathbf{if}\;a \cdot b \leq -7.2 \cdot 10^{+30}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -1 \cdot 10^{-201}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq -5 \cdot 10^{-301}:\\ \;\;\;\;c \cdot i + x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 6.5 \cdot 10^{-227}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 4.1 \cdot 10^{-60}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 0.24:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{elif}\;a \cdot b \leq 2.3 \cdot 10^{+54}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
Alternative 7
Error35.7%
Cost2008
\[\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 -3.4 \cdot 10^{+106}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq -5 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -3.05 \cdot 10^{-214}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -5 \cdot 10^{-323}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 7.8 \cdot 10^{-112}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 2.9 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 8
Error34.43%
Cost2008
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := c \cdot i + x \cdot y\\ t_3 := a \cdot b + x \cdot y\\ \mathbf{if}\;c \cdot i \leq -5500000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -8.5 \cdot 10^{-106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -5.5 \cdot 10^{-215}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq -5 \cdot 10^{-323}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.7 \cdot 10^{-113}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq 56000000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error60.51%
Cost1752
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.8 \cdot 10^{+28}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -1.5 \cdot 10^{-189}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 5.6 \cdot 10^{-211}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq 9 \cdot 10^{-61}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 5200:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq 1.35 \cdot 10^{+131}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 10
Error14.29%
Cost1225
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -2.7 \cdot 10^{+112} \lor \neg \left(c \cdot i \leq 1.3 \cdot 10^{+33}\right):\\ \;\;\;\;c \cdot i + x \cdot y\\ \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 -1.05 \cdot 10^{+25} \lor \neg \left(c \cdot i \leq 7000000000\right):\\ \;\;\;\;c \cdot i + t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + t_1\\ \end{array} \]
Alternative 12
Error9.55%
Cost1225
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -2.1 \cdot 10^{+56} \lor \neg \left(c \cdot i \leq 4 \cdot 10^{-6}\right):\\ \;\;\;\;c \cdot i + \left(a \cdot b + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + \left(x \cdot y + z \cdot t\right)\\ \end{array} \]
Alternative 13
Error51.36%
Cost976
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ \mathbf{if}\;x \leq -5.2 \cdot 10^{+173}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.3 \cdot 10^{-100}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-108}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 14
Error0.03%
Cost960
\[c \cdot i + \left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) \]
Alternative 15
Error59.19%
Cost712
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -2.15 \cdot 10^{+21}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 750000000:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 16
Error74.26%
Cost192
\[a \cdot b \]

Error

Reproduce?

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