Average Error: 33.8 → 9.4
Time: 13.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 -3.56950087216670373 \cdot 10^{75}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.4951704352063921 \cdot 10^{-301}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 2.12540180880083329 \cdot 10^{133}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \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 -3.56950087216670373 \cdot 10^{75}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r211940 = b;
        double r211941 = -r211940;
        double r211942 = r211940 * r211940;
        double r211943 = 4.0;
        double r211944 = a;
        double r211945 = r211943 * r211944;
        double r211946 = c;
        double r211947 = r211945 * r211946;
        double r211948 = r211942 - r211947;
        double r211949 = sqrt(r211948);
        double r211950 = r211941 + r211949;
        double r211951 = 2.0;
        double r211952 = r211951 * r211944;
        double r211953 = r211950 / r211952;
        return r211953;
}

double f(double a, double b, double c) {
        double r211954 = b;
        double r211955 = -3.5695008721667037e+75;
        bool r211956 = r211954 <= r211955;
        double r211957 = 1.0;
        double r211958 = c;
        double r211959 = r211958 / r211954;
        double r211960 = a;
        double r211961 = r211954 / r211960;
        double r211962 = r211959 - r211961;
        double r211963 = r211957 * r211962;
        double r211964 = 1.495170435206392e-301;
        bool r211965 = r211954 <= r211964;
        double r211966 = 1.0;
        double r211967 = 2.0;
        double r211968 = r211967 * r211960;
        double r211969 = r211954 * r211954;
        double r211970 = 4.0;
        double r211971 = r211970 * r211960;
        double r211972 = r211971 * r211958;
        double r211973 = r211969 - r211972;
        double r211974 = sqrt(r211973);
        double r211975 = r211974 - r211954;
        double r211976 = r211968 / r211975;
        double r211977 = r211966 / r211976;
        double r211978 = 2.1254018088008333e+133;
        bool r211979 = r211954 <= r211978;
        double r211980 = -r211954;
        double r211981 = r211980 - r211974;
        double r211982 = r211972 / r211981;
        double r211983 = r211982 / r211968;
        double r211984 = -1.0;
        double r211985 = r211984 * r211959;
        double r211986 = r211979 ? r211983 : r211985;
        double r211987 = r211965 ? r211977 : r211986;
        double r211988 = r211956 ? r211963 : r211987;
        return r211988;
}

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
Target21.2
Herbie9.4
\[\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 < -3.5695008721667037e+75

    1. Initial program 42.1

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

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

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

    if -3.5695008721667037e+75 < b < 1.495170435206392e-301

    1. Initial program 9.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-num9.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. Simplified9.6

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

    if 1.495170435206392e-301 < b < 2.1254018088008333e+133

    1. Initial program 33.6

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

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

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

    if 2.1254018088008333e+133 < b

    1. Initial program 61.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.56950087216670373 \cdot 10^{75}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.4951704352063921 \cdot 10^{-301}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{elif}\;b \le 2.12540180880083329 \cdot 10^{133}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019195 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))