Average Error: 4.0 → 0.9
Time: 4.4s
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 -2.37460898105936542 \cdot 10^{120} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 2.15379248506655815 \cdot 10^{115}\right):\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - 9 \cdot \left(t \cdot \left(z \cdot y\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}\;\left(y \cdot 9\right) \cdot z \le -2.37460898105936542 \cdot 10^{120} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 2.15379248506655815 \cdot 10^{115}\right):\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r1000673 = x;
        double r1000674 = 2.0;
        double r1000675 = r1000673 * r1000674;
        double r1000676 = y;
        double r1000677 = 9.0;
        double r1000678 = r1000676 * r1000677;
        double r1000679 = z;
        double r1000680 = r1000678 * r1000679;
        double r1000681 = t;
        double r1000682 = r1000680 * r1000681;
        double r1000683 = r1000675 - r1000682;
        double r1000684 = a;
        double r1000685 = 27.0;
        double r1000686 = r1000684 * r1000685;
        double r1000687 = b;
        double r1000688 = r1000686 * r1000687;
        double r1000689 = r1000683 + r1000688;
        return r1000689;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r1000690 = y;
        double r1000691 = 9.0;
        double r1000692 = r1000690 * r1000691;
        double r1000693 = z;
        double r1000694 = r1000692 * r1000693;
        double r1000695 = -2.3746089810593654e+120;
        bool r1000696 = r1000694 <= r1000695;
        double r1000697 = 2.153792485066558e+115;
        bool r1000698 = r1000694 <= r1000697;
        double r1000699 = !r1000698;
        bool r1000700 = r1000696 || r1000699;
        double r1000701 = a;
        double r1000702 = 27.0;
        double r1000703 = b;
        double r1000704 = r1000702 * r1000703;
        double r1000705 = x;
        double r1000706 = 2.0;
        double r1000707 = r1000705 * r1000706;
        double r1000708 = t;
        double r1000709 = r1000693 * r1000708;
        double r1000710 = r1000691 * r1000709;
        double r1000711 = r1000690 * r1000710;
        double r1000712 = r1000707 - r1000711;
        double r1000713 = fma(r1000701, r1000704, r1000712);
        double r1000714 = r1000701 * r1000703;
        double r1000715 = r1000702 * r1000714;
        double r1000716 = r1000693 * r1000690;
        double r1000717 = r1000708 * r1000716;
        double r1000718 = r1000691 * r1000717;
        double r1000719 = r1000715 - r1000718;
        double r1000720 = fma(r1000706, r1000705, r1000719);
        double r1000721 = r1000700 ? r1000713 : r1000720;
        return r1000721;
}

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

Original4.0
Target2.8
Herbie0.9
\[\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) z) < -2.3746089810593654e+120 or 2.153792485066558e+115 < (* (* y 9.0) z)

    1. Initial program 16.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. Simplified17.0

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

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

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

    if -2.3746089810593654e+120 < (* (* y 9.0) z) < 2.153792485066558e+115

    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. Simplified0.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}\]
    3. 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)}\]
    4. Simplified0.4

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

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

Reproduce

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