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

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

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

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

\end{array}
double f(double a, double b_2, double c) {
        double r714065 = b_2;
        double r714066 = -r714065;
        double r714067 = r714065 * r714065;
        double r714068 = a;
        double r714069 = c;
        double r714070 = r714068 * r714069;
        double r714071 = r714067 - r714070;
        double r714072 = sqrt(r714071);
        double r714073 = r714066 + r714072;
        double r714074 = r714073 / r714068;
        return r714074;
}

double f(double a, double b_2, double c) {
        double r714075 = b_2;
        double r714076 = -1.1167958442014868e+136;
        bool r714077 = r714075 <= r714076;
        double r714078 = -2.0;
        double r714079 = r714078 * r714075;
        double r714080 = a;
        double r714081 = r714079 / r714080;
        double r714082 = 3.318234109021414e-122;
        bool r714083 = r714075 <= r714082;
        double r714084 = r714075 * r714075;
        double r714085 = c;
        double r714086 = r714080 * r714085;
        double r714087 = r714084 - r714086;
        double r714088 = sqrt(r714087);
        double r714089 = r714088 - r714075;
        double r714090 = 1.0;
        double r714091 = r714090 / r714080;
        double r714092 = r714089 * r714091;
        double r714093 = 13471615.147294592;
        bool r714094 = r714075 <= r714093;
        double r714095 = -r714080;
        double r714096 = 0.0;
        double r714097 = fma(r714085, r714095, r714096);
        double r714098 = r714088 + r714075;
        double r714099 = r714097 / r714098;
        double r714100 = r714099 / r714080;
        double r714101 = r714085 / r714075;
        double r714102 = -0.5;
        double r714103 = r714101 * r714102;
        double r714104 = r714094 ? r714100 : r714103;
        double r714105 = r714083 ? r714092 : r714104;
        double r714106 = r714077 ? r714081 : r714105;
        return r714106;
}

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 < -1.1167958442014868e+136

    1. Initial program 54.9

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

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

      \[\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-prod54.9

      \[\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-neg54.9

      \[\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. Taylor expanded around -inf 2.6

      \[\leadsto \frac{\color{blue}{-2 \cdot b_2}}{a}\]
    8. Simplified2.6

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

    if -1.1167958442014868e+136 < 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-exp-log36.1

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

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

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

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

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

      \[\leadsto \frac{\frac{\mathsf{fma}\left(c, -a, 0\right)}{\color{blue}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}}}{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.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -1.1167958442014868 \cdot 10^{+136}:\\ \;\;\;\;\frac{-2 \cdot b_2}{a}\\ \mathbf{elif}\;b_2 \le 3.318234109021414 \cdot 10^{-122}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}\\ \mathbf{elif}\;b_2 \le 13471615.147294592:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(c, -a, 0\right)}{\sqrt{b_2 \cdot b_2 - a \cdot c} + b_2}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b_2} \cdot \frac{-1}{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))