\[\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\]
↓
\[\begin{array}{l}
t_1 := y \cdot x + a \cdot b\\
\mathbf{if}\;c \cdot i \leq -5 \cdot 10^{+19}:\\
\;\;\;\;c \cdot i + y \cdot x\\
\mathbf{elif}\;c \cdot i \leq -2 \cdot 10^{-160}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-197}:\\
\;\;\;\;a \cdot b + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-275}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{-293}:\\
\;\;\;\;y \cdot x + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{-188}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{+35}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(c, i, a \cdot b\right)\\
\end{array}
\]
(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
(let* ((t_1 (+ (* y x) (* a b))))
(if (<= (* c i) -5e+19)
(+ (* c i) (* y x))
(if (<= (* c i) -2e-160)
(fma y x (* a b))
(if (<= (* c i) -1e-197)
(+ (* a b) (* t z))
(if (<= (* c i) -1e-275)
t_1
(if (<= (* c i) 5e-293)
(+ (* y x) (* t z))
(if (<= (* c i) 4e-188)
t_1
(if (<= (* c i) 2e+35)
(fma y x (* t z))
(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);
}
\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
↓
\begin{array}{l}
t_1 := y \cdot x + a \cdot b\\
\mathbf{if}\;c \cdot i \leq -5 \cdot 10^{+19}:\\
\;\;\;\;c \cdot i + y \cdot x\\
\mathbf{elif}\;c \cdot i \leq -2 \cdot 10^{-160}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-197}:\\
\;\;\;\;a \cdot b + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-275}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{-293}:\\
\;\;\;\;y \cdot x + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{-188}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{+35}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(c, i, a \cdot b\right)\\
\end{array}
Error
Derivation
Split input into 7 regimes
if (*.f64 c i) < -5e19
Initial program 0.0
\[\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\]
Taylor expanded in x around inf 21.1
\[\leadsto \color{blue}{y \cdot x} + c \cdot i
\]
if -5e19 < (*.f64 c i) < -2e-160
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(c, i, \mathsf{fma}\left(a, b, z \cdot t\right)\right)\right)}
\]
Taylor expanded in z around 0 18.5
\[\leadsto \mathsf{fma}\left(x, y, \color{blue}{c \cdot i + a \cdot b}\right)
\]
Taylor expanded in c around 0 24.0
\[\leadsto \color{blue}{a \cdot b + y \cdot x}
\]
Simplified24.0
\[\leadsto \color{blue}{\mathsf{fma}\left(y, x, a \cdot b\right)}
\]
if -2e-160 < (*.f64 c i) < -9.9999999999999999e-198
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(c, i, \mathsf{fma}\left(a, b, z \cdot t\right)\right)\right)}
\]
Taylor expanded in c around 0 1.5
\[\leadsto \color{blue}{a \cdot b + \left(y \cdot x + t \cdot z\right)}
\]
Simplified1.5
\[\leadsto \color{blue}{\mathsf{fma}\left(t, z, \mathsf{fma}\left(y, x, a \cdot b\right)\right)}
\]
Taylor expanded in y around 0 20.1
\[\leadsto \color{blue}{a \cdot b + t \cdot z}
\]
if -9.9999999999999999e-198 < (*.f64 c i) < -9.99999999999999934e-276 or 5.0000000000000003e-293 < (*.f64 c i) < 3.9999999999999998e-188
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(c, i, \mathsf{fma}\left(a, b, z \cdot t\right)\right)\right)}
\]
Taylor expanded in z around 0 21.5
\[\leadsto \mathsf{fma}\left(x, y, \color{blue}{c \cdot i + a \cdot b}\right)
\]
Taylor expanded in c around 0 22.3
\[\leadsto \color{blue}{a \cdot b + y \cdot x}
\]
if -9.99999999999999934e-276 < (*.f64 c i) < 5.0000000000000003e-293
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(c, i, \mathsf{fma}\left(a, b, z \cdot t\right)\right)\right)}
\]
Taylor expanded in a around 0 22.4
\[\leadsto \mathsf{fma}\left(x, y, \color{blue}{c \cdot i + t \cdot z}\right)
\]
Taylor expanded in c around 0 22.4
\[\leadsto \color{blue}{y \cdot x + t \cdot z}
\]
if 3.9999999999999998e-188 < (*.f64 c i) < 1.9999999999999999e35
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(c, i, \mathsf{fma}\left(a, b, z \cdot t\right)\right)\right)}
\]
Taylor expanded in a around 0 18.0
\[\leadsto \mathsf{fma}\left(x, y, \color{blue}{c \cdot i + t \cdot z}\right)
\]
Taylor expanded in c around 0 26.5
\[\leadsto \color{blue}{y \cdot x + t \cdot z}
\]
Simplified26.4
\[\leadsto \color{blue}{\mathsf{fma}\left(y, x, t \cdot z\right)}
\]
if 1.9999999999999999e35 < (*.f64 c i)
Initial program 0.0
\[\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\]
Applied egg-rr0.0
\[\leadsto \color{blue}{\mathsf{fma}\left(c, i, \mathsf{fma}\left(a, b, \mathsf{fma}\left(x, y, z \cdot t\right)\right)\right)}
\]
Taylor expanded in a around inf 17.5
\[\leadsto \mathsf{fma}\left(c, i, \color{blue}{a \cdot b}\right)
\]
Recombined 7 regimes into one program.
Final simplification22.2
\[\leadsto \begin{array}{l}
\mathbf{if}\;c \cdot i \leq -5 \cdot 10^{+19}:\\
\;\;\;\;c \cdot i + y \cdot x\\
\mathbf{elif}\;c \cdot i \leq -2 \cdot 10^{-160}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-197}:\\
\;\;\;\;a \cdot b + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-275}:\\
\;\;\;\;y \cdot x + a \cdot b\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{-293}:\\
\;\;\;\;y \cdot x + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{-188}:\\
\;\;\;\;y \cdot x + a \cdot b\\
\mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{+35}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(c, i, a \cdot b\right)\\
\end{array}
\]
Alternatives
Alternative 1
Error
22.2
Cost
8540
\[\begin{array}{l}
t_1 := y \cdot x + a \cdot b\\
\mathbf{if}\;c \cdot i \leq -5 \cdot 10^{+19}:\\
\;\;\;\;c \cdot i + y \cdot x\\
\mathbf{elif}\;c \cdot i \leq -2 \cdot 10^{-160}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-197}:\\
\;\;\;\;a \cdot b + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-275}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{-293}:\\
\;\;\;\;y \cdot x + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{-188}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{+35}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + a \cdot b\\
\end{array}
\]
Alternative 2
Error
22.2
Cost
7240
\[\begin{array}{l}
t_1 := y \cdot x + a \cdot b\\
t_2 := y \cdot x + t \cdot z\\
\mathbf{if}\;c \cdot i \leq -5 \cdot 10^{+19}:\\
\;\;\;\;c \cdot i + y \cdot x\\
\mathbf{elif}\;c \cdot i \leq -2 \cdot 10^{-160}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-197}:\\
\;\;\;\;a \cdot b + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq -1 \cdot 10^{-275}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{-293}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{-188}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{+35}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + a \cdot b\\
\end{array}
\]
\[\begin{array}{l}
t_1 := y \cdot x + a \cdot b\\
t_2 := y \cdot x + t \cdot z\\
\mathbf{if}\;c \cdot i \leq -5.946016544694227 \cdot 10^{+19}:\\
\;\;\;\;c \cdot i + y \cdot x\\
\mathbf{elif}\;c \cdot i \leq -3.2952542024009906 \cdot 10^{-160}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq -1.8023883484232276 \cdot 10^{-197}:\\
\;\;\;\;a \cdot b + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq -1.1598427972431649 \cdot 10^{-275}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 3.046023912528629 \cdot 10^{-293}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 2.2062193131170184 \cdot 10^{-188}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 1.5579540771888221 \cdot 10^{+35}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + a \cdot b\\
\end{array}
\]
Alternative 5
Error
22.1
Cost
1748
\[\begin{array}{l}
t_1 := y \cdot x + a \cdot b\\
t_2 := y \cdot x + t \cdot z\\
\mathbf{if}\;c \cdot i \leq -1.0005989168943282 \cdot 10^{+77}:\\
\;\;\;\;c \cdot i + t \cdot z\\
\mathbf{elif}\;c \cdot i \leq -1.1598427972431649 \cdot 10^{-275}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 3.046023912528629 \cdot 10^{-293}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 2.2062193131170184 \cdot 10^{-188}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 1.5579540771888221 \cdot 10^{+35}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + a \cdot b\\
\end{array}
\]
Alternative 6
Error
22.3
Cost
1748
\[\begin{array}{l}
t_1 := y \cdot x + a \cdot b\\
t_2 := y \cdot x + t \cdot z\\
\mathbf{if}\;c \cdot i \leq -5.946016544694227 \cdot 10^{+19}:\\
\;\;\;\;c \cdot i + y \cdot x\\
\mathbf{elif}\;c \cdot i \leq -1.1598427972431649 \cdot 10^{-275}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 3.046023912528629 \cdot 10^{-293}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \cdot i \leq 2.2062193131170184 \cdot 10^{-188}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \cdot i \leq 1.5579540771888221 \cdot 10^{+35}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;c \cdot i + a \cdot b\\
\end{array}
\]
herbie shell --seed 2022228
(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)))