Average Error: 34.3 → 9.6
Time: 18.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 -2.303779241097880191978502132703296326983 \cdot 10^{138}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666296592325124947819858789 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le 4.626043257219637986942022736183111936335 \cdot 10^{-62}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{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 -2.303779241097880191978502132703296326983 \cdot 10^{138}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666296592325124947819858789 \cdot \frac{b}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r6138366 = b;
        double r6138367 = -r6138366;
        double r6138368 = r6138366 * r6138366;
        double r6138369 = 3.0;
        double r6138370 = a;
        double r6138371 = r6138369 * r6138370;
        double r6138372 = c;
        double r6138373 = r6138371 * r6138372;
        double r6138374 = r6138368 - r6138373;
        double r6138375 = sqrt(r6138374);
        double r6138376 = r6138367 + r6138375;
        double r6138377 = r6138376 / r6138371;
        return r6138377;
}

double f(double a, double b, double c) {
        double r6138378 = b;
        double r6138379 = -2.3037792410978802e+138;
        bool r6138380 = r6138378 <= r6138379;
        double r6138381 = 0.5;
        double r6138382 = c;
        double r6138383 = r6138382 / r6138378;
        double r6138384 = r6138381 * r6138383;
        double r6138385 = 0.6666666666666666;
        double r6138386 = a;
        double r6138387 = r6138378 / r6138386;
        double r6138388 = r6138385 * r6138387;
        double r6138389 = r6138384 - r6138388;
        double r6138390 = 4.626043257219638e-62;
        bool r6138391 = r6138378 <= r6138390;
        double r6138392 = r6138378 * r6138378;
        double r6138393 = 3.0;
        double r6138394 = r6138393 * r6138386;
        double r6138395 = r6138394 * r6138382;
        double r6138396 = r6138392 - r6138395;
        double r6138397 = sqrt(r6138396);
        double r6138398 = r6138397 - r6138378;
        double r6138399 = 1.0;
        double r6138400 = r6138399 / r6138394;
        double r6138401 = r6138398 * r6138400;
        double r6138402 = -0.5;
        double r6138403 = r6138402 * r6138383;
        double r6138404 = r6138391 ? r6138401 : r6138403;
        double r6138405 = r6138380 ? r6138389 : r6138404;
        return r6138405;
}

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 < -2.3037792410978802e+138

    1. Initial program 58.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified58.5

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

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

    if -2.3037792410978802e+138 < b < 4.626043257219638e-62

    1. Initial program 12.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified12.3

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv12.4

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

    if 4.626043257219638e-62 < b

    1. Initial program 53.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified53.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.303779241097880191978502132703296326983 \cdot 10^{138}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666296592325124947819858789 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le 4.626043257219637986942022736183111936335 \cdot 10^{-62}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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