Average Error: 34.1 → 9.9
Time: 17.0s
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 -1.550162015746626746000974336574470460524 \cdot 10^{150}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.61145084478121505718169973575148582501 \cdot 10^{-34}:\\ \;\;\;\;\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 -1.550162015746626746000974336574470460524 \cdot 10^{150}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 1.61145084478121505718169973575148582501 \cdot 10^{-34}:\\
\;\;\;\;\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 r81553 = b;
        double r81554 = -r81553;
        double r81555 = r81553 * r81553;
        double r81556 = 4.0;
        double r81557 = a;
        double r81558 = r81556 * r81557;
        double r81559 = c;
        double r81560 = r81558 * r81559;
        double r81561 = r81555 - r81560;
        double r81562 = sqrt(r81561);
        double r81563 = r81554 + r81562;
        double r81564 = 2.0;
        double r81565 = r81564 * r81557;
        double r81566 = r81563 / r81565;
        return r81566;
}

double f(double a, double b, double c) {
        double r81567 = b;
        double r81568 = -1.5501620157466267e+150;
        bool r81569 = r81567 <= r81568;
        double r81570 = 1.0;
        double r81571 = c;
        double r81572 = r81571 / r81567;
        double r81573 = a;
        double r81574 = r81567 / r81573;
        double r81575 = r81572 - r81574;
        double r81576 = r81570 * r81575;
        double r81577 = 1.611450844781215e-34;
        bool r81578 = r81567 <= r81577;
        double r81579 = 1.0;
        double r81580 = 2.0;
        double r81581 = r81580 * r81573;
        double r81582 = r81567 * r81567;
        double r81583 = 4.0;
        double r81584 = r81583 * r81573;
        double r81585 = r81584 * r81571;
        double r81586 = r81582 - r81585;
        double r81587 = sqrt(r81586);
        double r81588 = r81587 - r81567;
        double r81589 = r81581 / r81588;
        double r81590 = r81579 / r81589;
        double r81591 = -1.0;
        double r81592 = r81591 * r81572;
        double r81593 = r81578 ? r81590 : r81592;
        double r81594 = r81569 ? r81576 : r81593;
        return r81594;
}

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.1
Target21.2
Herbie9.9
\[\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 < -1.5501620157466267e+150

    1. Initial program 62.9

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

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

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

    if -1.5501620157466267e+150 < b < 1.611450844781215e-34

    1. Initial program 13.6

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

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

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

    if 1.611450844781215e-34 < b

    1. Initial program 55.0

      \[\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}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.550162015746626746000974336574470460524 \cdot 10^{150}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.61145084478121505718169973575148582501 \cdot 10^{-34}:\\ \;\;\;\;\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 2019325 +o rules:numerics
(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)))