Average Error: 34.0 → 7.2
Time: 6.2s
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 -3.71711085460076329 \cdot 10^{118}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.9300475349170912 \cdot 10^{-278}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3461964491124549:\\ \;\;\;\;1 \cdot \frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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 -3.71711085460076329 \cdot 10^{118}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r221577 = b;
        double r221578 = -r221577;
        double r221579 = r221577 * r221577;
        double r221580 = 4.0;
        double r221581 = a;
        double r221582 = r221580 * r221581;
        double r221583 = c;
        double r221584 = r221582 * r221583;
        double r221585 = r221579 - r221584;
        double r221586 = sqrt(r221585);
        double r221587 = r221578 + r221586;
        double r221588 = 2.0;
        double r221589 = r221588 * r221581;
        double r221590 = r221587 / r221589;
        return r221590;
}

double f(double a, double b, double c) {
        double r221591 = b;
        double r221592 = -3.7171108546007633e+118;
        bool r221593 = r221591 <= r221592;
        double r221594 = 1.0;
        double r221595 = c;
        double r221596 = r221595 / r221591;
        double r221597 = a;
        double r221598 = r221591 / r221597;
        double r221599 = r221596 - r221598;
        double r221600 = r221594 * r221599;
        double r221601 = -2.930047534917091e-278;
        bool r221602 = r221591 <= r221601;
        double r221603 = -r221591;
        double r221604 = r221591 * r221591;
        double r221605 = 4.0;
        double r221606 = r221605 * r221597;
        double r221607 = r221606 * r221595;
        double r221608 = r221604 - r221607;
        double r221609 = sqrt(r221608);
        double r221610 = r221603 + r221609;
        double r221611 = 2.0;
        double r221612 = r221611 * r221597;
        double r221613 = r221610 / r221612;
        double r221614 = 3461964491124549.0;
        bool r221615 = r221591 <= r221614;
        double r221616 = 1.0;
        double r221617 = r221611 * r221595;
        double r221618 = r221603 - r221609;
        double r221619 = r221617 / r221618;
        double r221620 = r221616 * r221619;
        double r221621 = -1.0;
        double r221622 = r221621 * r221596;
        double r221623 = r221615 ? r221620 : r221622;
        double r221624 = r221602 ? r221613 : r221623;
        double r221625 = r221593 ? r221600 : r221624;
        return r221625;
}

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.8
Herbie7.2
\[\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 < -3.7171108546007633e+118

    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 2.9

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

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

    if -3.7171108546007633e+118 < b < -2.930047534917091e-278

    1. Initial program 8.5

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

    if -2.930047534917091e-278 < b < 3461964491124549.0

    1. Initial program 26.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-+26.6

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

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

      \[\leadsto \color{blue}{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \frac{1}{2 \cdot a}}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity16.4

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(0 + 4 \cdot \left(a \cdot c\right)\right)}}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)} \cdot \frac{1}{2 \cdot a}\]
    10. Applied times-frac16.4

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

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

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

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

    if 3461964491124549.0 < b

    1. Initial program 55.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.71711085460076329 \cdot 10^{118}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.9300475349170912 \cdot 10^{-278}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3461964491124549:\\ \;\;\;\;1 \cdot \frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020027 +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)))