Average Error: 3.8 → 0.8
Time: 48.4s
Precision: 64
\[\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} \mathbf{if}\;9 \cdot y \le -2.026318969375462312008028647671240762128 \cdot 10^{-68}:\\ \;\;\;\;\mathsf{fma}\left(27, b \cdot a, x \cdot 2\right) - \left(y \cdot \left(t \cdot z\right)\right) \cdot 9\\ \mathbf{elif}\;9 \cdot y \le 5.381180766422347911412809455891368245888 \cdot 10^{-74}:\\ \;\;\;\;\mathsf{fma}\left(27, b \cdot a, x \cdot 2\right) - 9 \cdot \left(\left(z \cdot y\right) \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, \left(b \cdot 27\right) \cdot a - \left(t \cdot z\right) \cdot \left(9 \cdot y\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}
\mathbf{if}\;9 \cdot y \le -2.026318969375462312008028647671240762128 \cdot 10^{-68}:\\
\;\;\;\;\mathsf{fma}\left(27, b \cdot a, x \cdot 2\right) - \left(y \cdot \left(t \cdot z\right)\right) \cdot 9\\

\mathbf{elif}\;9 \cdot y \le 5.381180766422347911412809455891368245888 \cdot 10^{-74}:\\
\;\;\;\;\mathsf{fma}\left(27, b \cdot a, x \cdot 2\right) - 9 \cdot \left(\left(z \cdot y\right) \cdot t\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, x, \left(b \cdot 27\right) \cdot a - \left(t \cdot z\right) \cdot \left(9 \cdot y\right)\right)\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r35585358 = x;
        double r35585359 = 2.0;
        double r35585360 = r35585358 * r35585359;
        double r35585361 = y;
        double r35585362 = 9.0;
        double r35585363 = r35585361 * r35585362;
        double r35585364 = z;
        double r35585365 = r35585363 * r35585364;
        double r35585366 = t;
        double r35585367 = r35585365 * r35585366;
        double r35585368 = r35585360 - r35585367;
        double r35585369 = a;
        double r35585370 = 27.0;
        double r35585371 = r35585369 * r35585370;
        double r35585372 = b;
        double r35585373 = r35585371 * r35585372;
        double r35585374 = r35585368 + r35585373;
        return r35585374;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r35585375 = 9.0;
        double r35585376 = y;
        double r35585377 = r35585375 * r35585376;
        double r35585378 = -2.0263189693754623e-68;
        bool r35585379 = r35585377 <= r35585378;
        double r35585380 = 27.0;
        double r35585381 = b;
        double r35585382 = a;
        double r35585383 = r35585381 * r35585382;
        double r35585384 = x;
        double r35585385 = 2.0;
        double r35585386 = r35585384 * r35585385;
        double r35585387 = fma(r35585380, r35585383, r35585386);
        double r35585388 = t;
        double r35585389 = z;
        double r35585390 = r35585388 * r35585389;
        double r35585391 = r35585376 * r35585390;
        double r35585392 = r35585391 * r35585375;
        double r35585393 = r35585387 - r35585392;
        double r35585394 = 5.381180766422348e-74;
        bool r35585395 = r35585377 <= r35585394;
        double r35585396 = r35585389 * r35585376;
        double r35585397 = r35585396 * r35585388;
        double r35585398 = r35585375 * r35585397;
        double r35585399 = r35585387 - r35585398;
        double r35585400 = r35585381 * r35585380;
        double r35585401 = r35585400 * r35585382;
        double r35585402 = r35585390 * r35585377;
        double r35585403 = r35585401 - r35585402;
        double r35585404 = fma(r35585385, r35585384, r35585403);
        double r35585405 = r35585395 ? r35585399 : r35585404;
        double r35585406 = r35585379 ? r35585393 : r35585405;
        return r35585406;
}

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.8
Target2.8
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;y \lt 7.590524218811188954625810696587370427881 \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 (* y 9.0) < -2.0263189693754623e-68

    1. Initial program 6.4

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(a \cdot 27, b, x \cdot 2\right) - \left(9 \cdot y\right) \cdot \left(t \cdot z\right)}\]
    3. Using strategy rm
    4. Applied associate-*r*7.4

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2\right) - \color{blue}{\left(\left(9 \cdot y\right) \cdot t\right) \cdot z}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity7.4

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2\right) - \left(\left(9 \cdot y\right) \cdot t\right) \cdot \color{blue}{\left(1 \cdot z\right)}\]
    7. Applied associate-*r*7.4

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

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

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

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

    if -2.0263189693754623e-68 < (* y 9.0) < 5.381180766422348e-74

    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\]
    2. Simplified6.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(a \cdot 27, b, x \cdot 2\right) - \left(9 \cdot y\right) \cdot \left(t \cdot z\right)}\]
    3. Using strategy rm
    4. Applied associate-*r*0.6

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2\right) - \color{blue}{\left(\left(9 \cdot y\right) \cdot t\right) \cdot z}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity0.6

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2\right) - \left(\left(9 \cdot y\right) \cdot t\right) \cdot \color{blue}{\left(1 \cdot z\right)}\]
    7. Applied associate-*r*0.6

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

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

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

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

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

    if 5.381180766422348e-74 < (* y 9.0)

    1. Initial program 6.4

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;9 \cdot y \le -2.026318969375462312008028647671240762128 \cdot 10^{-68}:\\ \;\;\;\;\mathsf{fma}\left(27, b \cdot a, x \cdot 2\right) - \left(y \cdot \left(t \cdot z\right)\right) \cdot 9\\ \mathbf{elif}\;9 \cdot y \le 5.381180766422347911412809455891368245888 \cdot 10^{-74}:\\ \;\;\;\;\mathsf{fma}\left(27, b \cdot a, x \cdot 2\right) - 9 \cdot \left(\left(z \cdot y\right) \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, \left(b \cdot 27\right) \cdot a - \left(t \cdot z\right) \cdot \left(9 \cdot y\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019200 +o rules:numerics
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, A"

  :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)))