Average Error: 33.3 → 8.6
Time: 25.2s
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 -4.82289647433212 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.1232170674377175 \cdot 10^{-242}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.3233344071163898 \cdot 10^{+19}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\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 -4.82289647433212 \cdot 10^{+153}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \le 3.1232170674377175 \cdot 10^{-242}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\

\mathbf{elif}\;b \le 1.3233344071163898 \cdot 10^{+19}:\\
\;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{a \cdot 2}\\

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

\end{array}
double f(double a, double b, double c) {
        double r2985383 = b;
        double r2985384 = -r2985383;
        double r2985385 = r2985383 * r2985383;
        double r2985386 = 4.0;
        double r2985387 = a;
        double r2985388 = r2985386 * r2985387;
        double r2985389 = c;
        double r2985390 = r2985388 * r2985389;
        double r2985391 = r2985385 - r2985390;
        double r2985392 = sqrt(r2985391);
        double r2985393 = r2985384 + r2985392;
        double r2985394 = 2.0;
        double r2985395 = r2985394 * r2985387;
        double r2985396 = r2985393 / r2985395;
        return r2985396;
}

double f(double a, double b, double c) {
        double r2985397 = b;
        double r2985398 = -4.82289647433212e+153;
        bool r2985399 = r2985397 <= r2985398;
        double r2985400 = c;
        double r2985401 = r2985400 / r2985397;
        double r2985402 = a;
        double r2985403 = r2985397 / r2985402;
        double r2985404 = r2985401 - r2985403;
        double r2985405 = 3.1232170674377175e-242;
        bool r2985406 = r2985397 <= r2985405;
        double r2985407 = -r2985397;
        double r2985408 = r2985397 * r2985397;
        double r2985409 = 4.0;
        double r2985410 = r2985409 * r2985402;
        double r2985411 = r2985400 * r2985410;
        double r2985412 = r2985408 - r2985411;
        double r2985413 = sqrt(r2985412);
        double r2985414 = r2985407 + r2985413;
        double r2985415 = 2.0;
        double r2985416 = r2985402 * r2985415;
        double r2985417 = r2985414 / r2985416;
        double r2985418 = 1.3233344071163898e+19;
        bool r2985419 = r2985397 <= r2985418;
        double r2985420 = r2985408 - r2985408;
        double r2985421 = r2985420 + r2985411;
        double r2985422 = r2985407 - r2985413;
        double r2985423 = r2985421 / r2985422;
        double r2985424 = r2985423 / r2985416;
        double r2985425 = -r2985401;
        double r2985426 = r2985419 ? r2985424 : r2985425;
        double r2985427 = r2985406 ? r2985417 : r2985426;
        double r2985428 = r2985399 ? r2985404 : r2985427;
        return r2985428;
}

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

Target

Original33.3
Target20.7
Herbie8.6
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -4.82289647433212e+153

    1. Initial program 60.9

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}\]
    4. Applied associate-/l*60.9

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{\frac{\sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} - b}{a}}}}\]
    6. Using strategy rm
    7. Applied associate-/r/60.9

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

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

    if -4.82289647433212e+153 < b < 3.1232170674377175e-242

    1. Initial program 9.2

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

    if 3.1232170674377175e-242 < b < 1.3233344071163898e+19

    1. Initial program 28.7

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

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

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

    if 1.3233344071163898e+19 < b

    1. Initial program 55.3

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    3. Simplified4.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.82289647433212 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.1232170674377175 \cdot 10^{-242}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.3233344071163898 \cdot 10^{+19}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019142 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))