Average Error: 33.7 → 6.9
Time: 6.5s
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 -9.5975400610846271 \cdot 10^{115}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.06237398994986779 \cdot 10^{-305}:\\ \;\;\;\;1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.29571176074688 \cdot 10^{130}:\\ \;\;\;\;\frac{1}{\left(-b\right) \cdot \frac{\frac{2}{4}}{c} + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\frac{2}{4}}{c}}\\ \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 -9.5975400610846271 \cdot 10^{115}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r72823 = b;
        double r72824 = -r72823;
        double r72825 = r72823 * r72823;
        double r72826 = 4.0;
        double r72827 = a;
        double r72828 = r72826 * r72827;
        double r72829 = c;
        double r72830 = r72828 * r72829;
        double r72831 = r72825 - r72830;
        double r72832 = sqrt(r72831);
        double r72833 = r72824 + r72832;
        double r72834 = 2.0;
        double r72835 = r72834 * r72827;
        double r72836 = r72833 / r72835;
        return r72836;
}

double f(double a, double b, double c) {
        double r72837 = b;
        double r72838 = -9.597540061084627e+115;
        bool r72839 = r72837 <= r72838;
        double r72840 = 1.0;
        double r72841 = c;
        double r72842 = r72841 / r72837;
        double r72843 = a;
        double r72844 = r72837 / r72843;
        double r72845 = r72842 - r72844;
        double r72846 = r72840 * r72845;
        double r72847 = -1.0623739899498678e-305;
        bool r72848 = r72837 <= r72847;
        double r72849 = 1.0;
        double r72850 = -r72837;
        double r72851 = r72837 * r72837;
        double r72852 = 4.0;
        double r72853 = r72852 * r72843;
        double r72854 = r72853 * r72841;
        double r72855 = r72851 - r72854;
        double r72856 = sqrt(r72855);
        double r72857 = r72850 + r72856;
        double r72858 = 2.0;
        double r72859 = r72858 * r72843;
        double r72860 = r72857 / r72859;
        double r72861 = r72849 * r72860;
        double r72862 = 3.29571176074688e+130;
        bool r72863 = r72837 <= r72862;
        double r72864 = r72858 / r72852;
        double r72865 = r72864 / r72841;
        double r72866 = r72850 * r72865;
        double r72867 = -r72856;
        double r72868 = r72867 * r72865;
        double r72869 = r72866 + r72868;
        double r72870 = r72849 / r72869;
        double r72871 = -1.0;
        double r72872 = r72871 * r72842;
        double r72873 = r72863 ? r72870 : r72872;
        double r72874 = r72848 ? r72861 : r72873;
        double r72875 = r72839 ? r72846 : r72874;
        return r72875;
}

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.9
Herbie6.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 4 regimes
  2. if b < -9.597540061084627e+115

    1. Initial program 48.7

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

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

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

    if -9.597540061084627e+115 < b < -1.0623739899498678e-305

    1. Initial program 8.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 *-un-lft-identity8.7

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

    if -1.0623739899498678e-305 < b < 3.29571176074688e+130

    1. Initial program 34.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 flip-+34.4

      \[\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. Simplified16.9

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{1}}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    11. Using strategy rm
    12. Applied times-frac16.0

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

      \[\leadsto \frac{\frac{1}{1}}{\left(\frac{2}{4} \cdot \color{blue}{\frac{1}{c}}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    14. Using strategy rm
    15. Applied sub-neg9.7

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

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

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

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

    if 3.29571176074688e+130 < b

    1. Initial program 61.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.5975400610846271 \cdot 10^{115}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.06237398994986779 \cdot 10^{-305}:\\ \;\;\;\;1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.29571176074688 \cdot 10^{130}:\\ \;\;\;\;\frac{1}{\left(-b\right) \cdot \frac{\frac{2}{4}}{c} + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\frac{2}{4}}{c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020100 +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)))