Average Error: 6.6 → 1.1
Time: 14.6s
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(c, b, a\right)\\ t_2 := \left(c \cdot \left(a + b \cdot c\right)\right) \cdot i\\ t_3 := \mathsf{fma}\left(x, y, z \cdot t\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(c \cdot i, t_1, t_3\right)\\ \mathbf{elif}\;t_2 \leq 5.885984071619432 \cdot 10^{+301}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(i, c \cdot t_1, t_3\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(t_3 - c \cdot \left(c \cdot \left(b \cdot i\right) + a \cdot i\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(c, b, a\right)\\
t_2 := \left(c \cdot \left(a + b \cdot c\right)\right) \cdot i\\
t_3 := \mathsf{fma}\left(x, y, z \cdot t\right)\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(c \cdot i, t_1, t_3\right)\\

\mathbf{elif}\;t_2 \leq 5.885984071619432 \cdot 10^{+301}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(i, c \cdot t_1, t_3\right)\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t_3 - c \cdot \left(c \cdot \left(b \cdot i\right) + a \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 (- (fma c b a)))
        (t_2 (* (* c (+ a (* b c))) i))
        (t_3 (fma x y (* z t))))
   (if (<= t_2 (- INFINITY))
     (* 2.0 (fma (* c i) t_1 t_3))
     (if (<= t_2 5.885984071619432e+301)
       (* 2.0 (fma i (* c t_1) t_3))
       (* 2.0 (- t_3 (* c (+ (* c (* b i)) (* a 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));
}
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
	double t_1 = -fma(c, b, a);
	double t_2 = (c * (a + (b * c))) * i;
	double t_3 = fma(x, y, (z * t));
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = 2.0 * fma((c * i), t_1, t_3);
	} else if (t_2 <= 5.885984071619432e+301) {
		tmp = 2.0 * fma(i, (c * t_1), t_3);
	} else {
		tmp = 2.0 * (t_3 - (c * ((c * (b * i)) + (a * i))));
	}
	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.6
Target1.9
Herbie1.1
\[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 (+.f64 a (*.f64 b c)) c) i) < -inf.0

    1. 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) \]
    2. Simplified64.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 c around 0 34.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 egg-rr10.0

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

    if -inf.0 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 5.8859840716194319e301

    1. Initial program 0.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. Simplified0.3

      \[\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. Applied egg-rr0.3

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

    if 5.8859840716194319e301 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)

    1. Initial program 60.1

      \[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. Simplified60.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)} \]
    3. Taylor expanded in c around 0 35.5

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

      \[\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 6.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) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.1

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

Reproduce

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