Average Error: 33.5 → 9.0
Time: 18.0s
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 -5.300564053552496 \cdot 10^{+135}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{c}{b_2} \cdot \frac{1}{2}\right)\\ \mathbf{elif}\;b_2 \le 3.318234109021414 \cdot 10^{-122}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2\right) \cdot \frac{1}{a}\\ \mathbf{elif}\;b_2 \le 13471615.147294592:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(a, -c, 0\right)}{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}}{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 -5.300564053552496 \cdot 10^{+135}:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{c}{b_2} \cdot \frac{1}{2}\right)\\

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

\mathbf{elif}\;b_2 \le 13471615.147294592:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, -c, 0\right)}{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}}{a}\\

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

\end{array}
double f(double a, double b_2, double c) {
        double r696636 = b_2;
        double r696637 = -r696636;
        double r696638 = r696636 * r696636;
        double r696639 = a;
        double r696640 = c;
        double r696641 = r696639 * r696640;
        double r696642 = r696638 - r696641;
        double r696643 = sqrt(r696642);
        double r696644 = r696637 + r696643;
        double r696645 = r696644 / r696639;
        return r696645;
}

double f(double a, double b_2, double c) {
        double r696646 = b_2;
        double r696647 = -5.300564053552496e+135;
        bool r696648 = r696646 <= r696647;
        double r696649 = -2.0;
        double r696650 = a;
        double r696651 = r696646 / r696650;
        double r696652 = c;
        double r696653 = r696652 / r696646;
        double r696654 = 0.5;
        double r696655 = r696653 * r696654;
        double r696656 = fma(r696649, r696651, r696655);
        double r696657 = 3.318234109021414e-122;
        bool r696658 = r696646 <= r696657;
        double r696659 = r696646 * r696646;
        double r696660 = r696652 * r696650;
        double r696661 = r696659 - r696660;
        double r696662 = sqrt(r696661);
        double r696663 = r696662 - r696646;
        double r696664 = 1.0;
        double r696665 = r696664 / r696650;
        double r696666 = r696663 * r696665;
        double r696667 = 13471615.147294592;
        bool r696668 = r696646 <= r696667;
        double r696669 = -r696652;
        double r696670 = 0.0;
        double r696671 = fma(r696650, r696669, r696670);
        double r696672 = r696646 + r696662;
        double r696673 = r696671 / r696672;
        double r696674 = r696673 / r696650;
        double r696675 = -0.5;
        double r696676 = r696675 * r696653;
        double r696677 = r696668 ? r696674 : r696676;
        double r696678 = r696658 ? r696666 : r696677;
        double r696679 = r696648 ? r696656 : r696678;
        return r696679;
}

Error

Bits error versus a

Bits error versus b_2

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b_2 < -5.300564053552496e+135

    1. Initial program 54.8

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

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

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

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

    if -5.300564053552496e+135 < b_2 < 3.318234109021414e-122

    1. Initial program 11.9

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

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

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

    if 3.318234109021414e-122 < b_2 < 13471615.147294592

    1. Initial program 33.7

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt33.7

      \[\leadsto \frac{\sqrt{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} \cdot \sqrt{b_2 \cdot b_2 - a \cdot c}}} - b_2}{a}\]
    5. Applied sqrt-prod34.0

      \[\leadsto \frac{\color{blue}{\sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}} \cdot \sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}} - b_2}{a}\]
    6. Applied fma-neg34.1

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}, \sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}, -b_2\right)}}{a}\]
    7. Using strategy rm
    8. Applied add-exp-log36.6

      \[\leadsto \frac{\color{blue}{e^{\log \left(\mathsf{fma}\left(\sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}, \sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}, -b_2\right)\right)}}}{a}\]
    9. Simplified36.1

      \[\leadsto \frac{e^{\color{blue}{\log \left(\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2\right)}}}{a}\]
    10. Using strategy rm
    11. Applied flip--36.2

      \[\leadsto \frac{e^{\log \color{blue}{\left(\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} \cdot \sqrt{b_2 \cdot b_2 - c \cdot a} - b_2 \cdot b_2}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2}\right)}}}{a}\]
    12. Applied log-div36.2

      \[\leadsto \frac{e^{\color{blue}{\log \left(\sqrt{b_2 \cdot b_2 - c \cdot a} \cdot \sqrt{b_2 \cdot b_2 - c \cdot a} - b_2 \cdot b_2\right) - \log \left(\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2\right)}}}{a}\]
    13. Applied exp-diff36.3

      \[\leadsto \frac{\color{blue}{\frac{e^{\log \left(\sqrt{b_2 \cdot b_2 - c \cdot a} \cdot \sqrt{b_2 \cdot b_2 - c \cdot a} - b_2 \cdot b_2\right)}}{e^{\log \left(\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2\right)}}}}{a}\]
    14. Simplified18.4

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(a, -c, 0\right)}}{e^{\log \left(\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2\right)}}}{a}\]
    15. Simplified15.7

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

    if 13471615.147294592 < b_2

    1. Initial program 55.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -5.300564053552496 \cdot 10^{+135}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{c}{b_2} \cdot \frac{1}{2}\right)\\ \mathbf{elif}\;b_2 \le 3.318234109021414 \cdot 10^{-122}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2\right) \cdot \frac{1}{a}\\ \mathbf{elif}\;b_2 \le 13471615.147294592:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(a, -c, 0\right)}{b_2 + \sqrt{b_2 \cdot b_2 - c \cdot a}}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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