\[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 := a + b \cdot c\\
t_3 := \left(c \cdot t_2\right) \cdot i\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\mathbf{elif}\;t_3 \leq 2 \cdot 10^{-80}:\\
\;\;\;\;2 \cdot \left(t_1 - t_3\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t_1 - t_2 \cdot \left(c \cdot i\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 (+ a (* b c))) (t_3 (* (* c t_2) i)))
(if (<= t_3 (- INFINITY))
(* 2.0 (- t_1 (* c (* c (* b i)))))
(if (<= t_3 2e-80) (* 2.0 (- t_1 t_3)) (* 2.0 (- t_1 (* t_2 (* c 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 := a + b \cdot c\\
t_3 := \left(c \cdot t_2\right) \cdot i\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\mathbf{elif}\;t_3 \leq 2 \cdot 10^{-80}:\\
\;\;\;\;2 \cdot \left(t_1 - t_3\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t_1 - t_2 \cdot \left(c \cdot i\right)\right)\\
\end{array}
Error
Try it out
Results
Enter valid numbers for all inputs
Target
Original
6.1
Target
1.8
Herbie
2.0
\[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 (+.f64 a (*.f64 b c)) c) i) < -inf.0
Initial program 64.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)
\]
Taylor expanded in a around 0 43.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.7
\[\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
(*.f64 c (*.f64 c (*.f64 i b))): 0 points increase in error, 0 points decrease in error
(Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 c c) (*.f64 i b))): 48 points increase in error, 37 points decrease in error
(*.f64 (Rewrite<= unpow2_binary64 (pow.f64 c 2)) (*.f64 i b)): 0 points increase in error, 0 points decrease in error
if -inf.0 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 1.99999999999999992e-80
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 1.99999999999999992e-80 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)
Initial program 10.5
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\]
Simplified2.9
\[\leadsto \color{blue}{2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right)}
\]
Proof
(*.f64 2 (-.f64 (fma.f64 x y (*.f64 z t)) (*.f64 (+.f64 a (*.f64 b c)) (*.f64 c i)))): 0 points increase in error, 0 points decrease in error
(*.f64 2 (-.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x y) (*.f64 z t))) (*.f64 (+.f64 a (*.f64 b c)) (*.f64 c i)))): 2 points increase in error, 0 points decrease in error
(*.f64 2 (-.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)))): 34 points increase in error, 6 points decrease in error
Applied egg-rr2.9
\[\leadsto 2 \cdot \left(\color{blue}{\left(z \cdot t + x \cdot y\right)} - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right)
\]
Recombined 3 regimes into one program.
Final simplification2.0
\[\leadsto \begin{array}{l}
\mathbf{if}\;\left(c \cdot \left(a + b \cdot c\right)\right) \cdot i \leq -\infty:\\
\;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\
\mathbf{elif}\;\left(c \cdot \left(a + b \cdot c\right)\right) \cdot i \leq 2 \cdot 10^{-80}:\\
\;\;\;\;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) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right)\\
\end{array}
\]
herbie shell --seed 2022325
(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))))