Average Error: 34.6 → 8.4
Time: 23.7s
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.6581383089037873 \cdot 10^{81}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.3528823044057167 \cdot 10^{-206}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.593830924265355 \cdot 10^{-35}:\\ \;\;\;\;\frac{\frac{1}{\frac{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4 \cdot a}}{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 -1.6581383089037873 \cdot 10^{81}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r153076 = b;
        double r153077 = -r153076;
        double r153078 = r153076 * r153076;
        double r153079 = 4.0;
        double r153080 = a;
        double r153081 = r153079 * r153080;
        double r153082 = c;
        double r153083 = r153081 * r153082;
        double r153084 = r153078 - r153083;
        double r153085 = sqrt(r153084);
        double r153086 = r153077 + r153085;
        double r153087 = 2.0;
        double r153088 = r153087 * r153080;
        double r153089 = r153086 / r153088;
        return r153089;
}

double f(double a, double b, double c) {
        double r153090 = b;
        double r153091 = -1.6581383089037873e+81;
        bool r153092 = r153090 <= r153091;
        double r153093 = 1.0;
        double r153094 = c;
        double r153095 = r153094 / r153090;
        double r153096 = a;
        double r153097 = r153090 / r153096;
        double r153098 = r153095 - r153097;
        double r153099 = r153093 * r153098;
        double r153100 = -3.3528823044057167e-206;
        bool r153101 = r153090 <= r153100;
        double r153102 = -r153090;
        double r153103 = r153090 * r153090;
        double r153104 = 4.0;
        double r153105 = r153104 * r153096;
        double r153106 = r153105 * r153094;
        double r153107 = r153103 - r153106;
        double r153108 = sqrt(r153107);
        double r153109 = r153102 + r153108;
        double r153110 = 1.0;
        double r153111 = 2.0;
        double r153112 = r153111 * r153096;
        double r153113 = r153110 / r153112;
        double r153114 = r153109 * r153113;
        double r153115 = 3.593830924265355e-35;
        bool r153116 = r153090 <= r153115;
        double r153117 = r153102 - r153108;
        double r153118 = r153117 / r153105;
        double r153119 = r153118 / r153094;
        double r153120 = r153110 / r153119;
        double r153121 = r153120 / r153112;
        double r153122 = -1.0;
        double r153123 = r153122 * r153095;
        double r153124 = r153116 ? r153121 : r153123;
        double r153125 = r153101 ? r153114 : r153124;
        double r153126 = r153092 ? r153099 : r153125;
        return r153126;
}

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.6
Target21.3
Herbie8.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 < -1.6581383089037873e+81

    1. Initial program 43.9

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

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

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

    if -1.6581383089037873e+81 < b < -3.3528823044057167e-206

    1. Initial program 7.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv7.9

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

    if -3.3528823044057167e-206 < b < 3.593830924265355e-35

    1. Initial program 21.5

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

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

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

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

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

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

    if 3.593830924265355e-35 < b

    1. Initial program 55.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.6581383089037873 \cdot 10^{81}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.3528823044057167 \cdot 10^{-206}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.593830924265355 \cdot 10^{-35}:\\ \;\;\;\;\frac{\frac{1}{\frac{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{4 \cdot a}}{c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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