Average Error: 34.2 → 10.1
Time: 4.7s
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 -5.2389466313579672 \cdot 10^{127}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le 1.6670468245058271 \cdot 10^{-85}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]
\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 -5.2389466313579672 \cdot 10^{127}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r99767 = b;
        double r99768 = -r99767;
        double r99769 = r99767 * r99767;
        double r99770 = 3.0;
        double r99771 = a;
        double r99772 = r99770 * r99771;
        double r99773 = c;
        double r99774 = r99772 * r99773;
        double r99775 = r99769 - r99774;
        double r99776 = sqrt(r99775);
        double r99777 = r99768 + r99776;
        double r99778 = r99777 / r99772;
        return r99778;
}

double f(double a, double b, double c) {
        double r99779 = b;
        double r99780 = -5.238946631357967e+127;
        bool r99781 = r99779 <= r99780;
        double r99782 = 0.5;
        double r99783 = c;
        double r99784 = r99783 / r99779;
        double r99785 = r99782 * r99784;
        double r99786 = 0.6666666666666666;
        double r99787 = a;
        double r99788 = r99779 / r99787;
        double r99789 = r99786 * r99788;
        double r99790 = r99785 - r99789;
        double r99791 = 1.667046824505827e-85;
        bool r99792 = r99779 <= r99791;
        double r99793 = r99779 * r99779;
        double r99794 = 3.0;
        double r99795 = r99794 * r99787;
        double r99796 = r99795 * r99783;
        double r99797 = r99793 - r99796;
        double r99798 = sqrt(r99797);
        double r99799 = r99798 - r99779;
        double r99800 = r99799 / r99795;
        double r99801 = -0.5;
        double r99802 = r99801 * r99784;
        double r99803 = r99792 ? r99800 : r99802;
        double r99804 = r99781 ? r99790 : r99803;
        return r99804;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -5.238946631357967e+127

    1. Initial program 54.3

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}}\]

    if -5.238946631357967e+127 < b < 1.667046824505827e-85

    1. Initial program 12.3

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}\]
    4. Applied times-frac12.4

      \[\leadsto \color{blue}{\frac{1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{a}}\]
    5. Using strategy rm
    6. Applied frac-times12.3

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

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

    if 1.667046824505827e-85 < b

    1. Initial program 52.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.2389466313579672 \cdot 10^{127}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.66666666666666663 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le 1.6670468245058271 \cdot 10^{-85}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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