Average Error: 3.7 → 1.3
Time: 9.2s
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}\;y \cdot 9 \le -8.63828739859890366 \cdot 10^{64} \lor \neg \left(y \cdot 9 \le 4.26640526336584695 \cdot 10^{171}\right):\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(9 \cdot \left(z \cdot y\right)\right) \cdot t\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}\;y \cdot 9 \le -8.63828739859890366 \cdot 10^{64} \lor \neg \left(y \cdot 9 \le 4.26640526336584695 \cdot 10^{171}\right):\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(t \cdot z\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r796419 = x;
        double r796420 = 2.0;
        double r796421 = r796419 * r796420;
        double r796422 = y;
        double r796423 = 9.0;
        double r796424 = r796422 * r796423;
        double r796425 = z;
        double r796426 = r796424 * r796425;
        double r796427 = t;
        double r796428 = r796426 * r796427;
        double r796429 = r796421 - r796428;
        double r796430 = a;
        double r796431 = 27.0;
        double r796432 = r796430 * r796431;
        double r796433 = b;
        double r796434 = r796432 * r796433;
        double r796435 = r796429 + r796434;
        return r796435;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r796436 = y;
        double r796437 = 9.0;
        double r796438 = r796436 * r796437;
        double r796439 = -8.638287398598904e+64;
        bool r796440 = r796438 <= r796439;
        double r796441 = 4.266405263365847e+171;
        bool r796442 = r796438 <= r796441;
        double r796443 = !r796442;
        bool r796444 = r796440 || r796443;
        double r796445 = a;
        double r796446 = 27.0;
        double r796447 = r796445 * r796446;
        double r796448 = b;
        double r796449 = x;
        double r796450 = 2.0;
        double r796451 = r796449 * r796450;
        double r796452 = t;
        double r796453 = z;
        double r796454 = r796452 * r796453;
        double r796455 = r796438 * r796454;
        double r796456 = r796451 - r796455;
        double r796457 = fma(r796447, r796448, r796456);
        double r796458 = r796453 * r796436;
        double r796459 = r796437 * r796458;
        double r796460 = r796459 * r796452;
        double r796461 = r796451 - r796460;
        double r796462 = fma(r796447, r796448, r796461);
        double r796463 = r796444 ? r796457 : r796462;
        return r796463;
}

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
Herbie1.3
\[\begin{array}{l} \mathbf{if}\;y \lt 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 2 regimes
  2. if (* y 9.0) < -8.638287398598904e+64 or 4.266405263365847e+171 < (* y 9.0)

    1. Initial program 10.7

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

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

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

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

    if -8.638287398598904e+64 < (* y 9.0) < 4.266405263365847e+171

    1. Initial program 1.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.4

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

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot \color{blue}{{z}^{1}}\right) \cdot t\right)\]
    5. Applied pow11.4

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

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(\left(\color{blue}{{y}^{1}} \cdot {9}^{1}\right) \cdot {z}^{1}\right) \cdot t\right)\]
    7. Applied pow-prod-down1.4

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(\color{blue}{{\left(y \cdot 9\right)}^{1}} \cdot {z}^{1}\right) \cdot t\right)\]
    8. Applied pow-prod-down1.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot 9 \le -8.63828739859890366 \cdot 10^{64} \lor \neg \left(y \cdot 9 \le 4.26640526336584695 \cdot 10^{171}\right):\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(9 \cdot \left(z \cdot y\right)\right) \cdot t\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 +o rules:numerics
(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) (* (* (* y 9) z) t)) (* a (* 27 b))) (+ (- (* x 2) (* 9 (* y (* t z)))) (* (* a 27) b)))

  (+ (- (* x 2) (* (* (* y 9) z) t)) (* (* a 27) b)))