Average Error: 33.4 → 10.5
Time: 26.3s
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 -227369802444031.66:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\ \mathbf{elif}\;b_2 \le 2.0617732603635578 \cdot 10^{-61}:\\ \;\;\;\;\left(\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2\right) \cdot \frac{1}{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 -227369802444031.66:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\

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

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

\end{array}
double f(double a, double b_2, double c) {
        double r648227 = b_2;
        double r648228 = -r648227;
        double r648229 = r648227 * r648227;
        double r648230 = a;
        double r648231 = c;
        double r648232 = r648230 * r648231;
        double r648233 = r648229 - r648232;
        double r648234 = sqrt(r648233);
        double r648235 = r648228 + r648234;
        double r648236 = r648235 / r648230;
        return r648236;
}

double f(double a, double b_2, double c) {
        double r648237 = b_2;
        double r648238 = -227369802444031.66;
        bool r648239 = r648237 <= r648238;
        double r648240 = -2.0;
        double r648241 = a;
        double r648242 = r648237 / r648241;
        double r648243 = 0.5;
        double r648244 = c;
        double r648245 = r648244 / r648237;
        double r648246 = r648243 * r648245;
        double r648247 = fma(r648240, r648242, r648246);
        double r648248 = 2.0617732603635578e-61;
        bool r648249 = r648237 <= r648248;
        double r648250 = r648237 * r648237;
        double r648251 = r648244 * r648241;
        double r648252 = r648250 - r648251;
        double r648253 = sqrt(r648252);
        double r648254 = r648253 - r648237;
        double r648255 = 1.0;
        double r648256 = r648255 / r648241;
        double r648257 = r648254 * r648256;
        double r648258 = -0.5;
        double r648259 = r648245 * r648258;
        double r648260 = r648249 ? r648257 : r648259;
        double r648261 = r648239 ? r648247 : r648260;
        return r648261;
}

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 < -227369802444031.66

    1. Initial program 32.9

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

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

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

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

    if -227369802444031.66 < b_2 < 2.0617732603635578e-61

    1. Initial program 15.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    3. Using strategy rm
    4. Applied clear-num15.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 *-un-lft-identity15.0

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

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

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

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

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

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

      \[\leadsto 1 \cdot \color{blue}{\frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}}\]
    13. Using strategy rm
    14. Applied div-inv15.1

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

    if 2.0617732603635578e-61 < b_2

    1. Initial program 52.8

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

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

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

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

Reproduce

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