Average Error: 3.6 → 0.5
Time: 17.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}\;\left(y \cdot 9\right) \cdot z \le -1.308164313000467543776094765292299835855 \cdot 10^{187}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - 9 \cdot \left(\left(t \cdot z\right) \cdot y\right)\right)\\ \mathbf{elif}\;\left(y \cdot 9\right) \cdot z \le 1.769243710646989305256732586899326981103 \cdot 10^{270}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(t \cdot z\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 -1.308164313000467543776094765292299835855 \cdot 10^{187}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - 9 \cdot \left(\left(t \cdot z\right) \cdot y\right)\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r501181 = x;
        double r501182 = 2.0;
        double r501183 = r501181 * r501182;
        double r501184 = y;
        double r501185 = 9.0;
        double r501186 = r501184 * r501185;
        double r501187 = z;
        double r501188 = r501186 * r501187;
        double r501189 = t;
        double r501190 = r501188 * r501189;
        double r501191 = r501183 - r501190;
        double r501192 = a;
        double r501193 = 27.0;
        double r501194 = r501192 * r501193;
        double r501195 = b;
        double r501196 = r501194 * r501195;
        double r501197 = r501191 + r501196;
        return r501197;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r501198 = y;
        double r501199 = 9.0;
        double r501200 = r501198 * r501199;
        double r501201 = z;
        double r501202 = r501200 * r501201;
        double r501203 = -1.3081643130004675e+187;
        bool r501204 = r501202 <= r501203;
        double r501205 = a;
        double r501206 = 27.0;
        double r501207 = r501205 * r501206;
        double r501208 = b;
        double r501209 = x;
        double r501210 = 2.0;
        double r501211 = r501209 * r501210;
        double r501212 = t;
        double r501213 = r501212 * r501201;
        double r501214 = r501213 * r501198;
        double r501215 = r501199 * r501214;
        double r501216 = r501211 - r501215;
        double r501217 = fma(r501207, r501208, r501216);
        double r501218 = 1.7692437106469893e+270;
        bool r501219 = r501202 <= r501218;
        double r501220 = r501201 * r501198;
        double r501221 = r501212 * r501220;
        double r501222 = r501199 * r501221;
        double r501223 = r501211 - r501222;
        double r501224 = fma(r501207, r501208, r501223);
        double r501225 = r501205 * r501208;
        double r501226 = r501206 * r501225;
        double r501227 = r501200 * r501213;
        double r501228 = r501211 - r501227;
        double r501229 = r501226 + r501228;
        double r501230 = r501219 ? r501224 : r501229;
        double r501231 = r501204 ? r501217 : r501230;
        return r501231;
}

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.6
Target2.7
Herbie0.5
\[\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 3 regimes
  2. if (* (* y 9.0) z) < -1.3081643130004675e+187

    1. Initial program 22.5

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

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

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

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

    if -1.3081643130004675e+187 < (* (* y 9.0) z) < 1.7692437106469893e+270

    1. Initial program 0.5

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

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

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

    if 1.7692437106469893e+270 < (* (* y 9.0) z)

    1. Initial program 46.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. Simplified46.6

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

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

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

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

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

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

Reproduce

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