Average Error: 33.8 → 10.7
Time: 47.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 r231152 = b;
        double r231153 = -r231152;
        double r231154 = r231152 * r231152;
        double r231155 = 4.0;
        double r231156 = a;
        double r231157 = r231155 * r231156;
        double r231158 = c;
        double r231159 = r231157 * r231158;
        double r231160 = r231154 - r231159;
        double r231161 = sqrt(r231160);
        double r231162 = r231153 + r231161;
        double r231163 = 2.0;
        double r231164 = r231163 * r231156;
        double r231165 = r231162 / r231164;
        return r231165;
}

double f(double a, double b, double c) {
        double r231166 = b;
        double r231167 = -1.5543343806564732e+60;
        bool r231168 = r231166 <= r231167;
        double r231169 = c;
        double r231170 = r231169 / r231166;
        double r231171 = a;
        double r231172 = r231166 / r231171;
        double r231173 = r231170 - r231172;
        double r231174 = 1.0;
        double r231175 = r231173 * r231174;
        double r231176 = -3.4362912587903164e-161;
        bool r231177 = r231166 <= r231176;
        double r231178 = r231166 * r231166;
        double r231179 = r231169 * r231171;
        double r231180 = 4.0;
        double r231181 = r231179 * r231180;
        double r231182 = r231178 - r231181;
        double r231183 = sqrt(r231182);
        double r231184 = r231183 - r231166;
        double r231185 = r231184 / r231171;
        double r231186 = 2.0;
        double r231187 = r231178 - r231178;
        double r231188 = r231187 + r231181;
        double r231189 = r231186 * r231188;
        double r231190 = r231181 / r231189;
        double r231191 = r231185 * r231190;
        double r231192 = 1.958082194924451e+133;
        bool r231193 = r231166 <= r231192;
        double r231194 = r231180 * r231171;
        double r231195 = r231194 / r231186;
        double r231196 = -r231166;
        double r231197 = r231196 - r231183;
        double r231198 = r231169 / r231197;
        double r231199 = r231195 * r231198;
        double r231200 = r231199 / r231171;
        double r231201 = -1.0;
        double r231202 = r231169 * r231201;
        double r231203 = r231202 / r231166;
        double r231204 = r231193 ? r231200 : r231203;
        double r231205 = r231177 ? r231191 : r231204;
        double r231206 = r231168 ? r231175 : r231205;
        return r231206;
}

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