?

Average Error: 0.04% → 0.02%
Time: 16.2s
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(a, b, \mathsf{fma}\left(c, i, \mathsf{fma}\left(x, y, z \cdot t\right)\right)\right) \]
Alternative 2
Error35.81%
Cost3048
\[\begin{array}{l} t_1 := c \cdot i + x \cdot y\\ t_2 := a \cdot b + x \cdot y\\ t_3 := c \cdot i + z \cdot t\\ \mathbf{if}\;a \cdot b \leq -1.72 \cdot 10^{+72}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq -1.5 \cdot 10^{+33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq -1.85 \cdot 10^{-6}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq -1.5 \cdot 10^{-16}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \cdot b \leq 6.4 \cdot 10^{-300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 5.2 \cdot 10^{-235}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \cdot b \leq 3.15 \cdot 10^{-195}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 1.75 \cdot 10^{-118}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \cdot b \leq 4.7 \cdot 10^{-28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 40:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \end{array} \]
Alternative 3
Error36.69%
Cost2788
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := a \cdot b + x \cdot y\\ t_3 := c \cdot i + z \cdot t\\ \mathbf{if}\;c \cdot i \leq -2.5 \cdot 10^{+152}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \mathbf{elif}\;c \cdot i \leq -1.5 \cdot 10^{+16}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq -6 \cdot 10^{-30}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq -1.9 \cdot 10^{-162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 0:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 2.3 \cdot 10^{-186}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;c \cdot i \leq 1.08 \cdot 10^{-44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 1.12 \cdot 10^{+60}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.55 \cdot 10^{+103}:\\ \;\;\;\;c \cdot i + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error58.25%
Cost2272
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -2.65 \cdot 10^{+72}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -6.8 \cdot 10^{-184}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq 2.25 \cdot 10^{-291}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 2.3 \cdot 10^{-237}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 9.4 \cdot 10^{-195}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 2.2 \cdot 10^{-120}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 1.25 \cdot 10^{-26}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq 720000000000:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 5
Error43.4%
Cost2032
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := c \cdot i + z \cdot t\\ t_3 := a \cdot b + z \cdot t\\ t_4 := a \cdot b + c \cdot i\\ \mathbf{if}\;i \leq -2.05 \cdot 10^{-200}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq -2.2 \cdot 10^{-248}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq -7.8 \cdot 10^{-264}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;i \leq 4.6 \cdot 10^{-292}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 9.5 \cdot 10^{-251}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;i \leq 6.5 \cdot 10^{-41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 1.8 \cdot 10^{+20}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;i \leq 1.22 \cdot 10^{+48}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;i \leq 6.8 \cdot 10^{+72}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq 6 \cdot 10^{+106}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;i \leq 7.5 \cdot 10^{+185}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;i \leq 2.6 \cdot 10^{+208}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array} \]
Alternative 6
Error54.94%
Cost1768
\[\begin{array}{l} t_1 := a \cdot b + z \cdot t\\ \mathbf{if}\;i \leq -1.36 \cdot 10^{-118}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;i \leq -7.8 \cdot 10^{-209}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq -3.35 \cdot 10^{-248}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;i \leq 1.15 \cdot 10^{-240}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 2.6 \cdot 10^{-175}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;i \leq 7.6 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 4.5 \cdot 10^{-123}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;i \leq 2.25 \cdot 10^{-65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;i \leq 6.2 \cdot 10^{-42}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;i \leq 7 \cdot 10^{+166}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 7
Error39.17%
Cost1748
\[\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 -7.5 \cdot 10^{+163}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;c \cdot i \leq -3.25 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -1.55 \cdot 10^{-162}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 2.35 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 2.25 \cdot 10^{+70}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;c \cdot i\\ \end{array} \]
Alternative 8
Error35.92%
Cost1748
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ t_2 := a \cdot b + z \cdot t\\ t_3 := a \cdot b + c \cdot i\\ \mathbf{if}\;c \cdot i \leq -2.5 \cdot 10^{+152}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \cdot i \leq -1.72 \cdot 10^{+75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq -8.9 \cdot 10^{-159}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \cdot i \leq 5.1 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.15 \cdot 10^{+45}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 9
Error25.67%
Cost1496
\[\begin{array}{l} t_1 := c \cdot i + \left(a \cdot b + z \cdot t\right)\\ t_2 := a \cdot b + x \cdot y\\ \mathbf{if}\;y \leq -6.6 \cdot 10^{-89}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.06 \cdot 10^{+110}:\\ \;\;\;\;c \cdot i + x \cdot y\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{+129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+159}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+199}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \end{array} \]
Alternative 10
Error59.04%
Cost1492
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.5 \cdot 10^{+72}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -5.5 \cdot 10^{-300}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq 1.9 \cdot 10^{-113}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 9.8 \cdot 10^{-30}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;a \cdot b \leq 88000000000:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 11
Error20.23%
Cost1233
\[\begin{array}{l} t_1 := c \cdot i + \left(a \cdot b + z \cdot t\right)\\ \mathbf{if}\;z \leq -1.64 \cdot 10^{+198}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{+158}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{+129} \lor \neg \left(z \leq 2.4 \cdot 10^{-190}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;c \cdot i + \left(a \cdot b + x \cdot y\right)\\ \end{array} \]
Alternative 12
Error9.33%
Cost1225
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -5.5 \cdot 10^{+75} \lor \neg \left(a \cdot b \leq 1950000000000\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 13
Error0.04%
Cost960
\[\left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) + c \cdot i \]
Alternative 14
Error58.49%
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -8.5 \cdot 10^{+71}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 1.7 \cdot 10^{+16}:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 15
Error73.38%
Cost192
\[a \cdot b \]

Error

Reproduce?

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