Average Error: 34.2 → 11.9
Time: 12.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 -1.547666603636537260513437138645901028344 \cdot 10^{50}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.455592343308264166675918758902222662503 \cdot 10^{-170}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \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.547666603636537260513437138645901028344 \cdot 10^{50}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r101140 = b;
        double r101141 = -r101140;
        double r101142 = r101140 * r101140;
        double r101143 = 4.0;
        double r101144 = a;
        double r101145 = r101143 * r101144;
        double r101146 = c;
        double r101147 = r101145 * r101146;
        double r101148 = r101142 - r101147;
        double r101149 = sqrt(r101148);
        double r101150 = r101141 + r101149;
        double r101151 = 2.0;
        double r101152 = r101151 * r101144;
        double r101153 = r101150 / r101152;
        return r101153;
}

double f(double a, double b, double c) {
        double r101154 = b;
        double r101155 = -1.5476666036365373e+50;
        bool r101156 = r101154 <= r101155;
        double r101157 = 1.0;
        double r101158 = c;
        double r101159 = r101158 / r101154;
        double r101160 = a;
        double r101161 = r101154 / r101160;
        double r101162 = r101159 - r101161;
        double r101163 = r101157 * r101162;
        double r101164 = 7.455592343308264e-170;
        bool r101165 = r101154 <= r101164;
        double r101166 = 1.0;
        double r101167 = 2.0;
        double r101168 = r101167 * r101160;
        double r101169 = r101154 * r101154;
        double r101170 = 4.0;
        double r101171 = r101170 * r101160;
        double r101172 = r101171 * r101158;
        double r101173 = r101169 - r101172;
        double r101174 = sqrt(r101173);
        double r101175 = r101174 - r101154;
        double r101176 = r101168 / r101175;
        double r101177 = r101166 / r101176;
        double r101178 = -1.0;
        double r101179 = r101178 * r101159;
        double r101180 = r101165 ? r101177 : r101179;
        double r101181 = r101156 ? r101163 : r101180;
        return r101181;
}

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.2
Target20.8
Herbie11.9
\[\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 3 regimes
  2. if b < -1.5476666036365373e+50

    1. Initial program 37.8

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 5.8

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

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

    if -1.5476666036365373e+50 < b < 7.455592343308264e-170

    1. Initial program 12.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num12.5

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

    if 7.455592343308264e-170 < b

    1. Initial program 48.9

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Taylor expanded around inf 14.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.547666603636537260513437138645901028344 \cdot 10^{50}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.455592343308264166675918758902222662503 \cdot 10^{-170}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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