Average Error: 6.5 → 1.6
Time: 9.4s
Precision: binary64
\[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 := \mathsf{fma}\left(x, y, z \cdot t\right)\\ \mathbf{if}\;i \leq -2.0943062549980613 \cdot 10^{-40}:\\ \;\;\;\;2 \cdot \left(t_1 - \left(i \cdot c\right) \cdot \mathsf{fma}\left(c, b, a\right)\right)\\ \mathbf{elif}\;i \leq 5.5784381509619995 \cdot 10^{-98}:\\ \;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(i \cdot b\right) + i \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - i \cdot \left(c \cdot \left(a + c \cdot b\right)\right)\right)\\ \end{array} \]
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 := \mathsf{fma}\left(x, y, z \cdot t\right)\\
\mathbf{if}\;i \leq -2.0943062549980613 \cdot 10^{-40}:\\
\;\;\;\;2 \cdot \left(t_1 - \left(i \cdot c\right) \cdot \mathsf{fma}\left(c, b, a\right)\right)\\

\mathbf{elif}\;i \leq 5.5784381509619995 \cdot 10^{-98}:\\
\;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(i \cdot b\right) + i \cdot a\right)\right)\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - i \cdot \left(c \cdot \left(a + c \cdot b\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 (fma x y (* z t))))
   (if (<= i -2.0943062549980613e-40)
     (* 2.0 (- t_1 (* (* i c) (fma c b a))))
     (if (<= i 5.5784381509619995e-98)
       (* 2.0 (- t_1 (* c (+ (* c (* i b)) (* i a)))))
       (* 2.0 (- (+ (* z t) (* x y)) (* i (* c (+ a (* c b))))))))))
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));
}
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
	double t_1 = fma(x, y, (z * t));
	double tmp;
	if (i <= -2.0943062549980613e-40) {
		tmp = 2.0 * (t_1 - ((i * c) * fma(c, b, a)));
	} else if (i <= 5.5784381509619995e-98) {
		tmp = 2.0 * (t_1 - (c * ((c * (i * b)) + (i * a))));
	} else {
		tmp = 2.0 * (((z * t) + (x * y)) - (i * (c * (a + (c * b)))));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus i

Target

Original6.5
Target1.9
Herbie1.6
\[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

  1. Split input into 3 regimes
  2. if i < -2.09430625499806131e-40

    1. Initial program 0.8

      \[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
    2. Simplified0.8

      \[\leadsto \color{blue}{2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \left(c \cdot \mathsf{fma}\left(b, c, a\right)\right) \cdot i\right)} \]
    3. Taylor expanded in c around 0 17.1

      \[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{\left({c}^{2} \cdot \left(i \cdot b\right) + c \cdot \left(i \cdot a\right)\right)}\right) \]
    4. Simplified10.0

      \[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{c \cdot \left(i \cdot \mathsf{fma}\left(c, b, a\right)\right)}\right) \]
    5. Applied associate-*r*_binary641.2

      \[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{\left(c \cdot i\right) \cdot \mathsf{fma}\left(c, b, a\right)}\right) \]

    if -2.09430625499806131e-40 < i < 5.57843815096199946e-98

    1. Initial program 11.9

      \[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
    2. Simplified11.9

      \[\leadsto \color{blue}{2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \left(c \cdot \mathsf{fma}\left(b, c, a\right)\right) \cdot i\right)} \]
    3. Taylor expanded in c around 0 9.9

      \[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{\left({c}^{2} \cdot \left(i \cdot b\right) + c \cdot \left(i \cdot a\right)\right)}\right) \]
    4. Simplified2.0

      \[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{c \cdot \left(i \cdot \mathsf{fma}\left(c, b, a\right)\right)}\right) \]
    5. Taylor expanded in c around 0 1.7

      \[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \color{blue}{\left(c \cdot \left(i \cdot b\right) + a \cdot i\right)}\right) \]

    if 5.57843815096199946e-98 < i

    1. Initial program 1.9

      \[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \leq -2.0943062549980613 \cdot 10^{-40}:\\ \;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \left(i \cdot c\right) \cdot \mathsf{fma}\left(c, b, a\right)\right)\\ \mathbf{elif}\;i \leq 5.5784381509619995 \cdot 10^{-98}:\\ \;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(c \cdot \left(i \cdot b\right) + i \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - i \cdot \left(c \cdot \left(a + c \cdot b\right)\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022104 
(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))))