Average Error: 4.0 → 0.6
Time: 19.1s
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 -2.224794104309224529458788310876116156578:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2 - \left(y \cdot \left(z \cdot t\right)\right) \cdot 9\right)\\ \mathbf{elif}\;y \cdot 9 \le 9.796039309886120902205025799034389667047 \cdot 10^{68}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2 - \left(\left(9 \cdot t\right) \cdot y\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2 - \left(y \cdot \left(z \cdot t\right)\right) \cdot 9\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 -2.224794104309224529458788310876116156578:\\
\;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2 - \left(y \cdot \left(z \cdot t\right)\right) \cdot 9\right)\\

\mathbf{elif}\;y \cdot 9 \le 9.796039309886120902205025799034389667047 \cdot 10^{68}:\\
\;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2 - \left(\left(9 \cdot t\right) \cdot y\right) \cdot z\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r31311086 = x;
        double r31311087 = 2.0;
        double r31311088 = r31311086 * r31311087;
        double r31311089 = y;
        double r31311090 = 9.0;
        double r31311091 = r31311089 * r31311090;
        double r31311092 = z;
        double r31311093 = r31311091 * r31311092;
        double r31311094 = t;
        double r31311095 = r31311093 * r31311094;
        double r31311096 = r31311088 - r31311095;
        double r31311097 = a;
        double r31311098 = 27.0;
        double r31311099 = r31311097 * r31311098;
        double r31311100 = b;
        double r31311101 = r31311099 * r31311100;
        double r31311102 = r31311096 + r31311101;
        return r31311102;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r31311103 = y;
        double r31311104 = 9.0;
        double r31311105 = r31311103 * r31311104;
        double r31311106 = -2.2247941043092245;
        bool r31311107 = r31311105 <= r31311106;
        double r31311108 = 27.0;
        double r31311109 = a;
        double r31311110 = b;
        double r31311111 = r31311109 * r31311110;
        double r31311112 = x;
        double r31311113 = 2.0;
        double r31311114 = r31311112 * r31311113;
        double r31311115 = z;
        double r31311116 = t;
        double r31311117 = r31311115 * r31311116;
        double r31311118 = r31311103 * r31311117;
        double r31311119 = r31311118 * r31311104;
        double r31311120 = r31311114 - r31311119;
        double r31311121 = fma(r31311108, r31311111, r31311120);
        double r31311122 = 9.79603930988612e+68;
        bool r31311123 = r31311105 <= r31311122;
        double r31311124 = r31311104 * r31311116;
        double r31311125 = r31311124 * r31311103;
        double r31311126 = r31311125 * r31311115;
        double r31311127 = r31311114 - r31311126;
        double r31311128 = fma(r31311108, r31311111, r31311127);
        double r31311129 = r31311123 ? r31311128 : r31311121;
        double r31311130 = r31311107 ? r31311121 : r31311129;
        return r31311130;
}

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.7
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 (* y 9.0) < -2.2247941043092245 or 9.79603930988612e+68 < (* y 9.0)

    1. Initial program 9.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. Simplified9.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, x, \left(27 \cdot b\right) \cdot a - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}\]
    3. Taylor expanded around inf 9.0

      \[\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. Simplified9.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(27, b \cdot a, x \cdot 2 - \left(z \cdot y\right) \cdot \left(t \cdot 9\right)\right)}\]
    5. Taylor expanded around inf 9.0

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

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

    if -2.2247941043092245 < (* y 9.0) < 9.79603930988612e+68

    1. Initial program 0.8

      \[\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(2, x, \left(27 \cdot b\right) \cdot a - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}\]
    3. Taylor expanded around inf 0.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. Simplified0.8

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

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

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

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, A"

  :herbie-target
  (if (< y 7.590524218811189e-161) (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* a (* 27.0 b))) (+ (- (* x 2.0) (* 9.0 (* y (* t z)))) (* (* a 27.0) b)))

  (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))