Average Error: 34.1 → 9.9
Time: 17.3s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.550162015746626746000974336574470460524 \cdot 10^{150}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.61145084478121505718169973575148582501 \cdot 10^{-34}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -1.550162015746626746000974336574470460524 \cdot 10^{150}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 1.61145084478121505718169973575148582501 \cdot 10^{-34}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\

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

\end{array}
double f(double a, double b, double c) {
        double r37378 = b;
        double r37379 = -r37378;
        double r37380 = r37378 * r37378;
        double r37381 = 4.0;
        double r37382 = a;
        double r37383 = r37381 * r37382;
        double r37384 = c;
        double r37385 = r37383 * r37384;
        double r37386 = r37380 - r37385;
        double r37387 = sqrt(r37386);
        double r37388 = r37379 + r37387;
        double r37389 = 2.0;
        double r37390 = r37389 * r37382;
        double r37391 = r37388 / r37390;
        return r37391;
}

double f(double a, double b, double c) {
        double r37392 = b;
        double r37393 = -1.5501620157466267e+150;
        bool r37394 = r37392 <= r37393;
        double r37395 = 1.0;
        double r37396 = c;
        double r37397 = r37396 / r37392;
        double r37398 = a;
        double r37399 = r37392 / r37398;
        double r37400 = r37397 - r37399;
        double r37401 = r37395 * r37400;
        double r37402 = 1.611450844781215e-34;
        bool r37403 = r37392 <= r37402;
        double r37404 = 1.0;
        double r37405 = 2.0;
        double r37406 = r37405 * r37398;
        double r37407 = r37392 * r37392;
        double r37408 = 4.0;
        double r37409 = r37408 * r37398;
        double r37410 = r37409 * r37396;
        double r37411 = r37407 - r37410;
        double r37412 = sqrt(r37411);
        double r37413 = r37412 - r37392;
        double r37414 = r37406 / r37413;
        double r37415 = r37404 / r37414;
        double r37416 = -1.0;
        double r37417 = r37416 * r37397;
        double r37418 = r37403 ? r37415 : r37417;
        double r37419 = r37394 ? r37401 : r37418;
        return r37419;
}

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 < -1.5501620157466267e+150

    1. Initial program 62.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified62.9

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    4. Simplified1.7

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

    if -1.5501620157466267e+150 < b < 1.611450844781215e-34

    1. Initial program 13.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified13.6

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

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

    if 1.611450844781215e-34 < b

    1. Initial program 55.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified55.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.550162015746626746000974336574470460524 \cdot 10^{150}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.61145084478121505718169973575148582501 \cdot 10^{-34}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019325 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))