Average Error: 3.8 → 0.9
Time: 19.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 \le -2.096510172463769293334958117187919077634 \cdot 10^{-52}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, 2 \cdot x - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{elif}\;y \le 1.736087413763324001573940804782881383422 \cdot 10^{-76}:\\ \;\;\;\;2 \cdot x + \left(\left(\sqrt{27} \cdot \left(a \cdot b\right)\right) \cdot \sqrt{27} - \left(z \cdot y\right) \cdot \left(t \cdot 9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot x + \left(27 \cdot \left(a \cdot b\right) - \left(\left(t \cdot 9\right) \cdot z\right) \cdot y\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 \le -2.096510172463769293334958117187919077634 \cdot 10^{-52}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, b, 2 \cdot x - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\

\mathbf{elif}\;y \le 1.736087413763324001573940804782881383422 \cdot 10^{-76}:\\
\;\;\;\;2 \cdot x + \left(\left(\sqrt{27} \cdot \left(a \cdot b\right)\right) \cdot \sqrt{27} - \left(z \cdot y\right) \cdot \left(t \cdot 9\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r34745489 = x;
        double r34745490 = 2.0;
        double r34745491 = r34745489 * r34745490;
        double r34745492 = y;
        double r34745493 = 9.0;
        double r34745494 = r34745492 * r34745493;
        double r34745495 = z;
        double r34745496 = r34745494 * r34745495;
        double r34745497 = t;
        double r34745498 = r34745496 * r34745497;
        double r34745499 = r34745491 - r34745498;
        double r34745500 = a;
        double r34745501 = 27.0;
        double r34745502 = r34745500 * r34745501;
        double r34745503 = b;
        double r34745504 = r34745502 * r34745503;
        double r34745505 = r34745499 + r34745504;
        return r34745505;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r34745506 = y;
        double r34745507 = -2.0965101724637693e-52;
        bool r34745508 = r34745506 <= r34745507;
        double r34745509 = a;
        double r34745510 = 27.0;
        double r34745511 = r34745509 * r34745510;
        double r34745512 = b;
        double r34745513 = 2.0;
        double r34745514 = x;
        double r34745515 = r34745513 * r34745514;
        double r34745516 = 9.0;
        double r34745517 = z;
        double r34745518 = t;
        double r34745519 = r34745517 * r34745518;
        double r34745520 = r34745516 * r34745519;
        double r34745521 = r34745506 * r34745520;
        double r34745522 = r34745515 - r34745521;
        double r34745523 = fma(r34745511, r34745512, r34745522);
        double r34745524 = 1.736087413763324e-76;
        bool r34745525 = r34745506 <= r34745524;
        double r34745526 = sqrt(r34745510);
        double r34745527 = r34745509 * r34745512;
        double r34745528 = r34745526 * r34745527;
        double r34745529 = r34745528 * r34745526;
        double r34745530 = r34745517 * r34745506;
        double r34745531 = r34745518 * r34745516;
        double r34745532 = r34745530 * r34745531;
        double r34745533 = r34745529 - r34745532;
        double r34745534 = r34745515 + r34745533;
        double r34745535 = r34745510 * r34745527;
        double r34745536 = r34745531 * r34745517;
        double r34745537 = r34745536 * r34745506;
        double r34745538 = r34745535 - r34745537;
        double r34745539 = r34745515 + r34745538;
        double r34745540 = r34745525 ? r34745534 : r34745539;
        double r34745541 = r34745508 ? r34745523 : r34745540;
        return r34745541;
}

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.7
Herbie0.9
\[\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 < -2.0965101724637693e-52

    1. Initial program 7.0

      \[\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 6.6

      \[\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. Simplified1.1

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

    if -2.0965101724637693e-52 < y < 1.736087413763324e-76

    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. Taylor expanded around inf 0.6

      \[\leadsto \left(x \cdot 2 - \color{blue}{9 \cdot \left(t \cdot \left(z \cdot y\right)\right)}\right) + \left(a \cdot 27\right) \cdot b\]
    3. Using strategy rm
    4. Applied sub-neg0.6

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

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

      \[\leadsto x \cdot 2 + \color{blue}{\left(27 \cdot \left(a \cdot b\right) - \left(y \cdot z\right) \cdot \left(9 \cdot t\right)\right)}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.7

      \[\leadsto x \cdot 2 + \left(\color{blue}{\left(\sqrt{27} \cdot \sqrt{27}\right)} \cdot \left(a \cdot b\right) - \left(y \cdot z\right) \cdot \left(9 \cdot t\right)\right)\]
    9. Applied associate-*l*0.7

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

    if 1.736087413763324e-76 < y

    1. Initial program 5.9

      \[\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 5.8

      \[\leadsto \left(x \cdot 2 - \color{blue}{9 \cdot \left(t \cdot \left(z \cdot y\right)\right)}\right) + \left(a \cdot 27\right) \cdot b\]
    3. Using strategy rm
    4. Applied sub-neg5.8

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.096510172463769293334958117187919077634 \cdot 10^{-52}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, 2 \cdot x - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{elif}\;y \le 1.736087413763324001573940804782881383422 \cdot 10^{-76}:\\ \;\;\;\;2 \cdot x + \left(\left(\sqrt{27} \cdot \left(a \cdot b\right)\right) \cdot \sqrt{27} - \left(z \cdot y\right) \cdot \left(t \cdot 9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot x + \left(27 \cdot \left(a \cdot b\right) - \left(\left(t \cdot 9\right) \cdot z\right) \cdot y\right)\\ \end{array}\]

Reproduce

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