Average Error: 34.2 → 10.1
Time: 4.6s
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 r120415 = b;
        double r120416 = -r120415;
        double r120417 = r120415 * r120415;
        double r120418 = 3.0;
        double r120419 = a;
        double r120420 = r120418 * r120419;
        double r120421 = c;
        double r120422 = r120420 * r120421;
        double r120423 = r120417 - r120422;
        double r120424 = sqrt(r120423);
        double r120425 = r120416 + r120424;
        double r120426 = r120425 / r120420;
        return r120426;
}

double f(double a, double b, double c) {
        double r120427 = b;
        double r120428 = -5.238946631357967e+127;
        bool r120429 = r120427 <= r120428;
        double r120430 = 0.5;
        double r120431 = c;
        double r120432 = r120431 / r120427;
        double r120433 = r120430 * r120432;
        double r120434 = 0.6666666666666666;
        double r120435 = a;
        double r120436 = r120427 / r120435;
        double r120437 = r120434 * r120436;
        double r120438 = r120433 - r120437;
        double r120439 = 1.667046824505827e-85;
        bool r120440 = r120427 <= r120439;
        double r120441 = r120427 * r120427;
        double r120442 = 3.0;
        double r120443 = r120442 * r120435;
        double r120444 = r120443 * r120431;
        double r120445 = r120441 - r120444;
        double r120446 = sqrt(r120445);
        double r120447 = r120446 - r120427;
        double r120448 = r120447 / r120443;
        double r120449 = -0.5;
        double r120450 = r120449 * r120432;
        double r120451 = r120440 ? r120448 : r120450;
        double r120452 = r120429 ? r120438 : r120451;
        return r120452;
}

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)))