Average Error: 3.8 → 0.7
Time: 19.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.547759248047978209133550690022447008716 \cdot 10^{265}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \cdot t\right)\right)\\ \mathbf{elif}\;\left(y \cdot 9\right) \cdot z \le 3.935254980880975040051591172421922624115 \cdot 10^{135}:\\ \;\;\;\;\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \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 -2.547759248047978209133550690022447008716 \cdot 10^{265}:\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \cdot t\right)\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r47984617 = x;
        double r47984618 = 2.0;
        double r47984619 = r47984617 * r47984618;
        double r47984620 = y;
        double r47984621 = 9.0;
        double r47984622 = r47984620 * r47984621;
        double r47984623 = z;
        double r47984624 = r47984622 * r47984623;
        double r47984625 = t;
        double r47984626 = r47984624 * r47984625;
        double r47984627 = r47984619 - r47984626;
        double r47984628 = a;
        double r47984629 = 27.0;
        double r47984630 = r47984628 * r47984629;
        double r47984631 = b;
        double r47984632 = r47984630 * r47984631;
        double r47984633 = r47984627 + r47984632;
        return r47984633;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r47984634 = y;
        double r47984635 = 9.0;
        double r47984636 = r47984634 * r47984635;
        double r47984637 = z;
        double r47984638 = r47984636 * r47984637;
        double r47984639 = -2.5477592480479782e+265;
        bool r47984640 = r47984638 <= r47984639;
        double r47984641 = a;
        double r47984642 = 27.0;
        double r47984643 = b;
        double r47984644 = r47984642 * r47984643;
        double r47984645 = x;
        double r47984646 = 2.0;
        double r47984647 = r47984645 * r47984646;
        double r47984648 = r47984635 * r47984637;
        double r47984649 = t;
        double r47984650 = r47984648 * r47984649;
        double r47984651 = r47984634 * r47984650;
        double r47984652 = r47984647 - r47984651;
        double r47984653 = fma(r47984641, r47984644, r47984652);
        double r47984654 = 3.935254980880975e+135;
        bool r47984655 = r47984638 <= r47984654;
        double r47984656 = r47984638 * r47984649;
        double r47984657 = r47984647 - r47984656;
        double r47984658 = r47984641 * r47984642;
        double r47984659 = r47984658 * r47984643;
        double r47984660 = r47984657 + r47984659;
        double r47984661 = r47984655 ? r47984660 : r47984653;
        double r47984662 = r47984640 ? r47984653 : r47984661;
        return r47984662;
}

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.8
Herbie0.7
\[\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 2 regimes
  2. if (* (* y 9.0) z) < -2.5477592480479782e+265 or 3.935254980880975e+135 < (* (* y 9.0) z)

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

      \[\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*2.5

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

      \[\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)\]
    7. Using strategy rm
    8. Applied associate-*r*2.3

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

    if -2.5477592480479782e+265 < (* (* y 9.0) z) < 3.935254980880975e+135

    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\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

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

Reproduce

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