Average Error: 34.1 → 6.5
Time: 4.9s
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.7431685240570133 \cdot 10^{102}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.0417939395900796 \cdot 10^{-259}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 9.37351117144741807 \cdot 10^{103}:\\ \;\;\;\;\frac{\frac{1}{\frac{2}{4}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot 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 -1.7431685240570133 \cdot 10^{102}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r101216 = b;
        double r101217 = -r101216;
        double r101218 = r101216 * r101216;
        double r101219 = 4.0;
        double r101220 = a;
        double r101221 = r101219 * r101220;
        double r101222 = c;
        double r101223 = r101221 * r101222;
        double r101224 = r101218 - r101223;
        double r101225 = sqrt(r101224);
        double r101226 = r101217 + r101225;
        double r101227 = 2.0;
        double r101228 = r101227 * r101220;
        double r101229 = r101226 / r101228;
        return r101229;
}

double f(double a, double b, double c) {
        double r101230 = b;
        double r101231 = -1.7431685240570133e+102;
        bool r101232 = r101230 <= r101231;
        double r101233 = 1.0;
        double r101234 = c;
        double r101235 = r101234 / r101230;
        double r101236 = a;
        double r101237 = r101230 / r101236;
        double r101238 = r101235 - r101237;
        double r101239 = r101233 * r101238;
        double r101240 = 1.0417939395900796e-259;
        bool r101241 = r101230 <= r101240;
        double r101242 = -r101230;
        double r101243 = r101230 * r101230;
        double r101244 = 4.0;
        double r101245 = r101244 * r101236;
        double r101246 = r101245 * r101234;
        double r101247 = r101243 - r101246;
        double r101248 = sqrt(r101247);
        double r101249 = r101242 + r101248;
        double r101250 = 2.0;
        double r101251 = r101250 * r101236;
        double r101252 = r101249 / r101251;
        double r101253 = 9.373511171447418e+103;
        bool r101254 = r101230 <= r101253;
        double r101255 = 1.0;
        double r101256 = r101250 / r101244;
        double r101257 = r101255 / r101256;
        double r101258 = r101242 - r101248;
        double r101259 = r101257 / r101258;
        double r101260 = r101259 * r101234;
        double r101261 = -1.0;
        double r101262 = r101261 * r101235;
        double r101263 = r101254 ? r101260 : r101262;
        double r101264 = r101241 ? r101252 : r101263;
        double r101265 = r101232 ? r101239 : r101264;
        return r101265;
}

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.1
Target20.5
Herbie6.5
\[\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.7431685240570133e+102

    1. Initial program 47.5

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

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

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

    if -1.7431685240570133e+102 < b < 1.0417939395900796e-259

    1. Initial program 9.7

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

    if 1.0417939395900796e-259 < b < 9.373511171447418e+103

    1. Initial program 34.9

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

      \[\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. Simplified17.0

      \[\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-num17.3

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied times-frac16.1

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

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

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

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

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

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

    if 9.373511171447418e+103 < b

    1. Initial program 59.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.7431685240570133 \cdot 10^{102}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.0417939395900796 \cdot 10^{-259}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 9.37351117144741807 \cdot 10^{103}:\\ \;\;\;\;\frac{\frac{1}{\frac{2}{4}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot c\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020024 
(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)))