?

Average Error: 0.04% → 0.02%
Time: 13.6s
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.02%
Cost19776
\[\mathsf{fma}\left(c, i, \mathsf{fma}\left(a, b, \mathsf{fma}\left(x, y, z \cdot t\right)\right)\right) \]
Alternative 2
Error62.88%
Cost2012
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -8 \cdot 10^{-50}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq -1.85 \cdot 10^{-152}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 3.4 \cdot 10^{-200}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 1.15 \cdot 10^{-10}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 6.2 \cdot 10^{+82}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq 1.8 \cdot 10^{+92}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;c \cdot i \leq 1.2 \cdot 10^{+182}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 3
Error58.89%
Cost2012
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.65 \cdot 10^{+50}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -4.9 \cdot 10^{-206}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -1.2 \cdot 10^{-250}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq -5.5 \cdot 10^{-270}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 1.9 \cdot 10^{-92}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq 6.7 \cdot 10^{-16}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 2.9 \cdot 10^{+26}:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 4
Error35.46%
Cost2008
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := c \cdot i + x \cdot y\\ \mathbf{if}\;c \cdot i \leq -1.28 \cdot 10^{-48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -5.1 \cdot 10^{-152}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 6 \cdot 10^{-199}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 3.4 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 5.5 \cdot 10^{+82}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{+93}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \end{array} \]
Alternative 5
Error42.92%
Cost1900
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := a \cdot b + c \cdot i\\ t_3 := c \cdot i + z \cdot t\\ \mathbf{if}\;a \leq -2.6 \cdot 10^{+165}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{elif}\;a \leq -3.6 \cdot 10^{-44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.8 \cdot 10^{-130}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -9.6 \cdot 10^{-169}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -9.5 \cdot 10^{-236}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -8.5 \cdot 10^{-260}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \leq -2.1 \cdot 10^{-275}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2.05 \cdot 10^{-141}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 6.4 \cdot 10^{-114}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 7.6 \cdot 10^{-66}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 8200000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error41.18%
Cost1769
\[\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}\;t \leq -1.1 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.8 \cdot 10^{-306}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 6.6 \cdot 10^{-292}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.15 \cdot 10^{-230}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 9 \cdot 10^{-165}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 6.4 \cdot 10^{-34}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{elif}\;t \leq 2.1 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.02 \cdot 10^{+33}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.7 \cdot 10^{+46} \lor \neg \left(t \leq 9 \cdot 10^{+70}\right):\\ \;\;\;\;c \cdot i + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 7
Error49.56%
Cost1638
\[\begin{array}{l} t_1 := a \cdot b + c \cdot i\\ \mathbf{if}\;t \leq -8.3 \cdot 10^{-193}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.2 \cdot 10^{-264}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t \leq 2.85 \cdot 10^{-213}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.05 \cdot 10^{-185}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{-32} \lor \neg \left(t \leq 0.108\right) \land \left(t \leq 5.1 \cdot 10^{+32} \lor \neg \left(t \leq 3.5 \cdot 10^{+192}\right) \land t \leq 1.4 \cdot 10^{+212}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
Alternative 8
Error35.17%
Cost1488
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := a \cdot b + c \cdot i\\ \mathbf{if}\;c \cdot i \leq -6.4 \cdot 10^{-18}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -1.15 \cdot 10^{-149}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 4.2 \cdot 10^{-200}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 10^{+23}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Error49.39%
Cost1241
\[\begin{array}{l} t_1 := a \cdot b + c \cdot i\\ \mathbf{if}\;y \leq -8.8 \cdot 10^{-25}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-299}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-266}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;y \leq 2.95 \cdot 10^{+167} \lor \neg \left(y \leq 1.7 \cdot 10^{+214}\right) \land y \leq 4.4 \cdot 10^{+228}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 10
Error14.88%
Cost1224
\[\begin{array}{l} \mathbf{if}\;c \cdot i \leq -1.05 \cdot 10^{+59}:\\ \;\;\;\;c \cdot i + x \cdot y\\ \mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{+190}:\\ \;\;\;\;a \cdot b + \left(x \cdot y + z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + z \cdot t\\ \end{array} \]
Alternative 11
Error0.04%
Cost960
\[\left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) + c \cdot i \]
Alternative 12
Error59.49%
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -5.4 \cdot 10^{-16}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 7 \cdot 10^{+32}:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 13
Error73.55%
Cost192
\[a \cdot b \]

Error

Reproduce?

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