Average Error: 7.7 → 4.4
Time: 20.0s
Precision: 64
\[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot y \le -1.458727220089207535864960016002575750906 \cdot 10^{52} \lor \neg \left(x \cdot y \le 1.229286322194980864816099603400694281875 \cdot 10^{194}\right):\\ \;\;\;\;\mathsf{fma}\left(4.5, \frac{-t}{\frac{a}{z}}, y \cdot \frac{0.5 \cdot x}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, z \cdot \left(-9\right), x \cdot y\right)}{2 \cdot a}\\ \end{array}\]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
\mathbf{if}\;x \cdot y \le -1.458727220089207535864960016002575750906 \cdot 10^{52} \lor \neg \left(x \cdot y \le 1.229286322194980864816099603400694281875 \cdot 10^{194}\right):\\
\;\;\;\;\mathsf{fma}\left(4.5, \frac{-t}{\frac{a}{z}}, y \cdot \frac{0.5 \cdot x}{a}\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r608716 = x;
        double r608717 = y;
        double r608718 = r608716 * r608717;
        double r608719 = z;
        double r608720 = 9.0;
        double r608721 = r608719 * r608720;
        double r608722 = t;
        double r608723 = r608721 * r608722;
        double r608724 = r608718 - r608723;
        double r608725 = a;
        double r608726 = 2.0;
        double r608727 = r608725 * r608726;
        double r608728 = r608724 / r608727;
        return r608728;
}

double f(double x, double y, double z, double t, double a) {
        double r608729 = x;
        double r608730 = y;
        double r608731 = r608729 * r608730;
        double r608732 = -1.4587272200892075e+52;
        bool r608733 = r608731 <= r608732;
        double r608734 = 1.2292863221949809e+194;
        bool r608735 = r608731 <= r608734;
        double r608736 = !r608735;
        bool r608737 = r608733 || r608736;
        double r608738 = 4.5;
        double r608739 = t;
        double r608740 = -r608739;
        double r608741 = a;
        double r608742 = z;
        double r608743 = r608741 / r608742;
        double r608744 = r608740 / r608743;
        double r608745 = 0.5;
        double r608746 = r608745 * r608729;
        double r608747 = r608746 / r608741;
        double r608748 = r608730 * r608747;
        double r608749 = fma(r608738, r608744, r608748);
        double r608750 = 9.0;
        double r608751 = -r608750;
        double r608752 = r608742 * r608751;
        double r608753 = fma(r608739, r608752, r608731);
        double r608754 = 2.0;
        double r608755 = r608754 * r608741;
        double r608756 = r608753 / r608755;
        double r608757 = r608737 ? r608749 : r608756;
        return r608757;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original7.7
Target5.4
Herbie4.4
\[\begin{array}{l} \mathbf{if}\;a \lt -2.090464557976709043451944897028999329376 \cdot 10^{86}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;a \lt 2.144030707833976090627817222818061808815 \cdot 10^{99}:\\ \;\;\;\;\frac{x \cdot y - z \cdot \left(9 \cdot t\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} \cdot \left(x \cdot 0.5\right) - \frac{t}{a} \cdot \left(z \cdot 4.5\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (* x y) < -1.4587272200892075e+52 or 1.2292863221949809e+194 < (* x y)

    1. Initial program 19.0

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\]
    2. Simplified19.0

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{a} - 4.5 \cdot \frac{t \cdot z}{a}}\]
    4. Simplified19.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(4.5, -\frac{t \cdot z}{a}, \frac{0.5}{a} \cdot \left(x \cdot y\right)\right)}\]
    5. Using strategy rm
    6. Applied associate-*r*8.7

      \[\leadsto \mathsf{fma}\left(4.5, -\frac{t \cdot z}{a}, \color{blue}{\left(\frac{0.5}{a} \cdot x\right) \cdot y}\right)\]
    7. Simplified8.6

      \[\leadsto \mathsf{fma}\left(4.5, -\frac{t \cdot z}{a}, \color{blue}{\frac{x \cdot 0.5}{a}} \cdot y\right)\]
    8. Using strategy rm
    9. Applied associate-/l*4.1

      \[\leadsto \mathsf{fma}\left(4.5, -\color{blue}{\frac{t}{\frac{a}{z}}}, \frac{x \cdot 0.5}{a} \cdot y\right)\]

    if -1.4587272200892075e+52 < (* x y) < 1.2292863221949809e+194

    1. Initial program 4.5

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\]
    2. Simplified4.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \le -1.458727220089207535864960016002575750906 \cdot 10^{52} \lor \neg \left(x \cdot y \le 1.229286322194980864816099603400694281875 \cdot 10^{194}\right):\\ \;\;\;\;\mathsf{fma}\left(4.5, \frac{-t}{\frac{a}{z}}, y \cdot \frac{0.5 \cdot x}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, z \cdot \left(-9\right), x \cdot y\right)}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019194 +o rules:numerics
(FPCore (x y z t a)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, I"

  :herbie-target
  (if (< a -2.090464557976709e+86) (- (* 0.5 (/ (* y x) a)) (* 4.5 (/ t (/ a z)))) (if (< a 2.144030707833976e+99) (/ (- (* x y) (* z (* 9.0 t))) (* a 2.0)) (- (* (/ y a) (* x 0.5)) (* (/ t a) (* z 4.5)))))

  (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))