\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\]
↓
\[\begin{array}{l}
t_1 := z \cdot t + x \cdot y\\
t_2 := c \cdot \left(a + b \cdot c\right)\\
t_3 := b \cdot c - a\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{+160}:\\
\;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\frac{\frac{t_3}{\mathsf{fma}\left(c, b, a\right)}}{t_3}}\right)\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+302}:\\
\;\;\;\;2 \cdot \left(t_1 - t_2 \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\end{array}
\]
(FPCore (x y z t a b c i)
:precision binary64
(* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))
↓
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (+ (* z t) (* x y)))
(t_2 (* c (+ a (* b c))))
(t_3 (- (* b c) a)))
(if (<= t_2 -5e+160)
(* 2.0 (- (fma x y (* z t)) (/ (* c i) (/ (/ t_3 (fma c b a)) t_3))))
(if (<= t_2 5e+302)
(* 2.0 (- t_1 (* t_2 i)))
(* 2.0 (- t_1 (* c (* c (* b i)))))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i));
}
2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
↓
\begin{array}{l}
t_1 := z \cdot t + x \cdot y\\
t_2 := c \cdot \left(a + b \cdot c\right)\\
t_3 := b \cdot c - a\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{+160}:\\
\;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\frac{\frac{t_3}{\mathsf{fma}\left(c, b, a\right)}}{t_3}}\right)\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+302}:\\
\;\;\;\;2 \cdot \left(t_1 - t_2 \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\end{array}
Error
Target
Original
6.4
Target
1.9
Herbie
1.9
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right)
\]
Derivation
Split input into 3 regimes
if (*.f64 (+.f64 a (*.f64 b c)) c) < -5.0000000000000002e160
Initial program 26.0
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\]
Simplified5.1
\[\leadsto \color{blue}{2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(\mathsf{fma}\left(b, c, a\right) \cdot i\right)\right)}
\]
Proof
[Start]26.0
\[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\]
*-commutative [=>]26.0
\[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \color{blue}{\left(c \cdot \left(a + b \cdot c\right)\right)} \cdot i\right)
\]
associate-*l* [=>]5.1
\[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \color{blue}{c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)}\right)
\]
cancel-sign-sub-inv [=>]5.1
\[ 2 \cdot \color{blue}{\left(\left(x \cdot y + z \cdot t\right) + \left(-c\right) \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)}
\]
cancel-sign-sub [<=]5.1
\[ 2 \cdot \color{blue}{\left(\left(x \cdot y + z \cdot t\right) - \left(-\left(-c\right)\right) \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)}
\]
fma-def [=>]5.1
\[ 2 \cdot \left(\color{blue}{\mathsf{fma}\left(x, y, z \cdot t\right)} - \left(-\left(-c\right)\right) \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)
\]
remove-double-neg [=>]5.1
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{c} \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)
\]
+-commutative [=>]5.1
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(\color{blue}{\left(b \cdot c + a\right)} \cdot i\right)\right)
\]
fma-def [=>]5.1
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(\color{blue}{\mathsf{fma}\left(b, c, a\right)} \cdot i\right)\right)
\]
Applied egg-rr49.2
\[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{\frac{\left(c \cdot i\right) \cdot \left(\left(c \cdot b\right) \cdot \left(c \cdot b\right) - a \cdot a\right)}{c \cdot b - a}}\right)
\]
Simplified4.6
\[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{\frac{c \cdot i}{\frac{\frac{c \cdot b - a}{\mathsf{fma}\left(c, b, a\right)}}{c \cdot b - a}}}\right)
\]
Proof
[Start]49.2
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{\left(c \cdot i\right) \cdot \left(\left(c \cdot b\right) \cdot \left(c \cdot b\right) - a \cdot a\right)}{c \cdot b - a}\right)
\]
associate-/l* [=>]44.7
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{\frac{c \cdot i}{\frac{c \cdot b - a}{\left(c \cdot b\right) \cdot \left(c \cdot b\right) - a \cdot a}}}\right)
\]
difference-of-squares [=>]44.7
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\frac{c \cdot b - a}{\color{blue}{\left(c \cdot b + a\right) \cdot \left(c \cdot b - a\right)}}}\right)
\]
*-commutative [=>]44.7
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\frac{c \cdot b - a}{\left(\color{blue}{b \cdot c} + a\right) \cdot \left(c \cdot b - a\right)}}\right)
\]
fma-udef [<=]44.7
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\frac{c \cdot b - a}{\color{blue}{\mathsf{fma}\left(b, c, a\right)} \cdot \left(c \cdot b - a\right)}}\right)
\]
associate-/r* [=>]4.6
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\color{blue}{\frac{\frac{c \cdot b - a}{\mathsf{fma}\left(b, c, a\right)}}{c \cdot b - a}}}\right)
\]
fma-udef [=>]4.6
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\frac{\frac{c \cdot b - a}{\color{blue}{b \cdot c + a}}}{c \cdot b - a}}\right)
\]
*-commutative [<=]4.6
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\frac{\frac{c \cdot b - a}{\color{blue}{c \cdot b} + a}}{c \cdot b - a}}\right)
\]
fma-def [=>]4.6
\[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\frac{\frac{c \cdot b - a}{\color{blue}{\mathsf{fma}\left(c, b, a\right)}}}{c \cdot b - a}}\right)
\]
if -5.0000000000000002e160 < (*.f64 (+.f64 a (*.f64 b c)) c) < 5e302
Initial program 0.4
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\]
if 5e302 < (*.f64 (+.f64 a (*.f64 b c)) c)
Initial program 61.3
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\]
Taylor expanded in a around 0 42.4
\[\leadsto 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \color{blue}{{c}^{2} \cdot \left(i \cdot b\right)}\right)
\]
Simplified21.1
\[\leadsto 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \color{blue}{c \cdot \left(c \cdot \left(i \cdot b\right)\right)}\right)
\]
Proof
[Start]42.4
\[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - {c}^{2} \cdot \left(i \cdot b\right)\right)
\]
unpow2 [=>]42.4
\[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \color{blue}{\left(c \cdot c\right)} \cdot \left(i \cdot b\right)\right)
\]
associate-*l* [=>]21.1
\[ 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \color{blue}{c \cdot \left(c \cdot \left(i \cdot b\right)\right)}\right)
\]
Recombined 3 regimes into one program.
Final simplification1.9
\[\leadsto \begin{array}{l}
\mathbf{if}\;c \cdot \left(a + b \cdot c\right) \leq -5 \cdot 10^{+160}:\\
\;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \frac{c \cdot i}{\frac{\frac{b \cdot c - a}{\mathsf{fma}\left(c, b, a\right)}}{b \cdot c - a}}\right)\\
\mathbf{elif}\;c \cdot \left(a + b \cdot c\right) \leq 5 \cdot 10^{+302}:\\
\;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - \left(c \cdot \left(a + b \cdot c\right)\right) \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\end{array}
\]
Alternatives
Alternative 1
Error
2.2
Cost
2248
\[\begin{array}{l}
t_1 := z \cdot t + x \cdot y\\
t_2 := a + b \cdot c\\
t_3 := c \cdot t_2\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;2 \cdot \left(z \cdot t - c \cdot \left(i \cdot t_2\right)\right)\\
\mathbf{elif}\;t_3 \leq 5 \cdot 10^{+302}:\\
\;\;\;\;2 \cdot \left(t_1 - t_3 \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\end{array}
\]
Alternative 2
Error
1.9
Cost
2248
\[\begin{array}{l}
t_1 := z \cdot t + x \cdot y\\
t_2 := a + b \cdot c\\
t_3 := c \cdot t_2\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;2 \cdot \left(t_1 - \left(c \cdot i\right) \cdot t_2\right)\\
\mathbf{elif}\;t_3 \leq 5 \cdot 10^{+302}:\\
\;\;\;\;2 \cdot \left(t_1 - t_3 \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\end{array}
\]
Alternative 3
Error
22.9
Cost
1760
\[\begin{array}{l}
t_1 := 2 \cdot \left(z \cdot t + x \cdot y\right)\\
\mathbf{if}\;z \leq -1.35 \cdot 10^{+69}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -4.3 \cdot 10^{+36}:\\
\;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\\
\mathbf{elif}\;z \leq -1 \cdot 10^{-19}:\\
\;\;\;\;2 \cdot \left(z \cdot t - a \cdot \left(c \cdot i\right)\right)\\
\mathbf{elif}\;z \leq -9 \cdot 10^{-39}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -3.8 \cdot 10^{-58}:\\
\;\;\;\;\left(a + b \cdot c\right) \cdot \left(\left(c \cdot i\right) \cdot -2\right)\\
\mathbf{elif}\;z \leq -1.45 \cdot 10^{-185}:\\
\;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(a \cdot i\right)\right)\\
\mathbf{elif}\;z \leq -5.5 \cdot 10^{-198}:\\
\;\;\;\;2 \cdot \left(z \cdot t - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\mathbf{elif}\;z \leq 3 \cdot 10^{-216}:\\
\;\;\;\;2 \cdot \left(x \cdot y - i \cdot \left(a \cdot c\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
Alternative 4
Error
8.8
Cost
1616
\[\begin{array}{l}
t_1 := c \cdot \left(i \cdot \left(a + b \cdot c\right)\right)\\
t_2 := z \cdot t + x \cdot y\\
\mathbf{if}\;c \leq -6 \cdot 10^{-8}:\\
\;\;\;\;2 \cdot \left(z \cdot t - t_1\right)\\
\mathbf{elif}\;c \leq 1.12 \cdot 10^{-61}:\\
\;\;\;\;2 \cdot \left(t_2 - i \cdot \left(a \cdot c\right)\right)\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{+29}:\\
\;\;\;\;2 \cdot \left(t_2 - i \cdot \left(c \cdot \left(b \cdot c\right)\right)\right)\\
\mathbf{elif}\;c \leq 10^{+50}:\\
\;\;\;\;2 \cdot \left(x \cdot y - t_1\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t_2 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\end{array}
\]
herbie shell --seed 2023016
(FPCore (x y z t a b c i)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, A"
:precision binary64
:herbie-target
(* 2.0 (- (+ (* x y) (* z t)) (* (+ a (* b c)) (* c i))))
(* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))