Average Error: 3.7 → 1.1
Time: 16.7s
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 -4.472646977999147758850568062024165086616 \cdot 10^{149} \lor \neg \left(t \le 3.005129524995899454198697984750523172631 \cdot 10^{-32}\right):\\ \;\;\;\;\mathsf{fma}\left(\left(-t\right) \cdot \left(y \cdot z\right), 9, x \cdot 2\right) + \left(27 \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot t, y \cdot \left(-9\right), \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2\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}\;t \le -4.472646977999147758850568062024165086616 \cdot 10^{149} \lor \neg \left(t \le 3.005129524995899454198697984750523172631 \cdot 10^{-32}\right):\\
\;\;\;\;\mathsf{fma}\left(\left(-t\right) \cdot \left(y \cdot z\right), 9, x \cdot 2\right) + \left(27 \cdot a\right) \cdot b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r720006 = x;
        double r720007 = 2.0;
        double r720008 = r720006 * r720007;
        double r720009 = y;
        double r720010 = 9.0;
        double r720011 = r720009 * r720010;
        double r720012 = z;
        double r720013 = r720011 * r720012;
        double r720014 = t;
        double r720015 = r720013 * r720014;
        double r720016 = r720008 - r720015;
        double r720017 = a;
        double r720018 = 27.0;
        double r720019 = r720017 * r720018;
        double r720020 = b;
        double r720021 = r720019 * r720020;
        double r720022 = r720016 + r720021;
        return r720022;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r720023 = t;
        double r720024 = -4.472646977999148e+149;
        bool r720025 = r720023 <= r720024;
        double r720026 = 3.0051295249958995e-32;
        bool r720027 = r720023 <= r720026;
        double r720028 = !r720027;
        bool r720029 = r720025 || r720028;
        double r720030 = -r720023;
        double r720031 = y;
        double r720032 = z;
        double r720033 = r720031 * r720032;
        double r720034 = r720030 * r720033;
        double r720035 = 9.0;
        double r720036 = x;
        double r720037 = 2.0;
        double r720038 = r720036 * r720037;
        double r720039 = fma(r720034, r720035, r720038);
        double r720040 = 27.0;
        double r720041 = a;
        double r720042 = r720040 * r720041;
        double r720043 = b;
        double r720044 = r720042 * r720043;
        double r720045 = r720039 + r720044;
        double r720046 = r720032 * r720023;
        double r720047 = -r720035;
        double r720048 = r720031 * r720047;
        double r720049 = r720040 * r720043;
        double r720050 = fma(r720041, r720049, r720038);
        double r720051 = fma(r720046, r720048, r720050);
        double r720052 = r720029 ? r720045 : r720051;
        return r720052;
}

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.7
Target2.7
Herbie1.1
\[\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 < -4.472646977999148e+149 or 3.0051295249958995e-32 < t

    1. Initial program 0.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. Using strategy rm
    3. Applied fma-neg0.9

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

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot x - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)} + \left(a \cdot 27\right) \cdot b\]
    8. Simplified0.8

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

    if -4.472646977999148e+149 < t < 3.0051295249958995e-32

    1. Initial program 5.1

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
    2. Using strategy rm
    3. Applied fma-neg5.1

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

      \[\leadsto \mathsf{fma}\left(x, 2, \color{blue}{\left(-9 \cdot y\right) \cdot \left(z \cdot t\right)}\right) + \left(a \cdot 27\right) \cdot b\]
    5. Taylor expanded around inf 4.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)}\]
    6. Simplified1.2

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

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

Reproduce

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