Average Error: 34.2 → 9.5
Time: 21.5s
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 -3.710887557865060611891812934492943223731 \cdot 10^{138}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 4.626043257219637986942022736183111936335 \cdot 10^{-62}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{a \cdot 2}\\ \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 -3.710887557865060611891812934492943223731 \cdot 10^{138}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r4061433 = b;
        double r4061434 = -r4061433;
        double r4061435 = r4061433 * r4061433;
        double r4061436 = 4.0;
        double r4061437 = a;
        double r4061438 = r4061436 * r4061437;
        double r4061439 = c;
        double r4061440 = r4061438 * r4061439;
        double r4061441 = r4061435 - r4061440;
        double r4061442 = sqrt(r4061441);
        double r4061443 = r4061434 + r4061442;
        double r4061444 = 2.0;
        double r4061445 = r4061444 * r4061437;
        double r4061446 = r4061443 / r4061445;
        return r4061446;
}

double f(double a, double b, double c) {
        double r4061447 = b;
        double r4061448 = -3.7108875578650606e+138;
        bool r4061449 = r4061447 <= r4061448;
        double r4061450 = c;
        double r4061451 = r4061450 / r4061447;
        double r4061452 = a;
        double r4061453 = r4061447 / r4061452;
        double r4061454 = r4061451 - r4061453;
        double r4061455 = 1.0;
        double r4061456 = r4061454 * r4061455;
        double r4061457 = 4.626043257219638e-62;
        bool r4061458 = r4061447 <= r4061457;
        double r4061459 = r4061447 * r4061447;
        double r4061460 = 4.0;
        double r4061461 = r4061460 * r4061452;
        double r4061462 = r4061461 * r4061450;
        double r4061463 = r4061459 - r4061462;
        double r4061464 = sqrt(r4061463);
        double r4061465 = -r4061447;
        double r4061466 = r4061464 + r4061465;
        double r4061467 = 2.0;
        double r4061468 = r4061452 * r4061467;
        double r4061469 = r4061466 / r4061468;
        double r4061470 = -1.0;
        double r4061471 = r4061470 * r4061451;
        double r4061472 = r4061458 ? r4061469 : r4061471;
        double r4061473 = r4061449 ? r4061456 : r4061472;
        return r4061473;
}

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

Original34.2
Target21.0
Herbie9.5
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 3 regimes
  2. if b < -3.7108875578650606e+138

    1. Initial program 58.5

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. Simplified2.0

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

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

    1. Initial program 12.3

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

    if 4.626043257219638e-62 < b

    1. Initial program 53.7

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

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

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

Reproduce

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

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))