Average Error: 3.8 → 2.3
Time: 18.0s
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 -2.869136866886615148163974140793583317465 \cdot 10^{-79}:\\ \;\;\;\;\mathsf{fma}\left(2, x, \left(27 \cdot b\right) \cdot a - \left(y \cdot 9\right) \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(b \cdot a\right) - \left(t \cdot \left(z \cdot y\right)\right) \cdot 9\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 -2.869136866886615148163974140793583317465 \cdot 10^{-79}:\\
\;\;\;\;\mathsf{fma}\left(2, x, \left(27 \cdot b\right) \cdot a - \left(y \cdot 9\right) \cdot \left(t \cdot z\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r549378 = x;
        double r549379 = 2.0;
        double r549380 = r549378 * r549379;
        double r549381 = y;
        double r549382 = 9.0;
        double r549383 = r549381 * r549382;
        double r549384 = z;
        double r549385 = r549383 * r549384;
        double r549386 = t;
        double r549387 = r549385 * r549386;
        double r549388 = r549380 - r549387;
        double r549389 = a;
        double r549390 = 27.0;
        double r549391 = r549389 * r549390;
        double r549392 = b;
        double r549393 = r549391 * r549392;
        double r549394 = r549388 + r549393;
        return r549394;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r549395 = y;
        double r549396 = 9.0;
        double r549397 = r549395 * r549396;
        double r549398 = -2.869136866886615e-79;
        bool r549399 = r549397 <= r549398;
        double r549400 = 2.0;
        double r549401 = x;
        double r549402 = 27.0;
        double r549403 = b;
        double r549404 = r549402 * r549403;
        double r549405 = a;
        double r549406 = r549404 * r549405;
        double r549407 = t;
        double r549408 = z;
        double r549409 = r549407 * r549408;
        double r549410 = r549397 * r549409;
        double r549411 = r549406 - r549410;
        double r549412 = fma(r549400, r549401, r549411);
        double r549413 = r549403 * r549405;
        double r549414 = r549402 * r549413;
        double r549415 = r549408 * r549395;
        double r549416 = r549407 * r549415;
        double r549417 = r549416 * r549396;
        double r549418 = r549414 - r549417;
        double r549419 = fma(r549400, r549401, r549418);
        double r549420 = r549399 ? r549412 : r549419;
        return r549420;
}

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
Herbie2.3
\[\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) < -2.869136866886615e-79

    1. Initial program 6.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. Simplified6.3

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

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

    if -2.869136866886615e-79 < (* y 9.0)

    1. Initial program 2.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, x, \left(27 \cdot b\right) \cdot a - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}\]
    3. Taylor expanded around inf 2.8

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

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

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

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

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

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

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

Reproduce

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