Average Error: 3.5 → 0.6
Time: 4.7s
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.7471384292377557 \cdot 10^{115} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 3.57765631213840802 \cdot 10^{305}\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(a, 27 \cdot b, x \cdot 2 - \left(y \cdot \left(9 \cdot z\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}\;\left(y \cdot 9\right) \cdot z \le -2.7471384292377557 \cdot 10^{115} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 3.57765631213840802 \cdot 10^{305}\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(a, 27 \cdot b, x \cdot 2 - \left(y \cdot \left(9 \cdot z\right)\right) \cdot t\right)\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r767909 = x;
        double r767910 = 2.0;
        double r767911 = r767909 * r767910;
        double r767912 = y;
        double r767913 = 9.0;
        double r767914 = r767912 * r767913;
        double r767915 = z;
        double r767916 = r767914 * r767915;
        double r767917 = t;
        double r767918 = r767916 * r767917;
        double r767919 = r767911 - r767918;
        double r767920 = a;
        double r767921 = 27.0;
        double r767922 = r767920 * r767921;
        double r767923 = b;
        double r767924 = r767922 * r767923;
        double r767925 = r767919 + r767924;
        return r767925;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r767926 = y;
        double r767927 = 9.0;
        double r767928 = r767926 * r767927;
        double r767929 = z;
        double r767930 = r767928 * r767929;
        double r767931 = -2.7471384292377557e+115;
        bool r767932 = r767930 <= r767931;
        double r767933 = 3.577656312138408e+305;
        bool r767934 = r767930 <= r767933;
        double r767935 = !r767934;
        bool r767936 = r767932 || r767935;
        double r767937 = a;
        double r767938 = 27.0;
        double r767939 = b;
        double r767940 = r767938 * r767939;
        double r767941 = x;
        double r767942 = 2.0;
        double r767943 = r767941 * r767942;
        double r767944 = t;
        double r767945 = r767929 * r767944;
        double r767946 = r767927 * r767945;
        double r767947 = r767926 * r767946;
        double r767948 = r767943 - r767947;
        double r767949 = fma(r767937, r767940, r767948);
        double r767950 = r767927 * r767929;
        double r767951 = r767926 * r767950;
        double r767952 = r767951 * r767944;
        double r767953 = r767943 - r767952;
        double r767954 = fma(r767937, r767940, r767953);
        double r767955 = r767936 ? r767949 : r767954;
        return r767955;
}

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.5
Target2.3
Herbie0.6
\[\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.7471384292377557e+115 or 3.577656312138408e+305 < (* (* y 9.0) z)

    1. Initial program 24.5

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

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

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

      \[\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.7471384292377557e+115 < (* (* y 9.0) z) < 3.577656312138408e+305

    1. Initial program 0.5

      \[\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. Using strategy rm
    4. Applied associate-*l*0.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \le -2.7471384292377557 \cdot 10^{115} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 3.57765631213840802 \cdot 10^{305}\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(a, 27 \cdot b, x \cdot 2 - \left(y \cdot \left(9 \cdot z\right)\right) \cdot t\right)\\ \end{array}\]

Reproduce

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