Average Error: 3.8 → 0.6
Time: 38.4s
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 -2286477246243585503889719296:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - \left(t \cdot \left(y \cdot z\right)\right) \cdot 9\right)\\ \mathbf{elif}\;t \le 5.805755414873109712954710355525822507161 \cdot 10^{-8}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - \left(t \cdot \left(y \cdot z\right)\right) \cdot 9\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 -2286477246243585503889719296:\\
\;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - \left(t \cdot \left(y \cdot z\right)\right) \cdot 9\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r33115560 = x;
        double r33115561 = 2.0;
        double r33115562 = r33115560 * r33115561;
        double r33115563 = y;
        double r33115564 = 9.0;
        double r33115565 = r33115563 * r33115564;
        double r33115566 = z;
        double r33115567 = r33115565 * r33115566;
        double r33115568 = t;
        double r33115569 = r33115567 * r33115568;
        double r33115570 = r33115562 - r33115569;
        double r33115571 = a;
        double r33115572 = 27.0;
        double r33115573 = r33115571 * r33115572;
        double r33115574 = b;
        double r33115575 = r33115573 * r33115574;
        double r33115576 = r33115570 + r33115575;
        return r33115576;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r33115577 = t;
        double r33115578 = -2.2864772462435855e+27;
        bool r33115579 = r33115577 <= r33115578;
        double r33115580 = 2.0;
        double r33115581 = x;
        double r33115582 = 27.0;
        double r33115583 = a;
        double r33115584 = b;
        double r33115585 = r33115583 * r33115584;
        double r33115586 = r33115582 * r33115585;
        double r33115587 = y;
        double r33115588 = z;
        double r33115589 = r33115587 * r33115588;
        double r33115590 = r33115577 * r33115589;
        double r33115591 = 9.0;
        double r33115592 = r33115590 * r33115591;
        double r33115593 = r33115586 - r33115592;
        double r33115594 = fma(r33115580, r33115581, r33115593);
        double r33115595 = 5.80575541487311e-08;
        bool r33115596 = r33115577 <= r33115595;
        double r33115597 = r33115581 * r33115580;
        double r33115598 = r33115591 * r33115588;
        double r33115599 = r33115598 * r33115577;
        double r33115600 = r33115587 * r33115599;
        double r33115601 = r33115597 - r33115600;
        double r33115602 = fma(r33115582, r33115585, r33115601);
        double r33115603 = r33115596 ? r33115602 : r33115594;
        double r33115604 = r33115579 ? r33115594 : r33115603;
        return r33115604;
}

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.8
Target2.8
Herbie0.6
\[\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 < -2.2864772462435855e+27 or 5.80575541487311e-08 < t

    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. Simplified7.9

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

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

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

      \[\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)}\]
    8. Simplified0.6

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

    if -2.2864772462435855e+27 < t < 5.80575541487311e-08

    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. Simplified0.6

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

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

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

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

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

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

Reproduce

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