Average Error: 4.0 → 0.9
Time: 3.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(y \cdot 9\right) \cdot z \le -2.37460898105936542 \cdot 10^{120} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 2.15379248506655815 \cdot 10^{115}\right):\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\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}\;\left(y \cdot 9\right) \cdot z \le -2.37460898105936542 \cdot 10^{120} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 2.15379248506655815 \cdot 10^{115}\right):\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r815447 = x;
        double r815448 = 2.0;
        double r815449 = r815447 * r815448;
        double r815450 = y;
        double r815451 = 9.0;
        double r815452 = r815450 * r815451;
        double r815453 = z;
        double r815454 = r815452 * r815453;
        double r815455 = t;
        double r815456 = r815454 * r815455;
        double r815457 = r815449 - r815456;
        double r815458 = a;
        double r815459 = 27.0;
        double r815460 = r815458 * r815459;
        double r815461 = b;
        double r815462 = r815460 * r815461;
        double r815463 = r815457 + r815462;
        return r815463;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r815464 = y;
        double r815465 = 9.0;
        double r815466 = r815464 * r815465;
        double r815467 = z;
        double r815468 = r815466 * r815467;
        double r815469 = -2.3746089810593654e+120;
        bool r815470 = r815468 <= r815469;
        double r815471 = 2.153792485066558e+115;
        bool r815472 = r815468 <= r815471;
        double r815473 = !r815472;
        bool r815474 = r815470 || r815473;
        double r815475 = a;
        double r815476 = 27.0;
        double r815477 = b;
        double r815478 = r815476 * r815477;
        double r815479 = x;
        double r815480 = 2.0;
        double r815481 = r815479 * r815480;
        double r815482 = t;
        double r815483 = r815467 * r815482;
        double r815484 = r815465 * r815483;
        double r815485 = r815464 * r815484;
        double r815486 = r815481 - r815485;
        double r815487 = fma(r815475, r815478, r815486);
        double r815488 = r815475 * r815477;
        double r815489 = r815476 * r815488;
        double r815490 = r815467 * r815464;
        double r815491 = r815482 * r815490;
        double r815492 = r815465 * r815491;
        double r815493 = r815489 - r815492;
        double r815494 = fma(r815480, r815479, r815493);
        double r815495 = r815474 ? r815487 : r815494;
        return r815495;
}

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

Original4.0
Target2.8
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) z) < -2.3746089810593654e+120 or 2.153792485066558e+115 < (* (* y 9.0) z)

    1. Initial program 16.9

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

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

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

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

    if -2.3746089810593654e+120 < (* (* y 9.0) z) < 2.153792485066558e+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.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}\]
    3. 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)}\]
    4. Simplified0.4

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

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

Reproduce

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