Average Error: 33.3 → 8.6
Time: 20.1s
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.82289647433212 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.1232170674377175 \cdot 10^{-242}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.3233344071163898 \cdot 10^{+19}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\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.82289647433212 \cdot 10^{+153}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r4559575 = b;
        double r4559576 = -r4559575;
        double r4559577 = r4559575 * r4559575;
        double r4559578 = 4.0;
        double r4559579 = a;
        double r4559580 = r4559578 * r4559579;
        double r4559581 = c;
        double r4559582 = r4559580 * r4559581;
        double r4559583 = r4559577 - r4559582;
        double r4559584 = sqrt(r4559583);
        double r4559585 = r4559576 + r4559584;
        double r4559586 = 2.0;
        double r4559587 = r4559586 * r4559579;
        double r4559588 = r4559585 / r4559587;
        return r4559588;
}

double f(double a, double b, double c) {
        double r4559589 = b;
        double r4559590 = -4.82289647433212e+153;
        bool r4559591 = r4559589 <= r4559590;
        double r4559592 = c;
        double r4559593 = r4559592 / r4559589;
        double r4559594 = a;
        double r4559595 = r4559589 / r4559594;
        double r4559596 = r4559593 - r4559595;
        double r4559597 = 3.1232170674377175e-242;
        bool r4559598 = r4559589 <= r4559597;
        double r4559599 = -r4559589;
        double r4559600 = r4559589 * r4559589;
        double r4559601 = 4.0;
        double r4559602 = r4559601 * r4559594;
        double r4559603 = r4559592 * r4559602;
        double r4559604 = r4559600 - r4559603;
        double r4559605 = sqrt(r4559604);
        double r4559606 = r4559599 + r4559605;
        double r4559607 = 2.0;
        double r4559608 = r4559594 * r4559607;
        double r4559609 = r4559606 / r4559608;
        double r4559610 = 1.3233344071163898e+19;
        bool r4559611 = r4559589 <= r4559610;
        double r4559612 = r4559600 - r4559600;
        double r4559613 = r4559612 + r4559603;
        double r4559614 = r4559599 - r4559605;
        double r4559615 = r4559613 / r4559614;
        double r4559616 = r4559615 / r4559608;
        double r4559617 = -r4559593;
        double r4559618 = r4559611 ? r4559616 : r4559617;
        double r4559619 = r4559598 ? r4559609 : r4559618;
        double r4559620 = r4559591 ? r4559596 : r4559619;
        return r4559620;
}

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.3
Target20.7
Herbie8.6
\[\begin{array}{l} \mathbf{if}\;b \lt 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.82289647433212e+153

    1. Initial program 60.9

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

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]

    if -4.82289647433212e+153 < b < 3.1232170674377175e-242

    1. Initial program 9.2

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

    if 3.1232170674377175e-242 < b < 1.3233344071163898e+19

    1. Initial program 28.7

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

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

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

    if 1.3233344071163898e+19 < b

    1. Initial program 55.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity55.3

      \[\leadsto \frac{\left(-b\right) + \color{blue}{1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    4. Applied *-un-lft-identity55.3

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} + 1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    5. Applied distribute-lft-out55.3

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}\]
    6. Applied associate-/l*55.4

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{\frac{\sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} - b}{a}}}}\]
    8. Using strategy rm
    9. Applied associate-/r/55.4

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    11. Simplified4.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.82289647433212 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.1232170674377175 \cdot 10^{-242}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.3233344071163898 \cdot 10^{+19}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

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