Average Error: 33.5 → 10.0
Time: 10.0s
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.478406535480561669630649836752919254545 \cdot 10^{60}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.175674080408202904737521150531781836244 \cdot 10^{-169}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.705250296078930544323375298653357812472 \cdot 10^{-110} \lor \neg \left(b \le 29494967590524297216\right):\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(c \cdot 4\right) \cdot a}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \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.478406535480561669630649836752919254545 \cdot 10^{60}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 3.705250296078930544323375298653357812472 \cdot 10^{-110} \lor \neg \left(b \le 29494967590524297216\right):\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(c \cdot 4\right) \cdot a}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\

\end{array}
double f(double a, double b, double c) {
        double r117372 = b;
        double r117373 = -r117372;
        double r117374 = r117372 * r117372;
        double r117375 = 4.0;
        double r117376 = a;
        double r117377 = r117375 * r117376;
        double r117378 = c;
        double r117379 = r117377 * r117378;
        double r117380 = r117374 - r117379;
        double r117381 = sqrt(r117380);
        double r117382 = r117373 + r117381;
        double r117383 = 2.0;
        double r117384 = r117383 * r117376;
        double r117385 = r117382 / r117384;
        return r117385;
}

double f(double a, double b, double c) {
        double r117386 = b;
        double r117387 = -1.4784065354805617e+60;
        bool r117388 = r117386 <= r117387;
        double r117389 = 1.0;
        double r117390 = c;
        double r117391 = r117390 / r117386;
        double r117392 = a;
        double r117393 = r117386 / r117392;
        double r117394 = r117391 - r117393;
        double r117395 = r117389 * r117394;
        double r117396 = 2.175674080408203e-169;
        bool r117397 = r117386 <= r117396;
        double r117398 = -r117386;
        double r117399 = r117386 * r117386;
        double r117400 = 4.0;
        double r117401 = r117400 * r117392;
        double r117402 = r117401 * r117390;
        double r117403 = r117399 - r117402;
        double r117404 = sqrt(r117403);
        double r117405 = r117398 + r117404;
        double r117406 = 2.0;
        double r117407 = r117406 * r117392;
        double r117408 = r117405 / r117407;
        double r117409 = 3.7052502960789305e-110;
        bool r117410 = r117386 <= r117409;
        double r117411 = 2.9494967590524297e+19;
        bool r117412 = r117386 <= r117411;
        double r117413 = !r117412;
        bool r117414 = r117410 || r117413;
        double r117415 = -1.0;
        double r117416 = r117415 * r117391;
        double r117417 = r117390 * r117400;
        double r117418 = r117417 * r117392;
        double r117419 = r117398 - r117404;
        double r117420 = r117418 / r117419;
        double r117421 = r117420 / r117407;
        double r117422 = r117414 ? r117416 : r117421;
        double r117423 = r117397 ? r117408 : r117422;
        double r117424 = r117388 ? r117395 : r117423;
        return r117424;
}

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.5
Target20.5
Herbie10.0
\[\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.4784065354805617e+60

    1. Initial program 39.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 *-un-lft-identity39.0

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

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

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

    if -1.4784065354805617e+60 < b < 2.175674080408203e-169

    1. Initial program 10.7

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

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

    if 2.175674080408203e-169 < b < 3.7052502960789305e-110 or 2.9494967590524297e+19 < b

    1. Initial program 52.0

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]

    if 3.7052502960789305e-110 < b < 2.9494967590524297e+19

    1. Initial program 37.3

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

      \[\leadsto \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied flip-+37.3

      \[\leadsto 1 \cdot \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}\]
    6. Simplified16.3

      \[\leadsto 1 \cdot \frac{\frac{\color{blue}{0 + \left(c \cdot 4\right) \cdot a}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification10.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.478406535480561669630649836752919254545 \cdot 10^{60}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 2.175674080408202904737521150531781836244 \cdot 10^{-169}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.705250296078930544323375298653357812472 \cdot 10^{-110} \lor \neg \left(b \le 29494967590524297216\right):\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(c \cdot 4\right) \cdot a}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019350 +o rules:numerics
(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)))