Average Error: 3.7 → 1.3
Time: 11.1s
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(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, \mathsf{fma}\left(2, x, -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\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}\;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(z \cdot t\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r705388 = x;
        double r705389 = 2.0;
        double r705390 = r705388 * r705389;
        double r705391 = y;
        double r705392 = 9.0;
        double r705393 = r705391 * r705392;
        double r705394 = z;
        double r705395 = r705393 * r705394;
        double r705396 = t;
        double r705397 = r705395 * r705396;
        double r705398 = r705390 - r705397;
        double r705399 = a;
        double r705400 = 27.0;
        double r705401 = r705399 * r705400;
        double r705402 = b;
        double r705403 = r705401 * r705402;
        double r705404 = r705398 + r705403;
        return r705404;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r705405 = y;
        double r705406 = 9.0;
        double r705407 = r705405 * r705406;
        double r705408 = -8.638287398598904e+64;
        bool r705409 = r705407 <= r705408;
        double r705410 = 4.266405263365847e+171;
        bool r705411 = r705407 <= r705410;
        double r705412 = !r705411;
        bool r705413 = r705409 || r705412;
        double r705414 = a;
        double r705415 = 27.0;
        double r705416 = r705414 * r705415;
        double r705417 = b;
        double r705418 = x;
        double r705419 = 2.0;
        double r705420 = r705418 * r705419;
        double r705421 = z;
        double r705422 = t;
        double r705423 = r705421 * r705422;
        double r705424 = r705407 * r705423;
        double r705425 = r705420 - r705424;
        double r705426 = fma(r705416, r705417, r705425);
        double r705427 = r705421 * r705405;
        double r705428 = r705422 * r705427;
        double r705429 = r705406 * r705428;
        double r705430 = -r705429;
        double r705431 = fma(r705419, r705418, r705430);
        double r705432 = fma(r705416, r705417, r705431);
        double r705433 = r705413 ? r705426 : r705432;
        return r705433;
}

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)\]

    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)\]
    10. Taylor expanded around inf 1.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)}\]
    11. Simplified1.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(a \cdot 27, b, \mathsf{fma}\left(2, x, -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\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(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, \mathsf{fma}\left(2, x, -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\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)))