Average Error: 3.4 → 0.3
Time: 4.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 -3.34355137349026626 \cdot 10^{304} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 1.4897412691355755 \cdot 10^{307}\right):\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - \sqrt{9} \cdot \left(\sqrt{9} \cdot \left(\left(t \cdot z\right) \cdot y\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 -3.34355137349026626 \cdot 10^{304} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 1.4897412691355755 \cdot 10^{307}\right):\\
\;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - \sqrt{9} \cdot \left(\sqrt{9} \cdot \left(\left(t \cdot z\right) \cdot y\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 r764901 = x;
        double r764902 = 2.0;
        double r764903 = r764901 * r764902;
        double r764904 = y;
        double r764905 = 9.0;
        double r764906 = r764904 * r764905;
        double r764907 = z;
        double r764908 = r764906 * r764907;
        double r764909 = t;
        double r764910 = r764908 * r764909;
        double r764911 = r764903 - r764910;
        double r764912 = a;
        double r764913 = 27.0;
        double r764914 = r764912 * r764913;
        double r764915 = b;
        double r764916 = r764914 * r764915;
        double r764917 = r764911 + r764916;
        return r764917;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r764918 = y;
        double r764919 = 9.0;
        double r764920 = r764918 * r764919;
        double r764921 = z;
        double r764922 = r764920 * r764921;
        double r764923 = -3.3435513734902663e+304;
        bool r764924 = r764922 <= r764923;
        double r764925 = 1.4897412691355755e+307;
        bool r764926 = r764922 <= r764925;
        double r764927 = !r764926;
        bool r764928 = r764924 || r764927;
        double r764929 = 2.0;
        double r764930 = x;
        double r764931 = 27.0;
        double r764932 = a;
        double r764933 = b;
        double r764934 = r764932 * r764933;
        double r764935 = r764931 * r764934;
        double r764936 = sqrt(r764919);
        double r764937 = t;
        double r764938 = r764937 * r764921;
        double r764939 = r764938 * r764918;
        double r764940 = r764936 * r764939;
        double r764941 = r764936 * r764940;
        double r764942 = r764935 - r764941;
        double r764943 = fma(r764929, r764930, r764942);
        double r764944 = r764921 * r764918;
        double r764945 = r764937 * r764944;
        double r764946 = r764919 * r764945;
        double r764947 = r764935 - r764946;
        double r764948 = fma(r764929, r764930, r764947);
        double r764949 = r764928 ? r764943 : r764948;
        return r764949;
}

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.4
Target2.4
Herbie0.3
\[\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) < -3.3435513734902663e+304 or 1.4897412691355755e+307 < (* (* y 9.0) z)

    1. Initial program 61.6

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

      \[\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 59.9

      \[\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. Simplified59.9

      \[\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 add-sqr-sqrt59.9

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

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

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

    if -3.3435513734902663e+304 < (* (* y 9.0) z) < 1.4897412691355755e+307

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \le -3.34355137349026626 \cdot 10^{304} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 1.4897412691355755 \cdot 10^{307}\right):\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - \sqrt{9} \cdot \left(\sqrt{9} \cdot \left(\left(t \cdot z\right) \cdot y\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 2020065 +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)))