Average Error: 34.3 → 10.5
Time: 17.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 -1.566577234736048594271680252121402983446 \cdot 10^{69}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.649990358912618894034395734880511734682 \cdot 10^{-53}:\\ \;\;\;\;\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.566577234736048594271680252121402983446 \cdot 10^{69}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 2.649990358912618894034395734880511734682 \cdot 10^{-53}:\\
\;\;\;\;\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 r60558 = b;
        double r60559 = -r60558;
        double r60560 = r60558 * r60558;
        double r60561 = 4.0;
        double r60562 = a;
        double r60563 = r60561 * r60562;
        double r60564 = c;
        double r60565 = r60563 * r60564;
        double r60566 = r60560 - r60565;
        double r60567 = sqrt(r60566);
        double r60568 = r60559 + r60567;
        double r60569 = 2.0;
        double r60570 = r60569 * r60562;
        double r60571 = r60568 / r60570;
        return r60571;
}

double f(double a, double b, double c) {
        double r60572 = b;
        double r60573 = -1.5665772347360486e+69;
        bool r60574 = r60572 <= r60573;
        double r60575 = 1.0;
        double r60576 = c;
        double r60577 = r60576 / r60572;
        double r60578 = a;
        double r60579 = r60572 / r60578;
        double r60580 = r60577 - r60579;
        double r60581 = r60575 * r60580;
        double r60582 = 2.649990358912619e-53;
        bool r60583 = r60572 <= r60582;
        double r60584 = 1.0;
        double r60585 = 2.0;
        double r60586 = r60585 * r60578;
        double r60587 = r60572 * r60572;
        double r60588 = 4.0;
        double r60589 = r60588 * r60578;
        double r60590 = r60589 * r60576;
        double r60591 = r60587 - r60590;
        double r60592 = sqrt(r60591);
        double r60593 = r60592 - r60572;
        double r60594 = r60586 / r60593;
        double r60595 = r60584 / r60594;
        double r60596 = -1.0;
        double r60597 = r60596 * r60577;
        double r60598 = r60583 ? r60595 : r60597;
        double r60599 = r60574 ? r60581 : r60598;
        return r60599;
}

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.3
Target21.2
Herbie10.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 < -1.5665772347360486e+69

    1. Initial program 41.7

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

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

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

    if -1.5665772347360486e+69 < b < 2.649990358912619e-53

    1. Initial program 14.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-num14.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. Simplified14.7

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

    if 2.649990358912619e-53 < b

    1. Initial program 54.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.566577234736048594271680252121402983446 \cdot 10^{69}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.649990358912618894034395734880511734682 \cdot 10^{-53}:\\ \;\;\;\;\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 2019306 +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)))