Average Error: 3.7 → 0.9
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}\;y \cdot 9 \le -7.76493181041917186 \cdot 10^{-70} \lor \neg \left(y \cdot 9 \le 2.4095214353876484 \cdot 10^{42}\right):\\ \;\;\;\;\left(x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \cdot t\right)\right) + \left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, -\left(t \cdot y\right) \cdot \left(9 \cdot z\right)\right) + \mathsf{fma}\left(27, a \cdot b, \left(y \cdot \left(9 \cdot z\right)\right) \cdot \left(\left(-t\right) + t\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}\;y \cdot 9 \le -7.76493181041917186 \cdot 10^{-70} \lor \neg \left(y \cdot 9 \le 2.4095214353876484 \cdot 10^{42}\right):\\
\;\;\;\;\left(x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \cdot t\right)\right) + \left(a \cdot 27\right) \cdot b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r751254 = x;
        double r751255 = 2.0;
        double r751256 = r751254 * r751255;
        double r751257 = y;
        double r751258 = 9.0;
        double r751259 = r751257 * r751258;
        double r751260 = z;
        double r751261 = r751259 * r751260;
        double r751262 = t;
        double r751263 = r751261 * r751262;
        double r751264 = r751256 - r751263;
        double r751265 = a;
        double r751266 = 27.0;
        double r751267 = r751265 * r751266;
        double r751268 = b;
        double r751269 = r751267 * r751268;
        double r751270 = r751264 + r751269;
        return r751270;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r751271 = y;
        double r751272 = 9.0;
        double r751273 = r751271 * r751272;
        double r751274 = -7.764931810419172e-70;
        bool r751275 = r751273 <= r751274;
        double r751276 = 2.4095214353876484e+42;
        bool r751277 = r751273 <= r751276;
        double r751278 = !r751277;
        bool r751279 = r751275 || r751278;
        double r751280 = x;
        double r751281 = 2.0;
        double r751282 = r751280 * r751281;
        double r751283 = z;
        double r751284 = r751272 * r751283;
        double r751285 = t;
        double r751286 = r751284 * r751285;
        double r751287 = r751271 * r751286;
        double r751288 = r751282 - r751287;
        double r751289 = a;
        double r751290 = 27.0;
        double r751291 = r751289 * r751290;
        double r751292 = b;
        double r751293 = r751291 * r751292;
        double r751294 = r751288 + r751293;
        double r751295 = r751285 * r751271;
        double r751296 = r751295 * r751284;
        double r751297 = -r751296;
        double r751298 = fma(r751280, r751281, r751297);
        double r751299 = r751289 * r751292;
        double r751300 = r751271 * r751284;
        double r751301 = -r751285;
        double r751302 = r751301 + r751285;
        double r751303 = r751300 * r751302;
        double r751304 = fma(r751290, r751299, r751303);
        double r751305 = r751298 + r751304;
        double r751306 = r751279 ? r751294 : r751305;
        return r751306;
}

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.5
Herbie0.9
\[\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) < -7.764931810419172e-70 or 2.4095214353876484e+42 < (* y 9.0)

    1. Initial program 7.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. Using strategy rm
    3. Applied associate-*l*7.3

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

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

    if -7.764931810419172e-70 < (* y 9.0) < 2.4095214353876484e+42

    1. Initial program 0.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. Using strategy rm
    3. Applied associate-*l*0.7

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(y \cdot \left(9 \cdot z\right)\right)} \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
    4. Using strategy rm
    5. Applied prod-diff0.7

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

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

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

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

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

Reproduce

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