Average Error: 20.2 → 7.3
Time: 29.3s
Precision: 64
\[\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.0374603215218364316667016635065438611 \cdot 10^{-79}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{z}, y \cdot 9, \frac{b}{z} - a \cdot \left(4 \cdot t\right)\right)}{c}\\ \mathbf{elif}\;z \le 9.378696137572198364826430485554169585975 \cdot 10^{-117}:\\ \;\;\;\;\frac{b + \left(y \cdot \left(x \cdot 9\right) - \left(t \cdot \left(4 \cdot z\right)\right) \cdot a\right)}{z \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{z}, y \cdot 9, \frac{b}{z} - a \cdot \left(4 \cdot t\right)\right)}{c}\\ \end{array}\]
\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\begin{array}{l}
\mathbf{if}\;z \le -2.0374603215218364316667016635065438611 \cdot 10^{-79}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{z}, y \cdot 9, \frac{b}{z} - a \cdot \left(4 \cdot t\right)\right)}{c}\\

\mathbf{elif}\;z \le 9.378696137572198364826430485554169585975 \cdot 10^{-117}:\\
\;\;\;\;\frac{b + \left(y \cdot \left(x \cdot 9\right) - \left(t \cdot \left(4 \cdot z\right)\right) \cdot a\right)}{z \cdot c}\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b, double c) {
        double r32005572 = x;
        double r32005573 = 9.0;
        double r32005574 = r32005572 * r32005573;
        double r32005575 = y;
        double r32005576 = r32005574 * r32005575;
        double r32005577 = z;
        double r32005578 = 4.0;
        double r32005579 = r32005577 * r32005578;
        double r32005580 = t;
        double r32005581 = r32005579 * r32005580;
        double r32005582 = a;
        double r32005583 = r32005581 * r32005582;
        double r32005584 = r32005576 - r32005583;
        double r32005585 = b;
        double r32005586 = r32005584 + r32005585;
        double r32005587 = c;
        double r32005588 = r32005577 * r32005587;
        double r32005589 = r32005586 / r32005588;
        return r32005589;
}

double f(double x, double y, double z, double t, double a, double b, double c) {
        double r32005590 = z;
        double r32005591 = -2.0374603215218364e-79;
        bool r32005592 = r32005590 <= r32005591;
        double r32005593 = x;
        double r32005594 = r32005593 / r32005590;
        double r32005595 = y;
        double r32005596 = 9.0;
        double r32005597 = r32005595 * r32005596;
        double r32005598 = b;
        double r32005599 = r32005598 / r32005590;
        double r32005600 = a;
        double r32005601 = 4.0;
        double r32005602 = t;
        double r32005603 = r32005601 * r32005602;
        double r32005604 = r32005600 * r32005603;
        double r32005605 = r32005599 - r32005604;
        double r32005606 = fma(r32005594, r32005597, r32005605);
        double r32005607 = c;
        double r32005608 = r32005606 / r32005607;
        double r32005609 = 9.378696137572198e-117;
        bool r32005610 = r32005590 <= r32005609;
        double r32005611 = r32005593 * r32005596;
        double r32005612 = r32005595 * r32005611;
        double r32005613 = r32005601 * r32005590;
        double r32005614 = r32005602 * r32005613;
        double r32005615 = r32005614 * r32005600;
        double r32005616 = r32005612 - r32005615;
        double r32005617 = r32005598 + r32005616;
        double r32005618 = r32005590 * r32005607;
        double r32005619 = r32005617 / r32005618;
        double r32005620 = r32005610 ? r32005619 : r32005608;
        double r32005621 = r32005592 ? r32005608 : r32005620;
        return r32005621;
}

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

Bits error versus c

Target

