Average Error: 3.5 → 0.7
Time: 12.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 -1.65054985372108468 \cdot 10^{58} \lor \neg \left(y \cdot 9 \le 7815.61445024938166\right):\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2\right) - \left(\sqrt[3]{9} \cdot \sqrt[3]{9}\right) \cdot \left(\sqrt[3]{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}\;y \cdot 9 \le -1.65054985372108468 \cdot 10^{58} \lor \neg \left(y \cdot 9 \le 7815.61445024938166\right):\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2\right) - \left(\sqrt[3]{9} \cdot \sqrt[3]{9}\right) \cdot \left(\sqrt[3]{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 r722988 = x;
        double r722989 = 2.0;
        double r722990 = r722988 * r722989;
        double r722991 = y;
        double r722992 = 9.0;
        double r722993 = r722991 * r722992;
        double r722994 = z;
        double r722995 = r722993 * r722994;
        double r722996 = t;
        double r722997 = r722995 * r722996;
        double r722998 = r722990 - r722997;
        double r722999 = a;
        double r723000 = 27.0;
        double r723001 = r722999 * r723000;
        double r723002 = b;
        double r723003 = r723001 * r723002;
        double r723004 = r722998 + r723003;
        return r723004;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r723005 = y;
        double r723006 = 9.0;
        double r723007 = r723005 * r723006;
        double r723008 = -1.6505498537210847e+58;
        bool r723009 = r723007 <= r723008;
        double r723010 = 7815.614450249382;
        bool r723011 = r723007 <= r723010;
        double r723012 = !r723011;
        bool r723013 = r723009 || r723012;
        double r723014 = a;
        double r723015 = 27.0;
        double r723016 = r723014 * r723015;
        double r723017 = b;
        double r723018 = x;
        double r723019 = 2.0;
        double r723020 = r723018 * r723019;
        double r723021 = z;
        double r723022 = t;
        double r723023 = r723021 * r723022;
        double r723024 = r723007 * r723023;
        double r723025 = r723020 - r723024;
        double r723026 = fma(r723016, r723017, r723025);
        double r723027 = r723014 * r723017;
        double r723028 = fma(r723015, r723027, r723020);
        double r723029 = cbrt(r723006);
        double r723030 = r723029 * r723029;
        double r723031 = r723021 * r723005;
        double r723032 = r723022 * r723031;
        double r723033 = r723029 * r723032;
        double r723034 = r723030 * r723033;
        double r723035 = r723028 - r723034;
        double r723036 = r723013 ? r723026 : r723035;
        return r723036;
}

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.6
Herbie0.7
\[\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) < -1.6505498537210847e+58 or 7815.614450249382 < (* y 9.0)

    1. Initial program 8.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. Simplified8.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*0.8

      \[\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)\]

    if -1.6505498537210847e+58 < (* y 9.0) < 7815.614450249382

    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. Using strategy rm
    4. Applied associate-*l*5.1

      \[\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. Taylor expanded around inf 0.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(27, a \cdot b, x \cdot 2\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)}\]
    7. Using strategy rm
    8. Applied add-cube-cbrt0.6

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

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

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

Reproduce

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