Average Error: 34.7 → 7.0
Time: 6.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 -2.3202538172935113 \cdot 10^{68}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.90883508250240445 \cdot 10^{-161}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.67086091268017442 \cdot 10^{125}:\\ \;\;\;\;\frac{\frac{1}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4}}}{2} \cdot \frac{1}{\frac{1}{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 -2.3202538172935113 \cdot 10^{68}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r105862 = b;
        double r105863 = -r105862;
        double r105864 = r105862 * r105862;
        double r105865 = 4.0;
        double r105866 = a;
        double r105867 = r105865 * r105866;
        double r105868 = c;
        double r105869 = r105867 * r105868;
        double r105870 = r105864 - r105869;
        double r105871 = sqrt(r105870);
        double r105872 = r105863 + r105871;
        double r105873 = 2.0;
        double r105874 = r105873 * r105866;
        double r105875 = r105872 / r105874;
        return r105875;
}

double f(double a, double b, double c) {
        double r105876 = b;
        double r105877 = -2.3202538172935113e+68;
        bool r105878 = r105876 <= r105877;
        double r105879 = 1.0;
        double r105880 = c;
        double r105881 = r105880 / r105876;
        double r105882 = a;
        double r105883 = r105876 / r105882;
        double r105884 = r105881 - r105883;
        double r105885 = r105879 * r105884;
        double r105886 = -8.908835082502404e-161;
        bool r105887 = r105876 <= r105886;
        double r105888 = -r105876;
        double r105889 = r105876 * r105876;
        double r105890 = 4.0;
        double r105891 = r105890 * r105882;
        double r105892 = r105891 * r105880;
        double r105893 = r105889 - r105892;
        double r105894 = sqrt(r105893);
        double r105895 = r105888 + r105894;
        double r105896 = 1.0;
        double r105897 = 2.0;
        double r105898 = r105897 * r105882;
        double r105899 = r105896 / r105898;
        double r105900 = r105895 * r105899;
        double r105901 = 3.6708609126801744e+125;
        bool r105902 = r105876 <= r105901;
        double r105903 = r105888 - r105894;
        double r105904 = r105903 / r105890;
        double r105905 = r105896 / r105904;
        double r105906 = r105905 / r105897;
        double r105907 = r105896 / r105880;
        double r105908 = r105896 / r105907;
        double r105909 = r105906 * r105908;
        double r105910 = -1.0;
        double r105911 = r105910 * r105881;
        double r105912 = r105902 ? r105909 : r105911;
        double r105913 = r105887 ? r105900 : r105912;
        double r105914 = r105878 ? r105885 : r105913;
        return r105914;
}

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.7
Target20.9
Herbie7.0
\[\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 < -2.3202538172935113e+68

    1. Initial program 40.7

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

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

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

    if -2.3202538172935113e+68 < b < -8.908835082502404e-161

    1. Initial program 6.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 div-inv6.5

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

    if -8.908835082502404e-161 < b < 3.6708609126801744e+125

    1. Initial program 29.8

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

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

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

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

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4}}{a \cdot c}}}}{2 \cdot a}\]
    8. Using strategy rm
    9. Applied div-inv17.5

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4} \cdot \frac{1}{a \cdot c}}}}{2 \cdot a}\]
    10. Applied add-sqr-sqrt17.5

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

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

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

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

      \[\leadsto \frac{\frac{1}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4}}}{2} \cdot \color{blue}{\frac{a \cdot c}{a}}\]
    15. Using strategy rm
    16. Applied clear-num15.8

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

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

    if 3.6708609126801744e+125 < b

    1. Initial program 61.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.3202538172935113 \cdot 10^{68}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -8.90883508250240445 \cdot 10^{-161}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.67086091268017442 \cdot 10^{125}:\\ \;\;\;\;\frac{\frac{1}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4}}}{2} \cdot \frac{1}{\frac{1}{c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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