Average Error: 34.1 → 7.0
Time: 5.7s
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 -2.223763057046510327568967152287533282505 \cdot 10^{109}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.319380566438366601816459280349243307141 \cdot 10^{-186}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{elif}\;b \le 1.02738286211209785784187544728837722875 \cdot 10^{63}:\\ \;\;\;\;\frac{\frac{\frac{1}{\frac{2}{4}}}{\frac{1}{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 -2.223763057046510327568967152287533282505 \cdot 10^{109}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 1.02738286211209785784187544728837722875 \cdot 10^{63}:\\
\;\;\;\;\frac{\frac{\frac{1}{\frac{2}{4}}}{\frac{1}{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 r160575 = b;
        double r160576 = -r160575;
        double r160577 = r160575 * r160575;
        double r160578 = 4.0;
        double r160579 = a;
        double r160580 = r160578 * r160579;
        double r160581 = c;
        double r160582 = r160580 * r160581;
        double r160583 = r160577 - r160582;
        double r160584 = sqrt(r160583);
        double r160585 = r160576 + r160584;
        double r160586 = 2.0;
        double r160587 = r160586 * r160579;
        double r160588 = r160585 / r160587;
        return r160588;
}

double f(double a, double b, double c) {
        double r160589 = b;
        double r160590 = -2.2237630570465103e+109;
        bool r160591 = r160589 <= r160590;
        double r160592 = 1.0;
        double r160593 = c;
        double r160594 = r160593 / r160589;
        double r160595 = a;
        double r160596 = r160589 / r160595;
        double r160597 = r160594 - r160596;
        double r160598 = r160592 * r160597;
        double r160599 = -3.3193805664383666e-186;
        bool r160600 = r160589 <= r160599;
        double r160601 = -r160589;
        double r160602 = r160589 * r160589;
        double r160603 = 4.0;
        double r160604 = r160603 * r160595;
        double r160605 = r160604 * r160593;
        double r160606 = r160602 - r160605;
        double r160607 = sqrt(r160606);
        double r160608 = r160601 + r160607;
        double r160609 = sqrt(r160608);
        double r160610 = 2.0;
        double r160611 = r160609 / r160610;
        double r160612 = r160609 / r160595;
        double r160613 = r160611 * r160612;
        double r160614 = 1.0273828621120979e+63;
        bool r160615 = r160589 <= r160614;
        double r160616 = 1.0;
        double r160617 = r160610 / r160603;
        double r160618 = r160616 / r160617;
        double r160619 = r160616 / r160593;
        double r160620 = r160618 / r160619;
        double r160621 = r160601 - r160607;
        double r160622 = r160620 / r160621;
        double r160623 = -1.0;
        double r160624 = r160623 * r160594;
        double r160625 = r160615 ? r160622 : r160624;
        double r160626 = r160600 ? r160613 : r160625;
        double r160627 = r160591 ? r160598 : r160626;
        return r160627;
}

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.1
Target20.9
Herbie7.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 < -2.2237630570465103e+109

    1. Initial program 48.6

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

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

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

    if -2.2237630570465103e+109 < b < -3.3193805664383666e-186

    1. Initial program 6.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt7.3

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

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

    if -3.3193805664383666e-186 < b < 1.0273828621120979e+63

    1. Initial program 27.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-+27.7

      \[\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. Simplified17.0

      \[\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 *-un-lft-identity17.0

      \[\leadsto \frac{\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)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity17.0

      \[\leadsto \frac{\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)}}{2 \cdot a}\]
    8. Applied times-frac17.0

      \[\leadsto \frac{\color{blue}{\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}}}}{2 \cdot a}\]
    9. Applied associate-/l*17.1

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

      \[\leadsto \frac{\frac{1}{1}}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    11. Using strategy rm
    12. Applied times-frac16.8

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

      \[\leadsto \frac{\frac{1}{1}}{\left(\frac{2}{4} \cdot \color{blue}{\frac{1}{c}}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    14. Using strategy rm
    15. Applied associate-/r*11.0

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

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

    if 1.0273828621120979e+63 < b

    1. Initial program 57.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.223763057046510327568967152287533282505 \cdot 10^{109}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.319380566438366601816459280349243307141 \cdot 10^{-186}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2} \cdot \frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{a}\\ \mathbf{elif}\;b \le 1.02738286211209785784187544728837722875 \cdot 10^{63}:\\ \;\;\;\;\frac{\frac{\frac{1}{\frac{2}{4}}}{\frac{1}{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 2020001 +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)))