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))))): 2 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
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
22.0
Cost
2788
\[\begin{array}{l}
t_1 := c \cdot i + x \cdot y\\
t_2 := a \cdot b + x \cdot y\\
t_3 := a \cdot b + z \cdot t\\
t_4 := x \cdot y + z \cdot t\\
\mathbf{if}\;c \cdot i \leq -6.5 \cdot 10^{-5}:\\
\;\;\;\;c \cdot i + z \cdot t\\
\mathbf{elif}\;c \cdot i \leq -3.5 \cdot 10^{-62}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq -8.5 \cdot 10^{-204}:\\
\;\;\;\;t_4\\
\mathbf{elif}\;c \cdot i \leq -1.02 \cdot 10^{-284}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 3.4 \cdot 10^{-301}:\\
\;\;\;\;t_4\\
\mathbf{elif}\;c \cdot i \leq 2.5 \cdot 10^{-168}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 2.6 \cdot 10^{-36}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;c \cdot i \leq 62000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 9.5 \cdot 10^{+21}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
\[\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 -6.5 \cdot 10^{-5}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;c \cdot i \leq 3.5 \cdot 10^{-167}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 1.85 \cdot 10^{-42}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 0.9:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 8 \cdot 10^{+21}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}
\]
Alternative 4
Error
21.9
Cost
1748
\[\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 -6.5 \cdot 10^{-5}:\\
\;\;\;\;c \cdot i + z \cdot t\\
\mathbf{elif}\;c \cdot i \leq 1.65 \cdot 10^{-165}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 6 \cdot 10^{-41}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 0.0255:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 4.6 \cdot 10^{+22}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + c \cdot i\\
\end{array}
\]
Alternative 5
Error
22.1
Cost
1748
\[\begin{array}{l}
t_1 := c \cdot i + x \cdot y\\
t_2 := a \cdot b + z \cdot t\\
\mathbf{if}\;c \cdot i \leq -6.5 \cdot 10^{-5}:\\
\;\;\;\;c \cdot i + z \cdot t\\
\mathbf{elif}\;c \cdot i \leq 3.5 \cdot 10^{-162}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{elif}\;c \cdot i \leq 1.8 \cdot 10^{-36}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 64000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 1.75 \cdot 10^{+22}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
\[\begin{array}{l}
t_1 := a \cdot b + \left(c \cdot i + x \cdot y\right)\\
\mathbf{if}\;c \cdot i \leq -1.05 \cdot 10^{+33}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 1.8 \cdot 10^{+22}:\\
\;\;\;\;a \cdot b + \left(x \cdot y + z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
herbie shell --seed 2022329
(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)))