Average Error: 3.8 → 0.6
Time: 4.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}\;t \le -1.442353657523720384679958711284619115705 \cdot 10^{-17} \lor \neg \left(t \le 1860873616316365328357708884770553856\right):\\ \;\;\;\;\mathsf{fma}\left(2, x, \left(27 \cdot a\right) \cdot b - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - \left(\left(9 \cdot t\right) \cdot z\right) \cdot y\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}\;t \le -1.442353657523720384679958711284619115705 \cdot 10^{-17} \lor \neg \left(t \le 1860873616316365328357708884770553856\right):\\
\;\;\;\;\mathsf{fma}\left(2, x, \left(27 \cdot a\right) \cdot b - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r686901 = x;
        double r686902 = 2.0;
        double r686903 = r686901 * r686902;
        double r686904 = y;
        double r686905 = 9.0;
        double r686906 = r686904 * r686905;
        double r686907 = z;
        double r686908 = r686906 * r686907;
        double r686909 = t;
        double r686910 = r686908 * r686909;
        double r686911 = r686903 - r686910;
        double r686912 = a;
        double r686913 = 27.0;
        double r686914 = r686912 * r686913;
        double r686915 = b;
        double r686916 = r686914 * r686915;
        double r686917 = r686911 + r686916;
        return r686917;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r686918 = t;
        double r686919 = -1.4423536575237204e-17;
        bool r686920 = r686918 <= r686919;
        double r686921 = 1.8608736163163653e+36;
        bool r686922 = r686918 <= r686921;
        double r686923 = !r686922;
        bool r686924 = r686920 || r686923;
        double r686925 = 2.0;
        double r686926 = x;
        double r686927 = 27.0;
        double r686928 = a;
        double r686929 = r686927 * r686928;
        double r686930 = b;
        double r686931 = r686929 * r686930;
        double r686932 = 9.0;
        double r686933 = z;
        double r686934 = y;
        double r686935 = r686933 * r686934;
        double r686936 = r686918 * r686935;
        double r686937 = r686932 * r686936;
        double r686938 = r686931 - r686937;
        double r686939 = fma(r686925, r686926, r686938);
        double r686940 = r686928 * r686930;
        double r686941 = r686927 * r686940;
        double r686942 = r686932 * r686918;
        double r686943 = r686942 * r686933;
        double r686944 = r686943 * r686934;
        double r686945 = r686941 - r686944;
        double r686946 = fma(r686925, r686926, r686945);
        double r686947 = r686924 ? r686939 : r686946;
        return r686947;
}

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
Herbie0.6
\[\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 t < -1.4423536575237204e-17 or 1.8608736163163653e+36 < t

    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.8

      \[\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.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)}\]
    4. Simplified0.6

      \[\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)}\]
    5. Using strategy rm
    6. Applied associate-*r*0.6

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

    if -1.4423536575237204e-17 < t < 1.8608736163163653e+36

    1. Initial program 6.0

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

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

      \[\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)}\]
    5. Using strategy rm
    6. Applied associate-*r*5.8

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

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

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

Reproduce

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