Average Error: 33.8 → 6.8
Time: 7.5s
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.12428337420519208 \cdot 10^{57}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.6559623908913229 \cdot 10^{-256}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 4.1445535679869069 \cdot 10^{60}:\\ \;\;\;\;\frac{1}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{0.5}{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.12428337420519208 \cdot 10^{57}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 4.1445535679869069 \cdot 10^{60}:\\
\;\;\;\;\frac{1}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{0.5}{c}}\\

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

\end{array}
double f(double a, double b, double c) {
        double r35510 = b;
        double r35511 = -r35510;
        double r35512 = r35510 * r35510;
        double r35513 = 4.0;
        double r35514 = a;
        double r35515 = r35513 * r35514;
        double r35516 = c;
        double r35517 = r35515 * r35516;
        double r35518 = r35512 - r35517;
        double r35519 = sqrt(r35518);
        double r35520 = r35511 + r35519;
        double r35521 = 2.0;
        double r35522 = r35521 * r35514;
        double r35523 = r35520 / r35522;
        return r35523;
}

double f(double a, double b, double c) {
        double r35524 = b;
        double r35525 = -3.124283374205192e+57;
        bool r35526 = r35524 <= r35525;
        double r35527 = 1.0;
        double r35528 = c;
        double r35529 = r35528 / r35524;
        double r35530 = a;
        double r35531 = r35524 / r35530;
        double r35532 = r35529 - r35531;
        double r35533 = r35527 * r35532;
        double r35534 = -2.655962390891323e-256;
        bool r35535 = r35524 <= r35534;
        double r35536 = -r35524;
        double r35537 = r35524 * r35524;
        double r35538 = 4.0;
        double r35539 = r35538 * r35530;
        double r35540 = r35539 * r35528;
        double r35541 = r35537 - r35540;
        double r35542 = sqrt(r35541);
        double r35543 = r35536 + r35542;
        double r35544 = 2.0;
        double r35545 = r35544 * r35530;
        double r35546 = r35543 / r35545;
        double r35547 = 4.144553567986907e+60;
        bool r35548 = r35524 <= r35547;
        double r35549 = 1.0;
        double r35550 = r35530 * r35528;
        double r35551 = r35538 * r35550;
        double r35552 = r35537 - r35551;
        double r35553 = sqrt(r35552);
        double r35554 = r35536 - r35553;
        double r35555 = 0.5;
        double r35556 = r35555 / r35528;
        double r35557 = r35554 * r35556;
        double r35558 = r35549 / r35557;
        double r35559 = -1.0;
        double r35560 = r35559 * r35529;
        double r35561 = r35548 ? r35558 : r35560;
        double r35562 = r35535 ? r35546 : r35561;
        double r35563 = r35526 ? r35533 : r35562;
        return r35563;
}

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.8
Target20.4
Herbie6.8
\[\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.124283374205192e+57

    1. Initial program 39.5

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

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

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

    if -3.124283374205192e+57 < b < -2.655962390891323e-256

    1. Initial program 8.1

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

    if -2.655962390891323e-256 < b < 4.144553567986907e+60

    1. Initial program 28.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-+28.5

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

      \[\leadsto \frac{\frac{\color{blue}{b \cdot \left(b - b\right) + 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 *-un-lft-identity16.8

      \[\leadsto \frac{\frac{b \cdot \left(b - b\right) + 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)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity16.8

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(b \cdot \left(b - b\right) + 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)}}{2 \cdot a}\]
    8. Applied times-frac16.8

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

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

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

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

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

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

    if 4.144553567986907e+60 < b

    1. Initial program 58.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.12428337420519208 \cdot 10^{57}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -2.6559623908913229 \cdot 10^{-256}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 4.1445535679869069 \cdot 10^{60}:\\ \;\;\;\;\frac{1}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{0.5}{c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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