Average Error: 3.6 → 1.0
Time: 47.3s
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}\;\left(y \cdot 9\right) \cdot z \le -7.977144230546346826794071907718023773623 \cdot 10^{58}:\\ \;\;\;\;\mathsf{fma}\left(a, b \cdot 27, 2 \cdot x - y \cdot \left(\left(9 \cdot t\right) \cdot z\right)\right)\\ \mathbf{elif}\;\left(y \cdot 9\right) \cdot z \le 2.204127758260046842526454587643861854256 \cdot 10^{126}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \left(b \cdot 27\right) \cdot a - t \cdot \left(9 \cdot \left(z \cdot y\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, 2 \cdot x\right) - z \cdot \left(9 \cdot \left(y \cdot t\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}\;\left(y \cdot 9\right) \cdot z \le -7.977144230546346826794071907718023773623 \cdot 10^{58}:\\
\;\;\;\;\mathsf{fma}\left(a, b \cdot 27, 2 \cdot x - y \cdot \left(\left(9 \cdot t\right) \cdot z\right)\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r37178436 = x;
        double r37178437 = 2.0;
        double r37178438 = r37178436 * r37178437;
        double r37178439 = y;
        double r37178440 = 9.0;
        double r37178441 = r37178439 * r37178440;
        double r37178442 = z;
        double r37178443 = r37178441 * r37178442;
        double r37178444 = t;
        double r37178445 = r37178443 * r37178444;
        double r37178446 = r37178438 - r37178445;
        double r37178447 = a;
        double r37178448 = 27.0;
        double r37178449 = r37178447 * r37178448;
        double r37178450 = b;
        double r37178451 = r37178449 * r37178450;
        double r37178452 = r37178446 + r37178451;
        return r37178452;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r37178453 = y;
        double r37178454 = 9.0;
        double r37178455 = r37178453 * r37178454;
        double r37178456 = z;
        double r37178457 = r37178455 * r37178456;
        double r37178458 = -7.977144230546347e+58;
        bool r37178459 = r37178457 <= r37178458;
        double r37178460 = a;
        double r37178461 = b;
        double r37178462 = 27.0;
        double r37178463 = r37178461 * r37178462;
        double r37178464 = 2.0;
        double r37178465 = x;
        double r37178466 = r37178464 * r37178465;
        double r37178467 = t;
        double r37178468 = r37178454 * r37178467;
        double r37178469 = r37178468 * r37178456;
        double r37178470 = r37178453 * r37178469;
        double r37178471 = r37178466 - r37178470;
        double r37178472 = fma(r37178460, r37178463, r37178471);
        double r37178473 = 2.2041277582600468e+126;
        bool r37178474 = r37178457 <= r37178473;
        double r37178475 = r37178463 * r37178460;
        double r37178476 = r37178456 * r37178453;
        double r37178477 = r37178454 * r37178476;
        double r37178478 = r37178467 * r37178477;
        double r37178479 = r37178475 - r37178478;
        double r37178480 = fma(r37178465, r37178464, r37178479);
        double r37178481 = r37178460 * r37178462;
        double r37178482 = fma(r37178481, r37178461, r37178466);
        double r37178483 = r37178453 * r37178467;
        double r37178484 = r37178454 * r37178483;
        double r37178485 = r37178456 * r37178484;
        double r37178486 = r37178482 - r37178485;
        double r37178487 = r37178474 ? r37178480 : r37178486;
        double r37178488 = r37178459 ? r37178472 : r37178487;
        return r37178488;
}

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.6
Target2.6
Herbie1.0
\[\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) z) < -7.977144230546347e+58

    1. Initial program 11.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. Taylor expanded around inf 11.0

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

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

    if -7.977144230546347e+58 < (* (* y 9.0) z) < 2.2041277582600468e+126

    1. Initial program 0.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. Taylor expanded around inf 0.4

      \[\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)}\]
    3. Simplified4.0

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

      \[\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)}\]
    5. Simplified0.4

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

    if 2.2041277582600468e+126 < (* (* y 9.0) z)

    1. Initial program 15.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. Simplified2.9

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

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

Reproduce

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