Average Error: 33.7 → 10.0
Time: 11.9s
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 -2.847204280282031663920354805138023860461 \cdot 10^{48}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.407088231767797284873172100248652560848 \cdot 10^{-46}:\\ \;\;\;\;\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 -2.847204280282031663920354805138023860461 \cdot 10^{48}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 1.407088231767797284873172100248652560848 \cdot 10^{-46}:\\
\;\;\;\;\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 r71487 = b;
        double r71488 = -r71487;
        double r71489 = r71487 * r71487;
        double r71490 = 4.0;
        double r71491 = a;
        double r71492 = r71490 * r71491;
        double r71493 = c;
        double r71494 = r71492 * r71493;
        double r71495 = r71489 - r71494;
        double r71496 = sqrt(r71495);
        double r71497 = r71488 + r71496;
        double r71498 = 2.0;
        double r71499 = r71498 * r71491;
        double r71500 = r71497 / r71499;
        return r71500;
}

double f(double a, double b, double c) {
        double r71501 = b;
        double r71502 = -2.8472042802820317e+48;
        bool r71503 = r71501 <= r71502;
        double r71504 = 1.0;
        double r71505 = c;
        double r71506 = r71505 / r71501;
        double r71507 = a;
        double r71508 = r71501 / r71507;
        double r71509 = r71506 - r71508;
        double r71510 = r71504 * r71509;
        double r71511 = 1.4070882317677973e-46;
        bool r71512 = r71501 <= r71511;
        double r71513 = 1.0;
        double r71514 = 2.0;
        double r71515 = r71514 * r71507;
        double r71516 = r71501 * r71501;
        double r71517 = 4.0;
        double r71518 = r71517 * r71507;
        double r71519 = r71518 * r71505;
        double r71520 = r71516 - r71519;
        double r71521 = sqrt(r71520);
        double r71522 = r71521 - r71501;
        double r71523 = r71515 / r71522;
        double r71524 = r71513 / r71523;
        double r71525 = -1.0;
        double r71526 = r71525 * r71506;
        double r71527 = r71512 ? r71524 : r71526;
        double r71528 = r71503 ? r71510 : r71527;
        return r71528;
}

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.7
Target20.6
Herbie10.0
\[\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 < -2.8472042802820317e+48

    1. Initial program 38.1

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

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

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

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

    if -2.8472042802820317e+48 < b < 1.4070882317677973e-46

    1. Initial program 14.4

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

      \[\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-num14.5

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

    if 1.4070882317677973e-46 < b

    1. Initial program 53.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.847204280282031663920354805138023860461 \cdot 10^{48}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.407088231767797284873172100248652560848 \cdot 10^{-46}:\\ \;\;\;\;\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 2019212 
(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)))