Average Error: 3.1 → 2.2
Time: 6.3s
Precision: binary64
\[[y, z, t] = \mathsf{sort}([y, z, t]) \\]
\[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
\[\begin{array}{l} t_1 := \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ t_2 := \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\\ \mathbf{if}\;t_2 \leq 1.3987757777963822 \cdot 10^{-156}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, \mathsf{fma}\left(2, x, t_1\right)\right)\\ \mathbf{elif}\;t_2 \leq 6.566185616261638 \cdot 10^{+218}:\\ \;\;\;\;\left(2 \cdot x - t_2\right) + b \cdot \left(27 \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(2 \cdot x + 27 \cdot \left(a \cdot b\right)\right)\\ \end{array} \]
\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\begin{array}{l}
t_1 := \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\
t_2 := \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\\
\mathbf{if}\;t_2 \leq 1.3987757777963822 \cdot 10^{-156}:\\
\;\;\;\;\mathsf{fma}\left(27, a \cdot b, \mathsf{fma}\left(2, x, t_1\right)\right)\\

\mathbf{elif}\;t_2 \leq 6.566185616261638 \cdot 10^{+218}:\\
\;\;\;\;\left(2 \cdot x - t_2\right) + b \cdot \left(27 \cdot a\right)\\

\mathbf{else}:\\
\;\;\;\;t_1 + \left(2 \cdot x + 27 \cdot \left(a \cdot b\right)\right)\\


\end{array}
(FPCore (x y z t a b)
 :precision binary64
 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* (* y (* z t)) -9.0)) (t_2 (* (* (* y 9.0) z) t)))
   (if (<= t_2 1.3987757777963822e-156)
     (fma 27.0 (* a b) (fma 2.0 x t_1))
     (if (<= t_2 6.566185616261638e+218)
       (+ (- (* 2.0 x) t_2) (* b (* 27.0 a)))
       (+ t_1 (+ (* 2.0 x) (* 27.0 (* a b))))))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (y * (z * t)) * -9.0;
	double t_2 = ((y * 9.0) * z) * t;
	double tmp;
	if (t_2 <= 1.3987757777963822e-156) {
		tmp = fma(27.0, (a * b), fma(2.0, x, t_1));
	} else if (t_2 <= 6.566185616261638e+218) {
		tmp = ((2.0 * x) - t_2) + (b * (27.0 * a));
	} else {
		tmp = t_1 + ((2.0 * x) + (27.0 * (a * 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

Target

Original3.1
Target3.5
Herbie2.2
\[\begin{array}{l} \mathbf{if}\;y < 7.590524218811189 \cdot 10^{-161}:\\ \;\;\;\;\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 (*.f64 y 9) z) t) < 1.3987757777963822e-156

    1. Initial program 2.5

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Simplified2.3

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

      \[\leadsto \color{blue}{\left(27 \cdot \left(a \cdot b\right) + 2 \cdot x\right) - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)} \]
    4. Simplified2.1

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

    if 1.3987757777963822e-156 < (*.f64 (*.f64 (*.f64 y 9) z) t) < 6.566185616261638e218

    1. Initial program 0.6

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]

    if 6.566185616261638e218 < (*.f64 (*.f64 (*.f64 y 9) z) t)

    1. Initial program 19.9

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Simplified9.2

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

      \[\leadsto \color{blue}{\left(27 \cdot \left(a \cdot b\right) + 2 \cdot x\right) - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(y \cdot 9\right) \cdot z\right) \cdot t \leq 1.3987757777963822 \cdot 10^{-156}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, \mathsf{fma}\left(2, x, \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\right)\right)\\ \mathbf{elif}\;\left(\left(y \cdot 9\right) \cdot z\right) \cdot t \leq 6.566185616261638 \cdot 10^{+218}:\\ \;\;\;\;\left(2 \cdot x - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + b \cdot \left(27 \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot \left(z \cdot t\right)\right) \cdot -9 + \left(2 \cdot x + 27 \cdot \left(a \cdot b\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022067 
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, A"
  :precision binary64

  :herbie-target
  (if (< y 7.590524218811189e-161) (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* a (* 27.0 b))) (+ (- (* x 2.0) (* 9.0 (* y (* t z)))) (* (* a 27.0) b)))

  (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))