Average Error: 4.0 → 1.3
Time: 27.9s
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.434616547682554976717028694110922515392:\\ \;\;\;\;\mathsf{fma}\left(x, 2, a \cdot \left(27 \cdot b\right)\right) - \left(\left(t \cdot z\right) \cdot y\right) \cdot 9\\ \mathbf{elif}\;y \cdot 9 \le 1.511751713308080890358784734622859626508 \cdot 10^{-215}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2\right) - z \cdot \left(\left(y \cdot 9\right) \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, a \cdot \left(27 \cdot b\right)\right) - \left(\left(t \cdot z\right) \cdot y\right) \cdot 9\\ \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.434616547682554976717028694110922515392:\\
\;\;\;\;\mathsf{fma}\left(x, 2, a \cdot \left(27 \cdot b\right)\right) - \left(\left(t \cdot z\right) \cdot y\right) \cdot 9\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r31138353 = x;
        double r31138354 = 2.0;
        double r31138355 = r31138353 * r31138354;
        double r31138356 = y;
        double r31138357 = 9.0;
        double r31138358 = r31138356 * r31138357;
        double r31138359 = z;
        double r31138360 = r31138358 * r31138359;
        double r31138361 = t;
        double r31138362 = r31138360 * r31138361;
        double r31138363 = r31138355 - r31138362;
        double r31138364 = a;
        double r31138365 = 27.0;
        double r31138366 = r31138364 * r31138365;
        double r31138367 = b;
        double r31138368 = r31138366 * r31138367;
        double r31138369 = r31138363 + r31138368;
        return r31138369;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r31138370 = y;
        double r31138371 = 9.0;
        double r31138372 = r31138370 * r31138371;
        double r31138373 = -2.434616547682555;
        bool r31138374 = r31138372 <= r31138373;
        double r31138375 = x;
        double r31138376 = 2.0;
        double r31138377 = a;
        double r31138378 = 27.0;
        double r31138379 = b;
        double r31138380 = r31138378 * r31138379;
        double r31138381 = r31138377 * r31138380;
        double r31138382 = fma(r31138375, r31138376, r31138381);
        double r31138383 = t;
        double r31138384 = z;
        double r31138385 = r31138383 * r31138384;
        double r31138386 = r31138385 * r31138370;
        double r31138387 = r31138386 * r31138371;
        double r31138388 = r31138382 - r31138387;
        double r31138389 = 1.511751713308081e-215;
        bool r31138390 = r31138372 <= r31138389;
        double r31138391 = r31138377 * r31138379;
        double r31138392 = r31138375 * r31138376;
        double r31138393 = fma(r31138378, r31138391, r31138392);
        double r31138394 = r31138372 * r31138383;
        double r31138395 = r31138384 * r31138394;
        double r31138396 = r31138393 - r31138395;
        double r31138397 = r31138390 ? r31138396 : r31138388;
        double r31138398 = r31138374 ? r31138388 : r31138397;
        return r31138398;
}

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
Herbie1.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) < -2.434616547682555 or 1.511751713308081e-215 < (* y 9.0)

    1. Initial program 6.0

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

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

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

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

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

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

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

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

    if -2.434616547682555 < (* y 9.0) < 1.511751713308081e-215

    1. Initial program 0.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. Simplified0.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot 9 \le -2.434616547682554976717028694110922515392:\\ \;\;\;\;\mathsf{fma}\left(x, 2, a \cdot \left(27 \cdot b\right)\right) - \left(\left(t \cdot z\right) \cdot y\right) \cdot 9\\ \mathbf{elif}\;y \cdot 9 \le 1.511751713308080890358784734622859626508 \cdot 10^{-215}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2\right) - z \cdot \left(\left(y \cdot 9\right) \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, a \cdot \left(27 \cdot b\right)\right) - \left(\left(t \cdot z\right) \cdot y\right) \cdot 9\\ \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)))