Average Error: 33.5 → 9.0
Time: 18.7s
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(\frac{b_2}{a}, -2, \frac{\frac{1}{2} \cdot c}{b_2}\right)\\ \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)}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}}{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(\frac{b_2}{a}, -2, \frac{\frac{1}{2} \cdot c}{b_2}\right)\\

\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)}{b_2 + \sqrt{b_2 \cdot b_2 - a \cdot c}}}{a}\\

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

\end{array}
double f(double a, double b_2, double c) {
        double r758536 = b_2;
        double r758537 = -r758536;
        double r758538 = r758536 * r758536;
        double r758539 = a;
        double r758540 = c;
        double r758541 = r758539 * r758540;
        double r758542 = r758538 - r758541;
        double r758543 = sqrt(r758542);
        double r758544 = r758537 + r758543;
        double r758545 = r758544 / r758539;
        return r758545;
}

double f(double a, double b_2, double c) {
        double r758546 = b_2;
        double r758547 = -5.300564053552496e+135;
        bool r758548 = r758546 <= r758547;
        double r758549 = a;
        double r758550 = r758546 / r758549;
        double r758551 = -2.0;
        double r758552 = 0.5;
        double r758553 = c;
        double r758554 = r758552 * r758553;
        double r758555 = r758554 / r758546;
        double r758556 = fma(r758550, r758551, r758555);
        double r758557 = 3.318234109021414e-122;
        bool r758558 = r758546 <= r758557;
        double r758559 = r758546 * r758546;
        double r758560 = r758549 * r758553;
        double r758561 = r758559 - r758560;
        double r758562 = sqrt(r758561);
        double r758563 = r758562 - r758546;
        double r758564 = 1.0;
        double r758565 = r758564 / r758549;
        double r758566 = r758563 * r758565;
        double r758567 = 13471615.147294592;
        bool r758568 = r758546 <= r758567;
        double r758569 = -r758549;
        double r758570 = 0.0;
        double r758571 = fma(r758553, r758569, r758570);
        double r758572 = r758546 + r758562;
        double r758573 = r758571 / r758572;
        double r758574 = r758573 / r758549;
        double r758575 = -0.5;
        double r758576 = r758553 / r758546;
        double r758577 = r758575 * r758576;
        double r758578 = r758568 ? r758574 : r758577;
        double r758579 = r758558 ? r758566 : r758578;
        double r758580 = r758548 ? r758556 : r758579;
        return r758580;
}

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. Using strategy rm
    4. Applied div-inv54.8

      \[\leadsto \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}}\]
    5. Taylor expanded around -inf 2.4

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

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