Original20.2
Target14.2
Herbie7.3
\[\begin{array}{l} \mathbf{if}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \lt -1.100156740804104887233830094663413900721 \cdot 10^{-171}:\\ \;\;\;\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(z \cdot 4\right) \cdot \left(t \cdot a\right)\right) + b}{z \cdot c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \lt -0.0:\\ \;\;\;\;\frac{\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z}}{c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \lt 1.170887791174748819600820354912645756062 \cdot 10^{-53}:\\ \;\;\;\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(z \cdot 4\right) \cdot \left(t \cdot a\right)\right) + b}{z \cdot c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \lt 2.876823679546137226963937101710277849382 \cdot 10^{130}:\\ \;\;\;\;\left(\left(9 \cdot \frac{y}{c}\right) \cdot \frac{x}{z} + \frac{b}{c \cdot z}\right) - 4 \cdot \frac{a \cdot t}{c}\\ \mathbf{elif}\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c} \lt 1.383851504245631860711731716196098366993 \cdot 10^{158}:\\ \;\;\;\;\frac{\left(\left(x \cdot 9\right) \cdot y - \left(z \cdot 4\right) \cdot \left(t \cdot a\right)\right) + b}{z \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\left(9 \cdot \left(\frac{y}{c \cdot z} \cdot x\right) + \frac{b}{c \cdot z}\right) - 4 \cdot \frac{a \cdot t}{c}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -2.0374603215218364e-79 or 9.378696137572198e-117 < z

    1. Initial program 24.3

      \[\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}\]
    2. Simplified9.6

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(y \cdot 9, x, b\right)}{z} - \left(a \cdot t\right) \cdot 4}{c}}\]
    3. Using strategy rm
    4. Applied div-inv9.6

      \[\leadsto \color{blue}{\left(\frac{\mathsf{fma}\left(y \cdot 9, x, b\right)}{z} - \left(a \cdot t\right) \cdot 4\right) \cdot \frac{1}{c}}\]
    5. Taylor expanded around 0 9.6

      \[\leadsto \left(\color{blue}{\left(9 \cdot \frac{x \cdot y}{z} + \frac{b}{z}\right)} - \left(a \cdot t\right) \cdot 4\right) \cdot \frac{1}{c}\]
    6. Simplified7.2

      \[\leadsto \left(\color{blue}{\mathsf{fma}\left(\frac{x}{\frac{z}{y}}, 9, \frac{b}{z}\right)} - \left(a \cdot t\right) \cdot 4\right) \cdot \frac{1}{c}\]
    7. Using strategy rm
    8. Applied associate-*r/7.1

      \[\leadsto \color{blue}{\frac{\left(\mathsf{fma}\left(\frac{x}{\frac{z}{y}}, 9, \frac{b}{z}\right) - \left(a \cdot t\right) \cdot 4\right) \cdot 1}{c}}\]
    9. Simplified7.6

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

    if -2.0374603215218364e-79 < z < 9.378696137572198e-117

    1. Initial program 6.4

      \[\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification7.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.0374603215218364316667016635065438611 \cdot 10^{-79}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{z}, y \cdot 9, \frac{b}{z} - a \cdot \left(4 \cdot t\right)\right)}{c}\\ \mathbf{elif}\;z \le 9.378696137572198364826430485554169585975 \cdot 10^{-117}:\\ \;\;\;\;\frac{b + \left(y \cdot \left(x \cdot 9\right) - \left(t \cdot \left(4 \cdot z\right)\right) \cdot a\right)}{z \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{z}, y \cdot 9, \frac{b}{z} - a \cdot \left(4 \cdot t\right)\right)}{c}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) -1.100156740804105e-171) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) -0.0) (/ (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) z) c) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.1708877911747488e-53) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 2.876823679546137e+130) (- (+ (* (* 9.0 (/ y c)) (/ x z)) (/ b (* c z))) (* 4.0 (/ (* a t) c))) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.3838515042456319e+158) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (- (+ (* 9.0 (* (/ y (* c z)) x)) (/ b (* c z))) (* 4.0 (/ (* a t) c))))))))

  (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))