Average Error: 6.3 → 3.6
Time: 22.2s
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 := c \cdot \left(i \cdot \mathsf{fma}\left(c, b, a\right)\right)\\ t_2 := c \cdot \left(a + b \cdot c\right)\\ \mathbf{if}\;t_2 \leq -2.430660637364443 \cdot 10^{+139}:\\ \;\;\;\;2 \cdot \left(\mathsf{fma}\left(t, z, y \cdot x\right) - t_1\right)\\ \mathbf{elif}\;t_2 \leq 9.080212204033886 \cdot 10^{+246}:\\ \;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, t \cdot z\right) - i \cdot \left(c \cdot \mathsf{fma}\left(b, c, a\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(y \cdot x - t_1\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 := c \cdot \left(i \cdot \mathsf{fma}\left(c, b, a\right)\right)\\
t_2 := c \cdot \left(a + b \cdot c\right)\\
\mathbf{if}\;t_2 \leq -2.430660637364443 \cdot 10^{+139}:\\
\;\;\;\;2 \cdot \left(\mathsf{fma}\left(t, z, y \cdot x\right) - t_1\right)\\

\mathbf{elif}\;t_2 \leq 9.080212204033886 \cdot 10^{+246}:\\
\;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, t \cdot z\right) - i \cdot \left(c \cdot \mathsf{fma}\left(b, c, a\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(y \cdot x - t_1\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 (* c (* i (fma c b a)))) (t_2 (* c (+ a (* b c)))))
   (if (<= t_2 -2.430660637364443e+139)
     (* 2.0 (- (fma t z (* y x)) t_1))
     (if (<= t_2 9.080212204033886e+246)
       (* 2.0 (- (fma x y (* t z)) (* i (* c (fma b c a)))))
       (* 2.0 (- (* y x) t_1))))))
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 = c * (i * fma(c, b, a));
	double t_2 = c * (a + (b * c));
	double tmp;
	if (t_2 <= -2.430660637364443e+139) {
		tmp = 2.0 * (fma(t, z, (y * x)) - t_1);
	} else if (t_2 <= 9.080212204033886e+246) {
		tmp = 2.0 * (fma(x, y, (t * z)) - (i * (c * fma(b, c, a))));
	} else {
		tmp = 2.0 * ((y * x) - t_1);
	}
	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.3
Target3.8
Herbie3.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 (*.f64 (+.f64 a (*.f64 b c)) c) < -2.43066063736444301e139

    1. Initial program 12.2

      \[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. Simplified12.0

      \[\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 x around 0 20.4

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

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

    if -2.43066063736444301e139 < (*.f64 (+.f64 a (*.f64 b c)) c) < 9.0802122040338862e246

    1. Initial program 1.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) \]
    2. Simplified1.1

      \[\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)} \]

    if 9.0802122040338862e246 < (*.f64 (+.f64 a (*.f64 b c)) c)

    1. Initial program 14.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. Simplified14.7

      \[\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 z around 0 22.2

      \[\leadsto 2 \cdot \color{blue}{\left(y \cdot x - \left({c}^{2} \cdot \left(i \cdot b\right) + c \cdot \left(i \cdot a\right)\right)\right)} \]
    4. Simplified8.4

      \[\leadsto 2 \cdot \color{blue}{\left(y \cdot x - c \cdot \left(i \cdot \mathsf{fma}\left(c, b, a\right)\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification3.6

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

Reproduce

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