Average Error: 3.4 → 0.7
Time: 11.6s
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 = -\infty \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 1.982356267908346873207829061012719061228 \cdot 10^{115}\right):\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, 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 = -\infty \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 1.982356267908346873207829061012719061228 \cdot 10^{115}\right):\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \cdot t\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, 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 r898928 = x;
        double r898929 = 2.0;
        double r898930 = r898928 * r898929;
        double r898931 = y;
        double r898932 = 9.0;
        double r898933 = r898931 * r898932;
        double r898934 = z;
        double r898935 = r898933 * r898934;
        double r898936 = t;
        double r898937 = r898935 * r898936;
        double r898938 = r898930 - r898937;
        double r898939 = a;
        double r898940 = 27.0;
        double r898941 = r898939 * r898940;
        double r898942 = b;
        double r898943 = r898941 * r898942;
        double r898944 = r898938 + r898943;
        return r898944;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r898945 = y;
        double r898946 = 9.0;
        double r898947 = r898945 * r898946;
        double r898948 = z;
        double r898949 = r898947 * r898948;
        double r898950 = -inf.0;
        bool r898951 = r898949 <= r898950;
        double r898952 = 1.982356267908347e+115;
        bool r898953 = r898949 <= r898952;
        double r898954 = !r898953;
        bool r898955 = r898951 || r898954;
        double r898956 = a;
        double r898957 = 27.0;
        double r898958 = r898956 * r898957;
        double r898959 = b;
        double r898960 = x;
        double r898961 = 2.0;
        double r898962 = r898960 * r898961;
        double r898963 = r898946 * r898948;
        double r898964 = t;
        double r898965 = r898963 * r898964;
        double r898966 = r898945 * r898965;
        double r898967 = r898962 - r898966;
        double r898968 = fma(r898958, r898959, r898967);
        double r898969 = r898945 * r898963;
        double r898970 = r898969 * r898964;
        double r898971 = r898962 - r898970;
        double r898972 = fma(r898958, r898959, r898971);
        double r898973 = r898955 ? r898968 : r898972;
        return r898973;
}

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.4
Target2.4
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) < -inf.0 or 1.982356267908347e+115 < (* (* y 9.0) z)

    1. Initial program 23.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. Simplified23.5

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

      \[\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)\]
    5. Using strategy rm
    6. Applied associate-*l*2.2

      \[\leadsto \mathsf{fma}\left(a \cdot 27, 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.4

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

    if -inf.0 < (* (* y 9.0) z) < 1.982356267908347e+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.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 associate-*l*0.5

      \[\leadsto \mathsf{fma}\left(a \cdot 27, 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.7

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

Reproduce

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