Average Error: 33.5 → 11.9
Time: 23.5s
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.3725796156555912 \cdot 10^{+127}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\ \mathbf{elif}\;b_2 \le 3.207624111695675 \cdot 10^{-187}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b_2, b_2, \left(-a\right) \cdot c\right)} - b_2}{a}\\ \mathbf{elif}\;b_2 \le 4.664677641347216 \cdot 10^{-111}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \le 1.922674299151799 \cdot 10^{-16}:\\ \;\;\;\;\frac{1}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2} \cdot \frac{\left(b_2 \cdot b_2 - c \cdot a\right) - b_2 \cdot 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 -1.3725796156555912 \cdot 10^{+127}:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\

\mathbf{elif}\;b_2 \le 3.207624111695675 \cdot 10^{-187}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b_2, b_2, \left(-a\right) \cdot c\right)} - b_2}{a}\\

\mathbf{elif}\;b_2 \le 4.664677641347216 \cdot 10^{-111}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\

\mathbf{elif}\;b_2 \le 1.922674299151799 \cdot 10^{-16}:\\
\;\;\;\;\frac{1}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2} \cdot \frac{\left(b_2 \cdot b_2 - c \cdot a\right) - b_2 \cdot 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 r538067 = b_2;
        double r538068 = -r538067;
        double r538069 = r538067 * r538067;
        double r538070 = a;
        double r538071 = c;
        double r538072 = r538070 * r538071;
        double r538073 = r538069 - r538072;
        double r538074 = sqrt(r538073);
        double r538075 = r538068 + r538074;
        double r538076 = r538075 / r538070;
        return r538076;
}

double f(double a, double b_2, double c) {
        double r538077 = b_2;
        double r538078 = -1.3725796156555912e+127;
        bool r538079 = r538077 <= r538078;
        double r538080 = -2.0;
        double r538081 = a;
        double r538082 = r538077 / r538081;
        double r538083 = 0.5;
        double r538084 = c;
        double r538085 = r538084 / r538077;
        double r538086 = r538083 * r538085;
        double r538087 = fma(r538080, r538082, r538086);
        double r538088 = 3.207624111695675e-187;
        bool r538089 = r538077 <= r538088;
        double r538090 = -r538081;
        double r538091 = r538090 * r538084;
        double r538092 = fma(r538077, r538077, r538091);
        double r538093 = sqrt(r538092);
        double r538094 = r538093 - r538077;
        double r538095 = r538094 / r538081;
        double r538096 = 4.664677641347216e-111;
        bool r538097 = r538077 <= r538096;
        double r538098 = -0.5;
        double r538099 = r538098 * r538085;
        double r538100 = 1.922674299151799e-16;
        bool r538101 = r538077 <= r538100;
        double r538102 = 1.0;
        double r538103 = r538077 * r538077;
        double r538104 = r538084 * r538081;
        double r538105 = r538103 - r538104;
        double r538106 = sqrt(r538105);
        double r538107 = r538106 + r538077;
        double r538108 = r538102 / r538107;
        double r538109 = r538105 - r538103;
        double r538110 = r538109 / r538081;
        double r538111 = r538108 * r538110;
        double r538112 = r538101 ? r538111 : r538099;
        double r538113 = r538097 ? r538099 : r538112;
        double r538114 = r538089 ? r538095 : r538113;
        double r538115 = r538079 ? r538087 : r538114;
        return r538115;
}

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.3725796156555912e+127

    1. Initial program 51.4

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

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

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

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

    if -1.3725796156555912e+127 < b_2 < 3.207624111695675e-187

    1. Initial program 10.4

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

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

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

    if 3.207624111695675e-187 < b_2 < 4.664677641347216e-111 or 1.922674299151799e-16 < b_2

    1. Initial program 50.0

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

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

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

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

    if 4.664677641347216e-111 < b_2 < 1.922674299151799e-16

    1. Initial program 36.4

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{\mathsf{fma}\left(b_2, b_2, -a \cdot c\right)}} - b_2}{a}\]
    5. Using strategy rm
    6. Applied clear-num36.4

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

      \[\leadsto \frac{1}{\color{blue}{\frac{a}{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}}}\]
    8. Using strategy rm
    9. Applied flip--36.5

      \[\leadsto \frac{1}{\frac{a}{\color{blue}{\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}}}}\]
    10. Applied associate-/r/36.5

      \[\leadsto \frac{1}{\color{blue}{\frac{a}{\sqrt{b_2 \cdot b_2 - c \cdot a} \cdot \sqrt{b_2 \cdot b_2 - c \cdot a} - b_2 \cdot b_2} \cdot \left(\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2\right)}}\]
    11. Applied add-sqr-sqrt36.5

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\frac{a}{\sqrt{b_2 \cdot b_2 - c \cdot a} \cdot \sqrt{b_2 \cdot b_2 - c \cdot a} - b_2 \cdot b_2} \cdot \left(\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2\right)}\]
    12. Applied times-frac36.5

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{\frac{a}{\sqrt{b_2 \cdot b_2 - c \cdot a} \cdot \sqrt{b_2 \cdot b_2 - c \cdot a} - b_2 \cdot b_2}} \cdot \frac{\sqrt{1}}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2}}\]
    13. Simplified36.4

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

      \[\leadsto \frac{\left(b_2 \cdot b_2 - c \cdot a\right) - b_2 \cdot b_2}{a} \cdot \color{blue}{\frac{1}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -1.3725796156555912 \cdot 10^{+127}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\ \mathbf{elif}\;b_2 \le 3.207624111695675 \cdot 10^{-187}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b_2, b_2, \left(-a\right) \cdot c\right)} - b_2}{a}\\ \mathbf{elif}\;b_2 \le 4.664677641347216 \cdot 10^{-111}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \mathbf{elif}\;b_2 \le 1.922674299151799 \cdot 10^{-16}:\\ \;\;\;\;\frac{1}{\sqrt{b_2 \cdot b_2 - c \cdot a} + b_2} \cdot \frac{\left(b_2 \cdot b_2 - c \cdot a\right) - b_2 \cdot b_2}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b_2}\\ \end{array}\]

Reproduce

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