Average Error: 3.8 → 0.9
Time: 11.1s
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}\;y \cdot 9 \le -9.603020082180995 \cdot 10^{-84} \lor \neg \left(y \cdot 9 \le 1.8103678616736211 \cdot 10^{41}\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(\left(y \cdot 9\right) \cdot z\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}\;y \cdot 9 \le -9.603020082180995 \cdot 10^{-84} \lor \neg \left(y \cdot 9 \le 1.8103678616736211 \cdot 10^{41}\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(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r946141 = x;
        double r946142 = 2.0;
        double r946143 = r946141 * r946142;
        double r946144 = y;
        double r946145 = 9.0;
        double r946146 = r946144 * r946145;
        double r946147 = z;
        double r946148 = r946146 * r946147;
        double r946149 = t;
        double r946150 = r946148 * r946149;
        double r946151 = r946143 - r946150;
        double r946152 = a;
        double r946153 = 27.0;
        double r946154 = r946152 * r946153;
        double r946155 = b;
        double r946156 = r946154 * r946155;
        double r946157 = r946151 + r946156;
        return r946157;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r946158 = y;
        double r946159 = 9.0;
        double r946160 = r946158 * r946159;
        double r946161 = -9.603020082180995e-84;
        bool r946162 = r946160 <= r946161;
        double r946163 = 1.810367861673621e+41;
        bool r946164 = r946160 <= r946163;
        double r946165 = !r946164;
        bool r946166 = r946162 || r946165;
        double r946167 = a;
        double r946168 = 27.0;
        double r946169 = r946167 * r946168;
        double r946170 = b;
        double r946171 = x;
        double r946172 = 2.0;
        double r946173 = r946171 * r946172;
        double r946174 = z;
        double r946175 = r946159 * r946174;
        double r946176 = t;
        double r946177 = r946175 * r946176;
        double r946178 = r946158 * r946177;
        double r946179 = r946173 - r946178;
        double r946180 = fma(r946169, r946170, r946179);
        double r946181 = r946160 * r946174;
        double r946182 = r946181 * r946176;
        double r946183 = r946173 - r946182;
        double r946184 = fma(r946169, r946170, r946183);
        double r946185 = r946166 ? r946180 : r946184;
        return r946185;
}

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.6
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) < -9.603020082180995e-84 or 1.810367861673621e+41 < (* y 9.0)

    1. Initial program 7.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. Simplified7.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*1.3

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

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

      \[\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 -9.603020082180995e-84 < (* y 9.0) < 1.810367861673621e+41

    1. Initial program 0.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot 9 \le -9.603020082180995 \cdot 10^{-84} \lor \neg \left(y \cdot 9 \le 1.8103678616736211 \cdot 10^{41}\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(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)\\ \end{array}\]

Reproduce

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