Average Error: 3.6 → 2.3
Time: 16.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 4.168917714154861757771572877486206993919 \cdot 10^{-90}:\\ \;\;\;\;\mathsf{fma}\left(t \cdot \left(z \cdot y\right), -9, 2 \cdot x\right) + \left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(t \cdot z\right)\right) + a \cdot \left(27 \cdot b\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 4.168917714154861757771572877486206993919 \cdot 10^{-90}:\\
\;\;\;\;\mathsf{fma}\left(t \cdot \left(z \cdot y\right), -9, 2 \cdot x\right) + \left(a \cdot 27\right) \cdot b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r427341 = x;
        double r427342 = 2.0;
        double r427343 = r427341 * r427342;
        double r427344 = y;
        double r427345 = 9.0;
        double r427346 = r427344 * r427345;
        double r427347 = z;
        double r427348 = r427346 * r427347;
        double r427349 = t;
        double r427350 = r427348 * r427349;
        double r427351 = r427343 - r427350;
        double r427352 = a;
        double r427353 = 27.0;
        double r427354 = r427352 * r427353;
        double r427355 = b;
        double r427356 = r427354 * r427355;
        double r427357 = r427351 + r427356;
        return r427357;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r427358 = y;
        double r427359 = 9.0;
        double r427360 = r427358 * r427359;
        double r427361 = 4.168917714154862e-90;
        bool r427362 = r427360 <= r427361;
        double r427363 = t;
        double r427364 = z;
        double r427365 = r427364 * r427358;
        double r427366 = r427363 * r427365;
        double r427367 = -r427359;
        double r427368 = 2.0;
        double r427369 = x;
        double r427370 = r427368 * r427369;
        double r427371 = fma(r427366, r427367, r427370);
        double r427372 = a;
        double r427373 = 27.0;
        double r427374 = r427372 * r427373;
        double r427375 = b;
        double r427376 = r427374 * r427375;
        double r427377 = r427371 + r427376;
        double r427378 = r427369 * r427368;
        double r427379 = r427363 * r427364;
        double r427380 = r427360 * r427379;
        double r427381 = r427378 - r427380;
        double r427382 = r427373 * r427375;
        double r427383 = r427372 * r427382;
        double r427384 = r427381 + r427383;
        double r427385 = r427362 ? r427377 : r427384;
        return r427385;
}

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.6
Herbie2.3
\[\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) < 4.168917714154862e-90

    1. Initial program 2.7

      \[\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*4.3

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

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

      \[\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\]
    6. Simplified2.6

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

    if 4.168917714154862e-90 < (* y 9.0)

    1. Initial program 5.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 associate-*l*1.4

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

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

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

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

Reproduce

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