Average Error: 33.8 → 10.3
Time: 19.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 -4.91962817906715367126033645969528543778 \cdot 10^{153}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.071930020515770918527743961403466592109 \cdot 10^{-74}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a}\\ \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 -4.91962817906715367126033645969528543778 \cdot 10^{153}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r55949 = b;
        double r55950 = -r55949;
        double r55951 = r55949 * r55949;
        double r55952 = 4.0;
        double r55953 = a;
        double r55954 = r55952 * r55953;
        double r55955 = c;
        double r55956 = r55954 * r55955;
        double r55957 = r55951 - r55956;
        double r55958 = sqrt(r55957);
        double r55959 = r55950 + r55958;
        double r55960 = 2.0;
        double r55961 = r55960 * r55953;
        double r55962 = r55959 / r55961;
        return r55962;
}

double f(double a, double b, double c) {
        double r55963 = b;
        double r55964 = -4.919628179067154e+153;
        bool r55965 = r55963 <= r55964;
        double r55966 = 1.0;
        double r55967 = c;
        double r55968 = r55967 / r55963;
        double r55969 = a;
        double r55970 = r55963 / r55969;
        double r55971 = r55968 - r55970;
        double r55972 = r55966 * r55971;
        double r55973 = 2.071930020515771e-74;
        bool r55974 = r55963 <= r55973;
        double r55975 = 1.0;
        double r55976 = 2.0;
        double r55977 = r55975 / r55976;
        double r55978 = r55963 * r55963;
        double r55979 = 4.0;
        double r55980 = r55979 * r55969;
        double r55981 = r55980 * r55967;
        double r55982 = r55978 - r55981;
        double r55983 = sqrt(r55982);
        double r55984 = r55983 - r55963;
        double r55985 = r55984 / r55969;
        double r55986 = r55977 * r55985;
        double r55987 = -2.0;
        double r55988 = r55987 * r55968;
        double r55989 = r55977 * r55988;
        double r55990 = r55974 ? r55986 : r55989;
        double r55991 = r55965 ? r55972 : r55990;
        return r55991;
}

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.8
Target20.4
Herbie10.3
\[\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 3 regimes
  2. if b < -4.919628179067154e+153

    1. Initial program 63.8

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

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

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

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

    if -4.919628179067154e+153 < b < 2.071930020515771e-74

    1. Initial program 12.8

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num13.0

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

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

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

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

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

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

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

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

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

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

    if 2.071930020515771e-74 < b

    1. Initial program 53.2

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num53.2

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.91962817906715367126033645969528543778 \cdot 10^{153}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.071930020515770918527743961403466592109 \cdot 10^{-74}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \end{array}\]

Reproduce

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