Average Error: 3.7 → 0.8
Time: 14.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}\;y \cdot 9 \le -7.76493181041917186 \cdot 10^{-70} \lor \neg \left(y \cdot 9 \le 1.1033717482674748 \cdot 10^{-70}\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(27, a \cdot b, 2 \cdot x\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\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 -7.76493181041917186 \cdot 10^{-70} \lor \neg \left(y \cdot 9 \le 1.1033717482674748 \cdot 10^{-70}\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(27, a \cdot b, 2 \cdot x\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r745373 = x;
        double r745374 = 2.0;
        double r745375 = r745373 * r745374;
        double r745376 = y;
        double r745377 = 9.0;
        double r745378 = r745376 * r745377;
        double r745379 = z;
        double r745380 = r745378 * r745379;
        double r745381 = t;
        double r745382 = r745380 * r745381;
        double r745383 = r745375 - r745382;
        double r745384 = a;
        double r745385 = 27.0;
        double r745386 = r745384 * r745385;
        double r745387 = b;
        double r745388 = r745386 * r745387;
        double r745389 = r745383 + r745388;
        return r745389;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r745390 = y;
        double r745391 = 9.0;
        double r745392 = r745390 * r745391;
        double r745393 = -7.764931810419172e-70;
        bool r745394 = r745392 <= r745393;
        double r745395 = 1.1033717482674748e-70;
        bool r745396 = r745392 <= r745395;
        double r745397 = !r745396;
        bool r745398 = r745394 || r745397;
        double r745399 = a;
        double r745400 = 27.0;
        double r745401 = r745399 * r745400;
        double r745402 = b;
        double r745403 = x;
        double r745404 = 2.0;
        double r745405 = r745403 * r745404;
        double r745406 = z;
        double r745407 = r745391 * r745406;
        double r745408 = t;
        double r745409 = r745407 * r745408;
        double r745410 = r745390 * r745409;
        double r745411 = r745405 - r745410;
        double r745412 = fma(r745401, r745402, r745411);
        double r745413 = r745399 * r745402;
        double r745414 = r745404 * r745403;
        double r745415 = fma(r745400, r745413, r745414);
        double r745416 = r745406 * r745390;
        double r745417 = r745408 * r745416;
        double r745418 = r745391 * r745417;
        double r745419 = r745415 - r745418;
        double r745420 = r745398 ? r745412 : r745419;
        return r745420;
}

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.7
Target2.5
Herbie0.8
\[\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) < -7.764931810419172e-70 or 1.1033717482674748e-70 < (* y 9.0)

    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(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*6.2

      \[\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)\]
    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(\left(9 \cdot z\right) \cdot t\right)}\right)\]

    if -7.764931810419172e-70 < (* y 9.0) < 1.1033717482674748e-70

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

      \[\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)\]
    5. Taylor expanded around inf 0.4

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

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

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

Reproduce

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