Average Error: 0.0 → 0.0
Time: 11.5s
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(z, t, \mathsf{fma}\left(c, i, a \cdot b\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 z t (fma c i (* a b)))))
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(z, t, fma(c, i, (a * b))));
}
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(z, t, fma(c, i, Float64(a * b))))
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[(z * t + N[(c * i + N[(a * b), $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(z, t, \mathsf{fma}\left(c, i, a \cdot b\right)\right)\right)

Error

Derivation

  1. Initial program 0.0

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, \mathsf{fma}\left(c, i, a \cdot b\right)\right)\right)} \]
    Proof
    (fma.f64 x y (fma.f64 z t (fma.f64 c i (*.f64 a b)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x y (fma.f64 z t (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c i) (*.f64 a b))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x y (fma.f64 z t (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 a b) (*.f64 c i))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x y (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z t) (+.f64 (*.f64 a b) (*.f64 c i))))): 1 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x y) (+.f64 (*.f64 z t) (+.f64 (*.f64 a b) (*.f64 c i))))): 2 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (+.f64 (*.f64 a b) (*.f64 c i)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) (*.f64 c i))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost7232
\[\left(a \cdot b + c \cdot i\right) + \mathsf{fma}\left(t, z, x \cdot y\right) \]
Alternative 2
Error0.0
Cost7232
\[\mathsf{fma}\left(x, y, z \cdot t\right) + \left(a \cdot b + c \cdot i\right) \]
Alternative 3
Error26.9
Cost1768
\[\begin{array}{l} t_1 := c \cdot i + z \cdot t\\ t_2 := a \cdot b + c \cdot i\\ t_3 := x \cdot y + z \cdot t\\ t_4 := c \cdot i + x \cdot y\\ t_5 := a \cdot b + z \cdot t\\ \mathbf{if}\;y \leq -3.6 \cdot 10^{-136}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-244}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-243}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;y \leq 6.6 \cdot 10^{-178}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-68}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-52}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.06 \cdot 10^{-13}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+106}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{+167}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{+210}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error41.4
Cost1644
\[\begin{array}{l} \mathbf{if}\;z \leq -5.5 \cdot 10^{+15}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-96}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq -2.05 \cdot 10^{-138}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-155}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-226}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-246}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq 5.1 \cdot 10^{-307}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-282}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{-208}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-42}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-8}:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
Alternative 5
Error31.6
Cost1636
\[\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\\ \mathbf{if}\;x \leq -5.5 \cdot 10^{+209}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -5 \cdot 10^{+95}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.28 \cdot 10^{-20}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.5 \cdot 10^{-45}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-143}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-250}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-305}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 1.06 \cdot 10^{-196}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.4 \cdot 10^{-53}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 6
Error25.8
Cost1636
\[\begin{array}{l} t_1 := c \cdot i + x \cdot y\\ t_2 := c \cdot i + z \cdot t\\ t_3 := a \cdot b + c \cdot i\\ \mathbf{if}\;z \leq -3.8 \cdot 10^{+201}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.22 \cdot 10^{+35}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{elif}\;z \leq -2.25 \cdot 10^{+18}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -4.4 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-139}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-225}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -9.2 \cdot 10^{-302}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{-40}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error31.9
Cost1504
\[\begin{array}{l} t_1 := a \cdot b + c \cdot i\\ \mathbf{if}\;z \leq -6.2 \cdot 10^{+254}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;z \leq -1.32 \cdot 10^{+239}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1 \cdot 10^{+174}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{+105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{+36}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6 \cdot 10^{-96}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-8}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
Alternative 8
Error41.4
Cost1248
\[\begin{array}{l} \mathbf{if}\;z \leq -1.46 \cdot 10^{+35}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{-76}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-109}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-121}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;z \leq -1.82 \cdot 10^{-233}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;z \leq 4.1 \cdot 10^{-206}:\\ \;\;\;\;c \cdot i\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-44}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-22}:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
Alternative 9
Error8.4
Cost1224
\[\begin{array}{l} t_1 := a \cdot b + c \cdot i\\ \mathbf{if}\;c \cdot i \leq -7.5 \cdot 10^{+63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 4.2 \cdot 10^{+105}:\\ \;\;\;\;a \cdot b + \left(x \cdot y + z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error8.0
Cost1224
\[\begin{array}{l} t_1 := x \cdot y + z \cdot t\\ \mathbf{if}\;a \cdot b \leq -9 \cdot 10^{+123}:\\ \;\;\;\;a \cdot b + t_1\\ \mathbf{elif}\;a \cdot b \leq 6.5 \cdot 10^{+74}:\\ \;\;\;\;c \cdot i + t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + c \cdot i\\ \end{array} \]
Alternative 11
Error6.2
Cost1224
\[\begin{array}{l} t_1 := \left(a \cdot b + c \cdot i\right) + z \cdot t\\ \mathbf{if}\;a \cdot b \leq -6.2 \cdot 10^{+60}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 2.8 \cdot 10^{+70}:\\ \;\;\;\;c \cdot i + \left(x \cdot y + z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error22.0
Cost968
\[\begin{array}{l} t_1 := a \cdot b + c \cdot i\\ \mathbf{if}\;c \cdot i \leq -31500000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \cdot i \leq 1.55 \cdot 10^{+19}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error0.0
Cost960
\[c \cdot i + \left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) \]
Alternative 14
Error38.4
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -9 \cdot 10^{+123}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 4.2 \cdot 10^{+81}:\\ \;\;\;\;c \cdot i\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 15
Error47.0
Cost192
\[a \cdot b \]

Error

Reproduce

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