?

Average Error: 0.04% → 0.02%
Time: 14.2s
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.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(c, i, \mathsf{fma}\left(a, b, \mathsf{fma}\left(x, y, 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 \]

    +-commutative [=>]0.04

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

    \[ \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
Error44.07%
Cost2428
\[\begin{array}{l} t_1 := a \cdot b + c \cdot i\\ t_2 := a \cdot b + z \cdot t\\ t_3 := c \cdot i + z \cdot t\\ t_4 := c \cdot i + x \cdot y\\ t_5 := a \cdot b + x \cdot y\\ \mathbf{if}\;x \leq -1.05 \cdot 10^{+220}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -8 \cdot 10^{+199}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{+149}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{+117}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{+76}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-21}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -2.6 \cdot 10^{-42}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-62}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-121}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-158}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{-194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.5 \cdot 10^{-277}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-224}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-176}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-141}:\\ \;\;\;\;t_5\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array} \]
Alternative 2
Error43.67%
Cost2164
\[\begin{array}{l} t_1 := c \cdot i + z \cdot t\\ t_2 := a \cdot b + c \cdot i\\ t_3 := a \cdot b + z \cdot t\\ t_4 := x \cdot y + z \cdot t\\ t_5 := a \cdot b + x \cdot y\\ \mathbf{if}\;x \leq -7.6 \cdot 10^{+164}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -7 \cdot 10^{+116}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.9 \cdot 10^{+70}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;x \leq -3.1 \cdot 10^{-21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{-38}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-62}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -1.12 \cdot 10^{-119}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-158}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-194}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{-278}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-222}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-176}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-140}:\\ \;\;\;\;t_5\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array} \]
Alternative 3
Error67.01%
Cost1908
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+149}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -4.3 \cdot 10^{+117}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;x \leq -3.35 \cdot 10^{+81}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-21}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{-121}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{-158}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \leq -3.9 \cdot 10^{-196}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;x \leq -7.5 \cdot 10^{-229}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-278}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-272}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-223}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{-172}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-137}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 4
Error42.71%
Cost1508
\[\begin{array}{l} \mathbf{if}\;b \leq -7 \cdot 10^{-55} \lor \neg \left(b \leq 7 \cdot 10^{-301} \lor \neg \left(b \leq 1.02 \cdot 10^{-259}\right) \land \left(b \leq 0.00072 \lor \neg \left(b \leq 5.4 \cdot 10^{+22}\right) \land \left(b \leq 1.6 \cdot 10^{+65} \lor \neg \left(b \leq 1.02 \cdot 10^{+96}\right) \land b \leq 10^{+114}\right)\right)\right):\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \end{array} \]
Alternative 5
Error14.41%
Cost1224
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -6200000000000:\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 7.5 \cdot 10^{+112}:\\ \;\;\;\;a \cdot b + \left(x \cdot y + z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + x \cdot y\\ \end{array} \]
Alternative 6
Error10.3%
Cost1224
\[\begin{array}{l} t_1 := x \cdot y + z \cdot t\\ \mathbf{if}\;a \cdot b \leq -8.2 \cdot 10^{-25}:\\ \;\;\;\;c \cdot i + \left(a \cdot b + x \cdot y\right)\\ \mathbf{elif}\;a \cdot b \leq 1.3 \cdot 10^{-30}:\\ \;\;\;\;c \cdot i + t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + t_1\\ \end{array} \]
Alternative 7
Error52.45%
Cost977
\[\begin{array}{l} \mathbf{if}\;z \leq -1.55 \cdot 10^{+242}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;z \leq -1.06 \cdot 10^{+181} \lor \neg \left(z \leq -1.05 \cdot 10^{+85}\right) \land z \leq 7.2 \cdot 10^{-134}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
Alternative 8
Error16.97%
Cost969
\[\begin{array}{l} \mathbf{if}\;t \leq -4.9 \cdot 10^{-48} \lor \neg \left(t \leq 1.28 \cdot 10^{+45}\right):\\ \;\;\;\;a \cdot b + \left(x \cdot y + z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + \left(a \cdot b + x \cdot y\right)\\ \end{array} \]
Alternative 9
Error0.04%
Cost960
\[c \cdot i + \left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) \]
Alternative 10
Error65.95%
Cost852
\[\begin{array}{l} \mathbf{if}\;t \leq -3.5 \cdot 10^{-48}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;t \leq 5.1 \cdot 10^{-294}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{-260}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;t \leq 1.25 \cdot 10^{-29}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{+100}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
Alternative 11
Error42.48%
Cost844
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ \mathbf{if}\;z \leq -6.7 \cdot 10^{+74}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{-290}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-122}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error41.73%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -2.3 \cdot 10^{-48} \lor \neg \left(t \leq 1.35 \cdot 10^{+58}\right):\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \end{array} \]
Alternative 13
Error60.17%
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -3.2 \cdot 10^{-29}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 8 \cdot 10^{-31}:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 14
Error74.28%
Cost192
\[a \cdot b \]

Error

Reproduce?

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