Average Error: 34.2 → 9.9
Time: 5.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.4052299045085703 \cdot 10^{151}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.2529910715609764 \cdot 10^{-90}:\\ \;\;\;\;\frac{1 \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)}{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.4052299045085703 \cdot 10^{151}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r145197 = b;
        double r145198 = -r145197;
        double r145199 = r145197 * r145197;
        double r145200 = 4.0;
        double r145201 = a;
        double r145202 = r145200 * r145201;
        double r145203 = c;
        double r145204 = r145202 * r145203;
        double r145205 = r145199 - r145204;
        double r145206 = sqrt(r145205);
        double r145207 = r145198 + r145206;
        double r145208 = 2.0;
        double r145209 = r145208 * r145201;
        double r145210 = r145207 / r145209;
        return r145210;
}

double f(double a, double b, double c) {
        double r145211 = b;
        double r145212 = -1.4052299045085703e+151;
        bool r145213 = r145211 <= r145212;
        double r145214 = 1.0;
        double r145215 = c;
        double r145216 = r145215 / r145211;
        double r145217 = a;
        double r145218 = r145211 / r145217;
        double r145219 = r145216 - r145218;
        double r145220 = r145214 * r145219;
        double r145221 = 1.2529910715609764e-90;
        bool r145222 = r145211 <= r145221;
        double r145223 = 1.0;
        double r145224 = r145211 * r145211;
        double r145225 = 4.0;
        double r145226 = r145225 * r145217;
        double r145227 = r145226 * r145215;
        double r145228 = r145224 - r145227;
        double r145229 = sqrt(r145228);
        double r145230 = r145229 - r145211;
        double r145231 = r145223 * r145230;
        double r145232 = 2.0;
        double r145233 = r145232 * r145217;
        double r145234 = r145231 / r145233;
        double r145235 = -1.0;
        double r145236 = r145235 * r145216;
        double r145237 = r145222 ? r145234 : r145236;
        double r145238 = r145213 ? r145220 : r145237;
        return r145238;
}

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
Target21.2
Herbie9.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.4052299045085703e+151

    1. Initial program 63.1

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

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

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

    if -1.4052299045085703e+151 < b < 1.2529910715609764e-90

    1. Initial program 12.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity12.2

      \[\leadsto \frac{\left(-b\right) + \color{blue}{1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    4. Applied *-un-lft-identity12.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} + 1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    5. Applied distribute-lft-out12.2

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

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

    if 1.2529910715609764e-90 < b

    1. Initial program 52.5

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

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

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

Reproduce

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