Average Error: 34.3 → 8.6
Time: 13.4s
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.569310777886352095486911207889814773134 \cdot 10^{111}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le \frac{-8633006810733365}{2.808895523222368605827039360607851146278 \cdot 10^{306}}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{elif}\;b \le 1.447939350868406385811948663168665665979 \cdot 10^{78}:\\ \;\;\;\;\frac{\frac{\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)}{2 \cdot a}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \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.569310777886352095486911207889814773134 \cdot 10^{111}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r76736 = b;
        double r76737 = -r76736;
        double r76738 = r76736 * r76736;
        double r76739 = 4.0;
        double r76740 = a;
        double r76741 = r76739 * r76740;
        double r76742 = c;
        double r76743 = r76741 * r76742;
        double r76744 = r76738 - r76743;
        double r76745 = sqrt(r76744);
        double r76746 = r76737 + r76745;
        double r76747 = 2.0;
        double r76748 = r76747 * r76740;
        double r76749 = r76746 / r76748;
        return r76749;
}

double f(double a, double b, double c) {
        double r76750 = b;
        double r76751 = -1.569310777886352e+111;
        bool r76752 = r76750 <= r76751;
        double r76753 = 1.0;
        double r76754 = 2.0;
        double r76755 = r76753 / r76754;
        double r76756 = c;
        double r76757 = r76756 / r76750;
        double r76758 = r76754 * r76757;
        double r76759 = 2.0;
        double r76760 = a;
        double r76761 = r76750 / r76760;
        double r76762 = r76759 * r76761;
        double r76763 = r76758 - r76762;
        double r76764 = r76755 * r76763;
        double r76765 = -8633006810733365.0;
        double r76766 = 2.8088955232223686e+306;
        double r76767 = r76765 / r76766;
        bool r76768 = r76750 <= r76767;
        double r76769 = -r76750;
        double r76770 = r76750 * r76750;
        double r76771 = 4.0;
        double r76772 = r76771 * r76760;
        double r76773 = r76772 * r76756;
        double r76774 = r76770 - r76773;
        double r76775 = sqrt(r76774);
        double r76776 = r76769 + r76775;
        double r76777 = r76776 / r76760;
        double r76778 = r76755 * r76777;
        double r76779 = 1.4479393508684064e+78;
        bool r76780 = r76750 <= r76779;
        double r76781 = pow(r76750, r76759);
        double r76782 = r76781 - r76781;
        double r76783 = r76760 * r76756;
        double r76784 = r76771 * r76783;
        double r76785 = r76782 + r76784;
        double r76786 = r76754 * r76760;
        double r76787 = r76785 / r76786;
        double r76788 = r76769 - r76775;
        double r76789 = r76787 / r76788;
        double r76790 = -2.0;
        double r76791 = r76790 * r76757;
        double r76792 = r76755 * r76791;
        double r76793 = r76780 ? r76789 : r76792;
        double r76794 = r76768 ? r76778 : r76793;
        double r76795 = r76752 ? r76764 : r76794;
        return r76795;
}

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.1
Herbie8.6
\[\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 4 regimes
  2. if b < -1.569310777886352e+111

    1. Initial program 50.4

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{2}{1} \cdot \frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    8. Applied times-frac50.4

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

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

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

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

    if -1.569310777886352e+111 < b < -3.07345244398039e-291

    1. Initial program 8.4

      \[\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-num8.6

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity8.6

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

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

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{2}{1} \cdot \frac{a}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    8. Applied times-frac8.6

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

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

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

    if -3.07345244398039e-291 < b < 1.4479393508684064e+78

    1. Initial program 30.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 clear-num30.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. Using strategy rm
    5. Applied flip-+30.8

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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}}}}}\]
    6. Applied associate-/r/30.8

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\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}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    7. Applied associate-/r*30.9

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{2 \cdot a}{\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}}}\]
    8. Simplified15.9

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

    if 1.4479393508684064e+78 < b

    1. Initial program 58.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 clear-num58.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. Using strategy rm
    5. Applied *-un-lft-identity58.7

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

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

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(-2 \cdot \frac{c}{b}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.569310777886352095486911207889814773134 \cdot 10^{111}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le \frac{-8633006810733365}{2.808895523222368605827039360607851146278 \cdot 10^{306}}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}\\ \mathbf{elif}\;b \le 1.447939350868406385811948663168665665979 \cdot 10^{78}:\\ \;\;\;\;\frac{\frac{\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)}{2 \cdot a}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019303 
(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)))