Average Error: 34.0 → 7.1
Time: 46.8s
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 -5.089942740476039 \cdot 10^{+37}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.1606217053284985 \cdot 10^{-301}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.9653089193303188 \cdot 10^{+135}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\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 -5.089942740476039 \cdot 10^{+37}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r5116447 = b;
        double r5116448 = -r5116447;
        double r5116449 = r5116447 * r5116447;
        double r5116450 = 4.0;
        double r5116451 = a;
        double r5116452 = r5116450 * r5116451;
        double r5116453 = c;
        double r5116454 = r5116452 * r5116453;
        double r5116455 = r5116449 - r5116454;
        double r5116456 = sqrt(r5116455);
        double r5116457 = r5116448 + r5116456;
        double r5116458 = 2.0;
        double r5116459 = r5116458 * r5116451;
        double r5116460 = r5116457 / r5116459;
        return r5116460;
}

double f(double a, double b, double c) {
        double r5116461 = b;
        double r5116462 = -5.089942740476039e+37;
        bool r5116463 = r5116461 <= r5116462;
        double r5116464 = c;
        double r5116465 = r5116464 / r5116461;
        double r5116466 = a;
        double r5116467 = r5116461 / r5116466;
        double r5116468 = r5116465 - r5116467;
        double r5116469 = 1.1606217053284985e-301;
        bool r5116470 = r5116461 <= r5116469;
        double r5116471 = r5116461 * r5116461;
        double r5116472 = r5116464 * r5116466;
        double r5116473 = 4.0;
        double r5116474 = r5116472 * r5116473;
        double r5116475 = r5116471 - r5116474;
        double r5116476 = sqrt(r5116475);
        double r5116477 = r5116476 - r5116461;
        double r5116478 = 2.0;
        double r5116479 = r5116466 * r5116478;
        double r5116480 = r5116477 / r5116479;
        double r5116481 = 1.9653089193303188e+135;
        bool r5116482 = r5116461 <= r5116481;
        double r5116483 = -2.0;
        double r5116484 = r5116464 * r5116483;
        double r5116485 = r5116476 + r5116461;
        double r5116486 = r5116484 / r5116485;
        double r5116487 = -r5116465;
        double r5116488 = r5116482 ? r5116486 : r5116487;
        double r5116489 = r5116470 ? r5116480 : r5116488;
        double r5116490 = r5116463 ? r5116468 : r5116489;
        return r5116490;
}

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.0
Target20.7
Herbie7.1
\[\begin{array}{l} \mathbf{if}\;b \lt 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 < -5.089942740476039e+37

    1. Initial program 34.9

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

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

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

    if -5.089942740476039e+37 < b < 1.1606217053284985e-301

    1. Initial program 10.3

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

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

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

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

    if 1.1606217053284985e-301 < b < 1.9653089193303188e+135

    1. Initial program 34.6

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

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

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

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

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

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

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

    if 1.9653089193303188e+135 < b

    1. Initial program 61.2

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.089942740476039 \cdot 10^{+37}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.1606217053284985 \cdot 10^{-301}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.9653089193303188 \cdot 10^{+135}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019121 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 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)))