Average Error: 33.8 → 10.7
Time: 57.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 -1.554334380656473166047169134650490279571 \cdot 10^{60}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le -3.43629125879031642394551270881625565751 \cdot 10^{-161}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{a} \cdot \frac{\left(c \cdot a\right) \cdot 4}{2 \cdot \left(\left(b \cdot b - b \cdot b\right) + \left(c \cdot a\right) \cdot 4\right)}\\ \mathbf{elif}\;b \le 1.958082194924451042912296607079150108999 \cdot 10^{133}:\\ \;\;\;\;\frac{\frac{4 \cdot a}{2} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -1}{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 -1.554334380656473166047169134650490279571 \cdot 10^{60}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r169080 = b;
        double r169081 = -r169080;
        double r169082 = r169080 * r169080;
        double r169083 = 4.0;
        double r169084 = a;
        double r169085 = r169083 * r169084;
        double r169086 = c;
        double r169087 = r169085 * r169086;
        double r169088 = r169082 - r169087;
        double r169089 = sqrt(r169088);
        double r169090 = r169081 + r169089;
        double r169091 = 2.0;
        double r169092 = r169091 * r169084;
        double r169093 = r169090 / r169092;
        return r169093;
}

double f(double a, double b, double c) {
        double r169094 = b;
        double r169095 = -1.5543343806564732e+60;
        bool r169096 = r169094 <= r169095;
        double r169097 = c;
        double r169098 = r169097 / r169094;
        double r169099 = a;
        double r169100 = r169094 / r169099;
        double r169101 = r169098 - r169100;
        double r169102 = 1.0;
        double r169103 = r169101 * r169102;
        double r169104 = -3.4362912587903164e-161;
        bool r169105 = r169094 <= r169104;
        double r169106 = r169094 * r169094;
        double r169107 = r169097 * r169099;
        double r169108 = 4.0;
        double r169109 = r169107 * r169108;
        double r169110 = r169106 - r169109;
        double r169111 = sqrt(r169110);
        double r169112 = r169111 - r169094;
        double r169113 = r169112 / r169099;
        double r169114 = 2.0;
        double r169115 = r169106 - r169106;
        double r169116 = r169115 + r169109;
        double r169117 = r169114 * r169116;
        double r169118 = r169109 / r169117;
        double r169119 = r169113 * r169118;
        double r169120 = 1.958082194924451e+133;
        bool r169121 = r169094 <= r169120;
        double r169122 = r169108 * r169099;
        double r169123 = r169122 / r169114;
        double r169124 = -r169094;
        double r169125 = r169124 - r169111;
        double r169126 = r169097 / r169125;
        double r169127 = r169123 * r169126;
        double r169128 = r169127 / r169099;
        double r169129 = -1.0;
        double r169130 = r169097 * r169129;
        double r169131 = r169130 / r169094;
        double r169132 = r169121 ? r169128 : r169131;
        double r169133 = r169105 ? r169119 : r169132;
        double r169134 = r169096 ? r169103 : r169133;
        return r169134;
}

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
Herbie10.7
\[\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 < -1.5543343806564732e+60

    1. Initial program 39.6

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

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

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

    if -1.5543343806564732e+60 < b < -3.4362912587903164e-161

    1. Initial program 6.0

      \[\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-+39.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. Simplified39.2

      \[\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}\]
    5. Using strategy rm
    6. Applied flip--39.2

      \[\leadsto \frac{\frac{0 + \left(4 \cdot a\right) \cdot c}{\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}\]
    7. Applied associate-/r/39.2

      \[\leadsto \frac{\color{blue}{\frac{0 + \left(4 \cdot a\right) \cdot c}{\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}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}\]
    8. Applied times-frac39.2

      \[\leadsto \color{blue}{\frac{\frac{0 + \left(4 \cdot a\right) \cdot c}{\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}}}{2} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}}\]
    9. Simplified17.2

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

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

    if -3.4362912587903164e-161 < b < 1.958082194924451e+133

    1. Initial program 29.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-+29.9

      \[\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}\]
    5. Using strategy rm
    6. Applied associate-/r*16.7

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

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

    if 1.958082194924451e+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. Simplified1.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.554334380656473166047169134650490279571 \cdot 10^{60}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le -3.43629125879031642394551270881625565751 \cdot 10^{-161}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{a} \cdot \frac{\left(c \cdot a\right) \cdot 4}{2 \cdot \left(\left(b \cdot b - b \cdot b\right) + \left(c \cdot a\right) \cdot 4\right)}\\ \mathbf{elif}\;b \le 1.958082194924451042912296607079150108999 \cdot 10^{133}:\\ \;\;\;\;\frac{\frac{4 \cdot a}{2} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -1}{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)))