Average Error: 33.8 → 8.8
Time: 14.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.91962817906715367126033645969528543778 \cdot 10^{153}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.835959749839008164057240193717116825713 \cdot 10^{-262}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.079534415870105228594677033685255838157 \cdot 10^{-51}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2}}{a}\\ \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 -4.91962817906715367126033645969528543778 \cdot 10^{153}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r107485 = b;
        double r107486 = -r107485;
        double r107487 = r107485 * r107485;
        double r107488 = 4.0;
        double r107489 = a;
        double r107490 = r107488 * r107489;
        double r107491 = c;
        double r107492 = r107490 * r107491;
        double r107493 = r107487 - r107492;
        double r107494 = sqrt(r107493);
        double r107495 = r107486 + r107494;
        double r107496 = 2.0;
        double r107497 = r107496 * r107489;
        double r107498 = r107495 / r107497;
        return r107498;
}

double f(double a, double b, double c) {
        double r107499 = b;
        double r107500 = -4.919628179067154e+153;
        bool r107501 = r107499 <= r107500;
        double r107502 = 1.0;
        double r107503 = c;
        double r107504 = r107503 / r107499;
        double r107505 = a;
        double r107506 = r107499 / r107505;
        double r107507 = r107504 - r107506;
        double r107508 = r107502 * r107507;
        double r107509 = -1.8359597498390082e-262;
        bool r107510 = r107499 <= r107509;
        double r107511 = -r107499;
        double r107512 = r107499 * r107499;
        double r107513 = 4.0;
        double r107514 = r107513 * r107505;
        double r107515 = r107514 * r107503;
        double r107516 = r107512 - r107515;
        double r107517 = sqrt(r107516);
        double r107518 = r107511 + r107517;
        double r107519 = 2.0;
        double r107520 = r107519 * r107505;
        double r107521 = r107518 / r107520;
        double r107522 = 2.0795344158701052e-51;
        bool r107523 = r107499 <= r107522;
        double r107524 = r107511 - r107517;
        double r107525 = r107503 / r107524;
        double r107526 = r107514 * r107525;
        double r107527 = r107526 / r107519;
        double r107528 = r107527 / r107505;
        double r107529 = -1.0;
        double r107530 = r107529 * r107504;
        double r107531 = r107523 ? r107528 : r107530;
        double r107532 = r107510 ? r107521 : r107531;
        double r107533 = r107501 ? r107508 : r107532;
        return r107533;
}

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.8
Target20.4
Herbie8.8
\[\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 4 regimes
  2. if b < -4.919628179067154e+153

    1. Initial program 63.8

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

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

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

    if -4.919628179067154e+153 < b < -1.8359597498390082e-262

    1. Initial program 8.6

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

    if -1.8359597498390082e-262 < b < 2.0795344158701052e-51

    1. Initial program 22.0

      \[\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-+22.1

      \[\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.8

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

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

      \[\leadsto \frac{\color{blue}{\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2}}}{a}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity17.8

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

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

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

    if 2.0795344158701052e-51 < b

    1. Initial program 54.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.91962817906715367126033645969528543778 \cdot 10^{153}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.835959749839008164057240193717116825713 \cdot 10^{-262}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.079534415870105228594677033685255838157 \cdot 10^{-51}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.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)))