Average Error: 3.7 → 0.6
Time: 23.8s
Precision: 64
\[\left(x \cdot 2.0 - \left(\left(y \cdot 9.0\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27.0\right) \cdot b\]
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 9.0\right) \cdot z \le -1.6668062140809887 \cdot 10^{+104}:\\ \;\;\;\;\mathsf{fma}\left(b \cdot 27.0, a, x \cdot 2.0 - \left(z \cdot 9.0\right) \cdot \left(t \cdot y\right)\right)\\ \mathbf{elif}\;\left(y \cdot 9.0\right) \cdot z \le 5.320800982640892 \cdot 10^{+259}:\\ \;\;\;\;\left(x \cdot 2.0 - \left(\left(y \cdot 9.0\right) \cdot z\right) \cdot t\right) + \left(27.0 \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b \cdot 27.0, a, x \cdot 2.0 - \left(t \cdot \left(z \cdot 9.0\right)\right) \cdot y\right)\\ \end{array}\]
\left(x \cdot 2.0 - \left(\left(y \cdot 9.0\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27.0\right) \cdot b
\begin{array}{l}
\mathbf{if}\;\left(y \cdot 9.0\right) \cdot z \le -1.6668062140809887 \cdot 10^{+104}:\\
\;\;\;\;\mathsf{fma}\left(b \cdot 27.0, a, x \cdot 2.0 - \left(z \cdot 9.0\right) \cdot \left(t \cdot y\right)\right)\\

\mathbf{elif}\;\left(y \cdot 9.0\right) \cdot z \le 5.320800982640892 \cdot 10^{+259}:\\
\;\;\;\;\left(x \cdot 2.0 - \left(\left(y \cdot 9.0\right) \cdot z\right) \cdot t\right) + \left(27.0 \cdot a\right) \cdot b\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b \cdot 27.0, a, x \cdot 2.0 - \left(t \cdot \left(z \cdot 9.0\right)\right) \cdot y\right)\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r32832482 = x;
        double r32832483 = 2.0;
        double r32832484 = r32832482 * r32832483;
        double r32832485 = y;
        double r32832486 = 9.0;
        double r32832487 = r32832485 * r32832486;
        double r32832488 = z;
        double r32832489 = r32832487 * r32832488;
        double r32832490 = t;
        double r32832491 = r32832489 * r32832490;
        double r32832492 = r32832484 - r32832491;
        double r32832493 = a;
        double r32832494 = 27.0;
        double r32832495 = r32832493 * r32832494;
        double r32832496 = b;
        double r32832497 = r32832495 * r32832496;
        double r32832498 = r32832492 + r32832497;
        return r32832498;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r32832499 = y;
        double r32832500 = 9.0;
        double r32832501 = r32832499 * r32832500;
        double r32832502 = z;
        double r32832503 = r32832501 * r32832502;
        double r32832504 = -1.6668062140809887e+104;
        bool r32832505 = r32832503 <= r32832504;
        double r32832506 = b;
        double r32832507 = 27.0;
        double r32832508 = r32832506 * r32832507;
        double r32832509 = a;
        double r32832510 = x;
        double r32832511 = 2.0;
        double r32832512 = r32832510 * r32832511;
        double r32832513 = r32832502 * r32832500;
        double r32832514 = t;
        double r32832515 = r32832514 * r32832499;
        double r32832516 = r32832513 * r32832515;
        double r32832517 = r32832512 - r32832516;
        double r32832518 = fma(r32832508, r32832509, r32832517);
        double r32832519 = 5.320800982640892e+259;
        bool r32832520 = r32832503 <= r32832519;
        double r32832521 = r32832503 * r32832514;
        double r32832522 = r32832512 - r32832521;
        double r32832523 = r32832507 * r32832509;
        double r32832524 = r32832523 * r32832506;
        double r32832525 = r32832522 + r32832524;
        double r32832526 = r32832514 * r32832513;
        double r32832527 = r32832526 * r32832499;
        double r32832528 = r32832512 - r32832527;
        double r32832529 = fma(r32832508, r32832509, r32832528);
        double r32832530 = r32832520 ? r32832525 : r32832529;
        double r32832531 = r32832505 ? r32832518 : r32832530;
        return r32832531;
}

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.7
Target2.6
Herbie0.6
\[\begin{array}{l} \mathbf{if}\;y \lt 7.590524218811189 \cdot 10^{-161}:\\ \;\;\;\;\left(x \cdot 2.0 - \left(\left(y \cdot 9.0\right) \cdot z\right) \cdot t\right) + a \cdot \left(27.0 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2.0 - 9.0 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right) + \left(a \cdot 27.0\right) \cdot b\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (* (* y 9.0) z) < -1.6668062140809887e+104

    1. Initial program 13.5

      \[\left(x \cdot 2.0 - \left(\left(y \cdot 9.0\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27.0\right) \cdot b\]
    2. Simplified2.4

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

      \[\leadsto \mathsf{fma}\left(b \cdot 27.0, a, x \cdot 2.0 - \color{blue}{\left(9.0 \cdot z\right) \cdot \left(t \cdot y\right)}\right)\]

    if -1.6668062140809887e+104 < (* (* y 9.0) z) < 5.320800982640892e+259

    1. Initial program 0.4

      \[\left(x \cdot 2.0 - \left(\left(y \cdot 9.0\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27.0\right) \cdot b\]

    if 5.320800982640892e+259 < (* (* y 9.0) z)

    1. Initial program 41.0

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

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

      \[\leadsto \mathsf{fma}\left(b \cdot 27.0, a, x \cdot 2.0 - \color{blue}{\left(9.0 \cdot z\right) \cdot \left(t \cdot y\right)}\right)\]
    5. Using strategy rm
    6. Applied associate-*r*0.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 9.0\right) \cdot z \le -1.6668062140809887 \cdot 10^{+104}:\\ \;\;\;\;\mathsf{fma}\left(b \cdot 27.0, a, x \cdot 2.0 - \left(z \cdot 9.0\right) \cdot \left(t \cdot y\right)\right)\\ \mathbf{elif}\;\left(y \cdot 9.0\right) \cdot z \le 5.320800982640892 \cdot 10^{+259}:\\ \;\;\;\;\left(x \cdot 2.0 - \left(\left(y \cdot 9.0\right) \cdot z\right) \cdot t\right) + \left(27.0 \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b \cdot 27.0, a, x \cdot 2.0 - \left(t \cdot \left(z \cdot 9.0\right)\right) \cdot y\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 +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)))