Average Error: 34.5 → 10.3
Time: 16.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 -63362873442066488610789523456:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 6.484072051994263737451444554171174935457 \cdot 10^{-107}:\\ \;\;\;\;\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 -63362873442066488610789523456:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

\mathbf{elif}\;b \le 6.484072051994263737451444554171174935457 \cdot 10^{-107}:\\
\;\;\;\;\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 r4295523 = b;
        double r4295524 = -r4295523;
        double r4295525 = r4295523 * r4295523;
        double r4295526 = 4.0;
        double r4295527 = a;
        double r4295528 = r4295526 * r4295527;
        double r4295529 = c;
        double r4295530 = r4295528 * r4295529;
        double r4295531 = r4295525 - r4295530;
        double r4295532 = sqrt(r4295531);
        double r4295533 = r4295524 + r4295532;
        double r4295534 = 2.0;
        double r4295535 = r4295534 * r4295527;
        double r4295536 = r4295533 / r4295535;
        return r4295536;
}

double f(double a, double b, double c) {
        double r4295537 = b;
        double r4295538 = -6.336287344206649e+28;
        bool r4295539 = r4295537 <= r4295538;
        double r4295540 = c;
        double r4295541 = r4295540 / r4295537;
        double r4295542 = a;
        double r4295543 = r4295537 / r4295542;
        double r4295544 = r4295541 - r4295543;
        double r4295545 = 1.0;
        double r4295546 = r4295544 * r4295545;
        double r4295547 = 6.484072051994264e-107;
        bool r4295548 = r4295537 <= r4295547;
        double r4295549 = r4295537 * r4295537;
        double r4295550 = 4.0;
        double r4295551 = r4295550 * r4295542;
        double r4295552 = r4295551 * r4295540;
        double r4295553 = r4295549 - r4295552;
        double r4295554 = sqrt(r4295553);
        double r4295555 = -r4295537;
        double r4295556 = r4295554 + r4295555;
        double r4295557 = 2.0;
        double r4295558 = r4295542 * r4295557;
        double r4295559 = r4295556 / r4295558;
        double r4295560 = -1.0;
        double r4295561 = r4295560 * r4295541;
        double r4295562 = r4295548 ? r4295559 : r4295561;
        double r4295563 = r4295539 ? r4295546 : r4295562;
        return r4295563;
}

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.5
Target21.0
Herbie10.3
\[\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 < -6.336287344206649e+28

    1. Initial program 34.8

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

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

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

    if -6.336287344206649e+28 < b < 6.484072051994264e-107

    1. Initial program 12.9

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

    if 6.484072051994264e-107 < b

    1. Initial program 52.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -63362873442066488610789523456:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 6.484072051994263737451444554171174935457 \cdot 10^{-107}:\\ \;\;\;\;\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 2019192 
(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)))