Average Error: 3.5 → 0.9
Time: 19.8s
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(\left(y \cdot 9\right) \cdot z\right) \cdot t \le -4.597705171623115901365317967165424901369 \cdot 10^{297}:\\ \;\;\;\;\mathsf{fma}\left(27 \cdot a, b, 2 \cdot x\right) - z \cdot \left(\left(t \cdot y\right) \cdot 9\right)\\ \mathbf{elif}\;\left(\left(y \cdot 9\right) \cdot z\right) \cdot t \le 2.902082859828543998174010225498745187007 \cdot 10^{261}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(2 \cdot x - \left(\left(z \cdot 9\right) \cdot y\right) \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(27 \cdot a, b, 2 \cdot x\right) - \left(y \cdot \left(z \cdot t\right)\right) \cdot 9\\ \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(\left(y \cdot 9\right) \cdot z\right) \cdot t \le -4.597705171623115901365317967165424901369 \cdot 10^{297}:\\
\;\;\;\;\mathsf{fma}\left(27 \cdot a, b, 2 \cdot x\right) - z \cdot \left(\left(t \cdot y\right) \cdot 9\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r35318059 = x;
        double r35318060 = 2.0;
        double r35318061 = r35318059 * r35318060;
        double r35318062 = y;
        double r35318063 = 9.0;
        double r35318064 = r35318062 * r35318063;
        double r35318065 = z;
        double r35318066 = r35318064 * r35318065;
        double r35318067 = t;
        double r35318068 = r35318066 * r35318067;
        double r35318069 = r35318061 - r35318068;
        double r35318070 = a;
        double r35318071 = 27.0;
        double r35318072 = r35318070 * r35318071;
        double r35318073 = b;
        double r35318074 = r35318072 * r35318073;
        double r35318075 = r35318069 + r35318074;
        return r35318075;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r35318076 = y;
        double r35318077 = 9.0;
        double r35318078 = r35318076 * r35318077;
        double r35318079 = z;
        double r35318080 = r35318078 * r35318079;
        double r35318081 = t;
        double r35318082 = r35318080 * r35318081;
        double r35318083 = -4.597705171623116e+297;
        bool r35318084 = r35318082 <= r35318083;
        double r35318085 = 27.0;
        double r35318086 = a;
        double r35318087 = r35318085 * r35318086;
        double r35318088 = b;
        double r35318089 = 2.0;
        double r35318090 = x;
        double r35318091 = r35318089 * r35318090;
        double r35318092 = fma(r35318087, r35318088, r35318091);
        double r35318093 = r35318081 * r35318076;
        double r35318094 = r35318093 * r35318077;
        double r35318095 = r35318079 * r35318094;
        double r35318096 = r35318092 - r35318095;
        double r35318097 = 2.902082859828544e+261;
        bool r35318098 = r35318082 <= r35318097;
        double r35318099 = r35318085 * r35318088;
        double r35318100 = r35318086 * r35318099;
        double r35318101 = r35318079 * r35318077;
        double r35318102 = r35318101 * r35318076;
        double r35318103 = r35318102 * r35318081;
        double r35318104 = r35318091 - r35318103;
        double r35318105 = r35318100 + r35318104;
        double r35318106 = r35318079 * r35318081;
        double r35318107 = r35318076 * r35318106;
        double r35318108 = r35318107 * r35318077;
        double r35318109 = r35318092 - r35318108;
        double r35318110 = r35318098 ? r35318105 : r35318109;
        double r35318111 = r35318084 ? r35318096 : r35318110;
        return r35318111;
}

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.5
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 9.0) z) t) < -4.597705171623116e+297

    1. Initial program 55.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. Simplified4.3

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

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

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

    if -4.597705171623116e+297 < (* (* (* y 9.0) z) t) < 2.902082859828544e+261

    1. Initial program 0.3

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
    2. Using strategy rm
    3. Applied associate-*l*0.4

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

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

    if 2.902082859828544e+261 < (* (* (* y 9.0) z) t)

    1. Initial program 39.2

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

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

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

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

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

Reproduce

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