Average Error: 33.3 → 7.0
Time: 1.3m
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.4179764337068727 \cdot 10^{+51}:\\ \;\;\;\;\frac{(\frac{3}{2} \cdot \left(\frac{a}{\frac{b}{c}}\right) + \left(b \cdot -2\right))_*}{3 \cdot a}\\ \mathbf{elif}\;b \le -1.791459875542678 \cdot 10^{-192}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3}}{a}\\ \mathbf{elif}\;b \le 2.4712962921452696 \cdot 10^{+131}:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-1}{2}\\ \end{array}\]
double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r22488550 = b;
        double r22488551 = -r22488550;
        double r22488552 = r22488550 * r22488550;
        double r22488553 = 3.0;
        double r22488554 = a;
        double r22488555 = r22488553 * r22488554;
        double r22488556 = c;
        double r22488557 = r22488555 * r22488556;
        double r22488558 = r22488552 - r22488557;
        double r22488559 = sqrt(r22488558);
        double r22488560 = r22488551 + r22488559;
        double r22488561 = r22488560 / r22488555;
        return r22488561;
}

double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r22488562 = b;
        double r22488563 = -1.4179764337068727e+51;
        bool r22488564 = r22488562 <= r22488563;
        double r22488565 = 1.5;
        double r22488566 = a;
        double r22488567 = c;
        double r22488568 = r22488562 / r22488567;
        double r22488569 = r22488566 / r22488568;
        double r22488570 = -2.0;
        double r22488571 = r22488562 * r22488570;
        double r22488572 = fma(r22488565, r22488569, r22488571);
        double r22488573 = 3.0;
        double r22488574 = r22488573 * r22488566;
        double r22488575 = r22488572 / r22488574;
        double r22488576 = -1.791459875542678e-192;
        bool r22488577 = r22488562 <= r22488576;
        double r22488578 = r22488562 * r22488562;
        double r22488579 = r22488574 * r22488567;
        double r22488580 = r22488578 - r22488579;
        double r22488581 = sqrt(r22488580);
        double r22488582 = -r22488562;
        double r22488583 = r22488581 + r22488582;
        double r22488584 = r22488583 / r22488573;
        double r22488585 = r22488584 / r22488566;
        double r22488586 = 2.4712962921452696e+131;
        bool r22488587 = r22488562 <= r22488586;
        double r22488588 = r22488582 - r22488581;
        double r22488589 = r22488567 / r22488588;
        double r22488590 = r22488567 / r22488562;
        double r22488591 = -0.5;
        double r22488592 = r22488590 * r22488591;
        double r22488593 = r22488587 ? r22488589 : r22488592;
        double r22488594 = r22488577 ? r22488585 : r22488593;
        double r22488595 = r22488564 ? r22488575 : r22488594;
        return r22488595;
}

\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -1.4179764337068727 \cdot 10^{+51}:\\
\;\;\;\;\frac{(\frac{3}{2} \cdot \left(\frac{a}{\frac{b}{c}}\right) + \left(b \cdot -2\right))_*}{3 \cdot a}\\

\mathbf{elif}\;b \le -1.791459875542678 \cdot 10^{-192}:\\
\;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3}}{a}\\

\mathbf{elif}\;b \le 2.4712962921452696 \cdot 10^{+131}:\\
\;\;\;\;\frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-1}{2}\\

\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Derivation

  1. Split input into 4 regimes
  2. if b < -1.4179764337068727e+51

    1. Initial program 37.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Taylor expanded around -inf 10.6

      \[\leadsto \frac{\color{blue}{\frac{3}{2} \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{3 \cdot a}\]
    3. Simplified6.1

      \[\leadsto \frac{\color{blue}{(\frac{3}{2} \cdot \left(\frac{a}{\frac{b}{c}}\right) + \left(-2 \cdot b\right))_*}}{3 \cdot a}\]

    if -1.4179764337068727e+51 < b < -1.791459875542678e-192

    1. Initial program 7.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-/r*7.9

      \[\leadsto \color{blue}{\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3}}{a}}\]

    if -1.791459875542678e-192 < b < 2.4712962921452696e+131

    1. Initial program 29.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+30.1

      \[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}\]
    4. Applied associate-/l/34.7

      \[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\left(3 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}\]
    5. Simplified20.1

      \[\leadsto \frac{\color{blue}{3 \cdot \left(c \cdot a\right)}}{\left(3 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}\]
    6. Using strategy rm
    7. Applied associate-/r*14.5

      \[\leadsto \color{blue}{\frac{\frac{3 \cdot \left(c \cdot a\right)}{3 \cdot a}}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}\]
    8. Taylor expanded around -inf 9.4

      \[\leadsto \frac{\color{blue}{c}}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\]

    if 2.4712962921452696e+131 < b

    1. Initial program 60.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Taylor expanded around inf 1.8

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.4179764337068727 \cdot 10^{+51}:\\ \;\;\;\;\frac{(\frac{3}{2} \cdot \left(\frac{a}{\frac{b}{c}}\right) + \left(b \cdot -2\right))_*}{3 \cdot a}\\ \mathbf{elif}\;b \le -1.791459875542678 \cdot 10^{-192}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3}}{a}\\ \mathbf{elif}\;b \le 2.4712962921452696 \cdot 10^{+131}:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-1}{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019101 +o rules:numerics
(FPCore (a b c d)
  :name "Cubic critical"
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3 a) c)))) (* 3 a)))