Average Error: 34.7 → 7.0
Time: 7.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 -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 r159919 = b;
        double r159920 = -r159919;
        double r159921 = r159919 * r159919;
        double r159922 = 4.0;
        double r159923 = a;
        double r159924 = r159922 * r159923;
        double r159925 = c;
        double r159926 = r159924 * r159925;
        double r159927 = r159921 - r159926;
        double r159928 = sqrt(r159927);
        double r159929 = r159920 + r159928;
        double r159930 = 2.0;
        double r159931 = r159930 * r159923;
        double r159932 = r159929 / r159931;
        return r159932;
}

double f(double a, double b, double c) {
        double r159933 = b;
        double r159934 = -2.3202538172935113e+68;
        bool r159935 = r159933 <= r159934;
        double r159936 = 1.0;
        double r159937 = c;
        double r159938 = r159937 / r159933;
        double r159939 = a;
        double r159940 = r159933 / r159939;
        double r159941 = r159938 - r159940;
        double r159942 = r159936 * r159941;
        double r159943 = -8.908835082502404e-161;
        bool r159944 = r159933 <= r159943;
        double r159945 = -r159933;
        double r159946 = r159933 * r159933;
        double r159947 = 4.0;
        double r159948 = r159947 * r159939;
        double r159949 = r159948 * r159937;
        double r159950 = r159946 - r159949;
        double r159951 = sqrt(r159950);
        double r159952 = r159945 + r159951;
        double r159953 = 1.0;
        double r159954 = 2.0;
        double r159955 = r159954 * r159939;
        double r159956 = r159953 / r159955;
        double r159957 = r159952 * r159956;
        double r159958 = 3.6708609126801744e+125;
        bool r159959 = r159933 <= r159958;
        double r159960 = r159945 - r159951;
        double r159961 = r159960 / r159947;
        double r159962 = r159953 / r159961;
        double r159963 = r159962 / r159954;
        double r159964 = r159953 / r159937;
        double r159965 = r159953 / r159964;
        double r159966 = r159963 * r159965;
        double r159967 = -1.0;
        double r159968 = r159967 * r159938;
        double r159969 = r159959 ? r159966 : r159968;
        double r159970 = r159944 ? r159957 : r159969;
        double r159971 = r159935 ? r159942 : r159970;
        return r159971;
}

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)))