Average Error: 33.7 → 9.5
Time: 19.4s
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.739519777490095733488952130644039307968 \cdot 10^{139}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{b_2}, \frac{1}{2}, -2 \cdot \frac{b_2}{a}\right)\\ \mathbf{elif}\;b_2 \le 1.857168791023148873006570039361439890702 \cdot 10^{-47}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \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.739519777490095733488952130644039307968 \cdot 10^{139}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b_2}, \frac{1}{2}, -2 \cdot \frac{b_2}{a}\right)\\

\mathbf{elif}\;b_2 \le 1.857168791023148873006570039361439890702 \cdot 10^{-47}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\

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

\end{array}
double f(double a, double b_2, double c) {
        double r24689 = b_2;
        double r24690 = -r24689;
        double r24691 = r24689 * r24689;
        double r24692 = a;
        double r24693 = c;
        double r24694 = r24692 * r24693;
        double r24695 = r24691 - r24694;
        double r24696 = sqrt(r24695);
        double r24697 = r24690 + r24696;
        double r24698 = r24697 / r24692;
        return r24698;
}

double f(double a, double b_2, double c) {
        double r24699 = b_2;
        double r24700 = -4.7395197774900957e+139;
        bool r24701 = r24699 <= r24700;
        double r24702 = c;
        double r24703 = r24702 / r24699;
        double r24704 = 0.5;
        double r24705 = -2.0;
        double r24706 = a;
        double r24707 = r24699 / r24706;
        double r24708 = r24705 * r24707;
        double r24709 = fma(r24703, r24704, r24708);
        double r24710 = 1.8571687910231489e-47;
        bool r24711 = r24699 <= r24710;
        double r24712 = r24699 * r24699;
        double r24713 = r24706 * r24702;
        double r24714 = r24712 - r24713;
        double r24715 = sqrt(r24714);
        double r24716 = r24715 - r24699;
        double r24717 = r24716 / r24706;
        double r24718 = -0.5;
        double r24719 = r24718 * r24703;
        double r24720 = r24711 ? r24717 : r24719;
        double r24721 = r24701 ? r24709 : r24720;
        return r24721;
}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b_2 < -4.7395197774900957e+139

    1. Initial program 58.8

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified58.8

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Taylor expanded around -inf 2.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{b_2}, \frac{1}{2}, -2 \cdot \frac{b_2}{a}\right)}\]

    if -4.7395197774900957e+139 < b_2 < 1.8571687910231489e-47

    1. Initial program 12.9

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified12.9

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied clear-num13.0

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}}\]
    5. Using strategy rm
    6. Applied div-inv13.1

      \[\leadsto \frac{1}{\color{blue}{a \cdot \frac{1}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}}\]
    7. Applied add-cube-cbrt13.1

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

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{a} \cdot \frac{\sqrt[3]{1}}{\frac{1}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}}\]
    9. Simplified13.1

      \[\leadsto \color{blue}{\frac{1}{a}} \cdot \frac{\sqrt[3]{1}}{\frac{1}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}\]
    10. Simplified13.0

      \[\leadsto \frac{1}{a} \cdot \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right)}\]
    11. Using strategy rm
    12. Applied *-un-lft-identity13.0

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

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

      \[\leadsto \color{blue}{\left(\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{1} \cdot \frac{\sqrt[3]{1}}{a}\right)} \cdot \left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right)\]
    15. Applied associate-*l*13.0

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

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

    if 1.8571687910231489e-47 < b_2

    1. Initial program 53.7

      \[\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}\]
    2. Simplified53.7

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Taylor expanded around inf 7.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -4.739519777490095733488952130644039307968 \cdot 10^{139}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{b_2}, \frac{1}{2}, -2 \cdot \frac{b_2}{a}\right)\\ \mathbf{elif}\;b_2 \le 1.857168791023148873006570039361439890702 \cdot 10^{-47}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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