Average Error: 34.6 → 10.0
Time: 6.1s
Precision: 64
\[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
\[\begin{array}{l} \mathbf{if}\;b_2 \le -4.706781135059311758856471716413486308072 \cdot 10^{-92}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le 6.385814412780331293336851171468331234192 \cdot 10^{98}:\\ \;\;\;\;\frac{1}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}} \cdot c\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
\mathbf{if}\;b_2 \le -4.706781135059311758856471716413486308072 \cdot 10^{-92}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\

\mathbf{elif}\;b_2 \le 6.385814412780331293336851171468331234192 \cdot 10^{98}:\\
\;\;\;\;\frac{1}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}} \cdot c\\

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

\end{array}
double f(double a, double b_2, double c) {
        double r20239 = b_2;
        double r20240 = -r20239;
        double r20241 = r20239 * r20239;
        double r20242 = a;
        double r20243 = c;
        double r20244 = r20242 * r20243;
        double r20245 = r20241 - r20244;
        double r20246 = sqrt(r20245);
        double r20247 = r20240 + r20246;
        double r20248 = r20247 / r20242;
        return r20248;
}

double f(double a, double b_2, double c) {
        double r20249 = b_2;
        double r20250 = -4.706781135059312e-92;
        bool r20251 = r20249 <= r20250;
        double r20252 = 0.5;
        double r20253 = c;
        double r20254 = r20253 / r20249;
        double r20255 = r20252 * r20254;
        double r20256 = 2.0;
        double r20257 = a;
        double r20258 = r20249 / r20257;
        double r20259 = r20256 * r20258;
        double r20260 = r20255 - r20259;
        double r20261 = 6.385814412780331e+98;
        bool r20262 = r20249 <= r20261;
        double r20263 = 1.0;
        double r20264 = -r20249;
        double r20265 = r20249 * r20249;
        double r20266 = r20257 * r20253;
        double r20267 = r20265 - r20266;
        double r20268 = sqrt(r20267);
        double r20269 = r20264 - r20268;
        double r20270 = r20263 / r20269;
        double r20271 = r20270 * r20253;
        double r20272 = -0.5;
        double r20273 = r20272 * r20254;
        double r20274 = r20262 ? r20271 : r20273;
        double r20275 = r20251 ? r20260 : r20274;
        return r20275;
}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b_2 < -4.706781135059312e-92

    1. Initial program 26.6

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}}\]

    if -4.706781135059312e-92 < b_2 < 6.385814412780331e+98

    1. Initial program 26.4

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Using strategy rm
    3. Applied flip-+28.7

      \[\leadsto \frac{\color{blue}{\frac{\left(-b_2\right) \cdot \left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c}}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}}}{a}\]
    4. Simplified17.8

      \[\leadsto \frac{\frac{\color{blue}{0 + a \cdot c}}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}}{a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity17.8

      \[\leadsto \frac{\frac{0 + a \cdot c}{\color{blue}{1 \cdot \left(\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}\right)}}}{a}\]
    7. Applied *-un-lft-identity17.8

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(0 + a \cdot c\right)}}{1 \cdot \left(\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}\right)}}{a}\]
    8. Applied times-frac17.8

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{0 + a \cdot c}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}}}{a}\]
    9. Simplified17.8

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

      \[\leadsto \frac{1 \cdot \color{blue}{\frac{a}{\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{c}}}}{a}\]
    11. Using strategy rm
    12. Applied clear-num16.2

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{1 \cdot \frac{a}{\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}{c}}}}}\]
    13. Simplified12.5

      \[\leadsto \frac{1}{\color{blue}{\frac{1 \cdot \left(\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}\right)}{c}}}\]
    14. Using strategy rm
    15. Applied div-inv12.6

      \[\leadsto \frac{1}{\color{blue}{\left(1 \cdot \left(\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}\right)\right) \cdot \frac{1}{c}}}\]
    16. Applied add-cube-cbrt12.6

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\left(1 \cdot \left(\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}\right)\right) \cdot \frac{1}{c}}\]
    17. Applied times-frac12.4

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{1 \cdot \left(\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}\right)} \cdot \frac{\sqrt[3]{1}}{\frac{1}{c}}}\]
    18. Simplified12.4

      \[\leadsto \color{blue}{\frac{1}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}}} \cdot \frac{\sqrt[3]{1}}{\frac{1}{c}}\]
    19. Simplified12.3

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

    if 6.385814412780331e+98 < b_2

    1. Initial program 59.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -4.706781135059311758856471716413486308072 \cdot 10^{-92}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}\\ \mathbf{elif}\;b_2 \le 6.385814412780331293336851171468331234192 \cdot 10^{98}:\\ \;\;\;\;\frac{1}{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - a \cdot c}} \cdot c\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019353 +o rules:numerics
(FPCore (a b_2 c)
  :name "quad2p (problem 3.2.1, positive)"
  :precision binary64
  (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))