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
Initial program 0.0
\[\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\]
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))))): 4 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))))): 1 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
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
Error
0.0
Cost
13504
\[\mathsf{fma}\left(z, t, \mathsf{fma}\left(c, i, a \cdot b\right)\right) + x \cdot y
\]
Alternative 2
Error
0.0
Cost
7232
\[x \cdot y + \left(a \cdot b + \mathsf{fma}\left(z, t, c \cdot i\right)\right)
\]
Alternative 3
Error
22.9
Cost
2528
\[\begin{array}{l}
t_1 := a \cdot b + c \cdot i\\
t_2 := x \cdot y + z \cdot t\\
t_3 := c \cdot i + z \cdot t\\
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+93}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot y \leq -1 \cdot 10^{+42}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot y \leq -5 \cdot 10^{-176}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-204}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-166}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;x \cdot y \leq 2.3 \cdot 10^{-25}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot y \leq 0.01:\\
\;\;\;\;t_3\\
\mathbf{elif}\;x \cdot y \leq 10^{+109}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\]
Alternative 4
Error
27.3
Cost
2268
\[\begin{array}{l}
t_1 := x \cdot y + z \cdot t\\
t_2 := a \cdot b + x \cdot y\\
\mathbf{if}\;a \cdot b \leq -6.602995088872467 \cdot 10^{+95}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;a \cdot b \leq -4.284678858099299 \cdot 10^{-12}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;a \cdot b \leq -5.357299628203318 \cdot 10^{-24}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;a \cdot b \leq -7.781851573985181 \cdot 10^{-202}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;a \cdot b \leq 2.946772324054719 \cdot 10^{-149}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;a \cdot b \leq 3.76775614528453 \cdot 10^{-83}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;a \cdot b \leq 3.7143353556154977 \cdot 10^{-17}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\]
Alternative 5
Error
24.0
Cost
2008
\[\begin{array}{l}
t_1 := a \cdot b + c \cdot i\\
t_2 := x \cdot y + z \cdot t\\
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+93}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot y \leq -1 \cdot 10^{+42}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot y \leq -6 \cdot 10^{-62}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-204}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \cdot y \leq 10^{-175}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;x \cdot y \leq 10^{+109}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\]
\[\begin{array}{l}
t_1 := a \cdot b + x \cdot y\\
\mathbf{if}\;c \cdot i \leq -3.6 \cdot 10^{+55}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;c \cdot i \leq -1.2837655069738792 \cdot 10^{-84}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -7.230569029682756 \cdot 10^{-156}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;c \cdot i \leq 7.703326665501798 \cdot 10^{+62}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;c \cdot i\\
\end{array}
\]
Alternative 8
Error
8.9
Cost
1224
\[\begin{array}{l}
t_1 := c \cdot i + z \cdot t\\
\mathbf{if}\;c \cdot i \leq -3.6 \cdot 10^{+55}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 7.703326665501798 \cdot 10^{+62}:\\
\;\;\;\;x \cdot y + \left(a \cdot b + z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
herbie shell --seed 2022291
(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)))