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))))): 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
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
24.5
Cost
3048
\[\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
t_2 := a \cdot b + x \cdot y\\
\mathbf{if}\;c \cdot i \leq -1.5861817794182834 \cdot 10^{+111}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;c \cdot i \leq -1.9783636499985824 \cdot 10^{+72}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -6.725002976982434 \cdot 10^{+28}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;c \cdot i \leq -2.60329005008175:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq -3.6536423374613737 \cdot 10^{-153}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -1.7928102115681634 \cdot 10^{-189}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 3.407894878446139 \cdot 10^{-233}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 7.354243352626241 \cdot 10^{-120}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 3.6444506979209956 \cdot 10^{-10}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 2.4752696748309327 \cdot 10^{+125}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;c \cdot i\\
\end{array}
\]
Alternative 3
Error
24.3
Cost
3048
\[\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
t_2 := a \cdot b + x \cdot y\\
t_3 := x \cdot y + z \cdot t\\
\mathbf{if}\;c \cdot i \leq -1.5861817794182834 \cdot 10^{+111}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;c \cdot i \leq -1.9783636499985824 \cdot 10^{+72}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -6.725002976982434 \cdot 10^{+28}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;c \cdot i \leq -4.746280094471139:\\
\;\;\;\;t_3\\
\mathbf{elif}\;c \cdot i \leq -3.6536423374613737 \cdot 10^{-153}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -1.7928102115681634 \cdot 10^{-189}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 3.407894878446139 \cdot 10^{-233}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 7.354243352626241 \cdot 10^{-120}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 8.563812012560354 \cdot 10^{-11}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 2.245671752058582 \cdot 10^{+120}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;c \cdot i\\
\end{array}
\]
Alternative 4
Error
22.2
Cost
2268
\[\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
t_2 := a \cdot b + x \cdot y\\
t_3 := a \cdot b + c \cdot i\\
\mathbf{if}\;c \cdot i \leq -6.725002976982434 \cdot 10^{+28}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;c \cdot i \leq -3.6536423374613737 \cdot 10^{-153}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -1.7928102115681634 \cdot 10^{-189}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 3.407894878446139 \cdot 10^{-233}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 7.354243352626241 \cdot 10^{-120}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 8.563812012560354 \cdot 10^{-11}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 2.245671752058582 \cdot 10^{+120}:\\
\;\;\;\;x \cdot y + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}
\]
Alternative 5
Error
21.9
Cost
2268
\[\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
t_2 := a \cdot b + x \cdot y\\
\mathbf{if}\;c \cdot i \leq -6.725002976982434 \cdot 10^{+28}:\\
\;\;\;\;a \cdot b + c \cdot i\\
\mathbf{elif}\;c \cdot i \leq -3.6536423374613737 \cdot 10^{-153}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -1.7928102115681634 \cdot 10^{-189}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 3.407894878446139 \cdot 10^{-233}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 7.354243352626241 \cdot 10^{-120}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 8.563812012560354 \cdot 10^{-11}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 2.2657300911518845 \cdot 10^{+103}:\\
\;\;\;\;x \cdot y + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + z \cdot t\\
\end{array}
\]
Alternative 6
Error
26.7
Cost
1900
\[\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\\
t_4 := a \cdot b + x \cdot y\\
\mathbf{if}\;t \leq -3.602923674511332 \cdot 10^{-119}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t \leq 1.810090742487807 \cdot 10^{-278}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t \leq 3.583183976748807 \cdot 10^{-222}:\\
\;\;\;\;t_4\\
\mathbf{elif}\;t \leq 2.463730693800578 \cdot 10^{-104}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t \leq 4.954048685970513 \cdot 10^{-69}:\\
\;\;\;\;c \cdot i + x \cdot y\\
\mathbf{elif}\;t \leq 14.225072778404131:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t \leq 3.0422334852816393 \cdot 10^{+41}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t \leq 10^{+85}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t \leq 10^{+104}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t \leq 9.5 \cdot 10^{+164}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t \leq 1.1 \cdot 10^{+207}:\\
\;\;\;\;t_4\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\]
\[\begin{array}{l}
t_1 := a \cdot b + x \cdot y\\
\mathbf{if}\;c \cdot i \leq -6.725002976982434 \cdot 10^{+28}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;c \cdot i \leq -1.7928102115681634 \cdot 10^{-189}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -1.9288925597302295 \cdot 10^{-276}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;c \cdot i \leq 2.4752696748309327 \cdot 10^{+125}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;c \cdot i\\
\end{array}
\]
Alternative 10
Error
9.3
Cost
1224
\[\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -6.725002976982434 \cdot 10^{+28}:\\
\;\;\;\;a \cdot b + c \cdot i\\
\mathbf{elif}\;c \cdot i \leq 2.4752696748309327 \cdot 10^{+125}:\\
\;\;\;\;x \cdot y + \left(a \cdot b + z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + z \cdot t\\
\end{array}
\]
Alternative 11
Error
6.0
Cost
1224
\[\begin{array}{l}
t_1 := c \cdot i + \left(x \cdot y + z \cdot t\right)\\
\mathbf{if}\;c \cdot i \leq -6.725002976982434 \cdot 10^{+28}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 8.563812012560354 \cdot 10^{-11}:\\
\;\;\;\;x \cdot y + \left(a \cdot b + z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
Alternative 12
Error
0.0
Cost
960
\[\left(a \cdot b + \left(x \cdot y + z \cdot t\right)\right) + c \cdot i
\]
herbie shell --seed 2022318
(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)))