Average Error: 32.9 → 10.3
Time: 19.1s
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 -9.088000531423294 \cdot 10^{+152}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{b_2}, \frac{1}{2}, -2 \cdot \frac{b_2}{a}\right)\\ \mathbf{elif}\;b_2 \le 9.354082991670835 \cdot 10^{-125}:\\ \;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - 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 -9.088000531423294 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b_2}, \frac{1}{2}, -2 \cdot \frac{b_2}{a}\right)\\

\mathbf{elif}\;b_2 \le 9.354082991670835 \cdot 10^{-125}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - c \cdot a} - 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 r384945 = b_2;
        double r384946 = -r384945;
        double r384947 = r384945 * r384945;
        double r384948 = a;
        double r384949 = c;
        double r384950 = r384948 * r384949;
        double r384951 = r384947 - r384950;
        double r384952 = sqrt(r384951);
        double r384953 = r384946 + r384952;
        double r384954 = r384953 / r384948;
        return r384954;
}

double f(double a, double b_2, double c) {
        double r384955 = b_2;
        double r384956 = -9.088000531423294e+152;
        bool r384957 = r384955 <= r384956;
        double r384958 = c;
        double r384959 = r384958 / r384955;
        double r384960 = 0.5;
        double r384961 = -2.0;
        double r384962 = a;
        double r384963 = r384955 / r384962;
        double r384964 = r384961 * r384963;
        double r384965 = fma(r384959, r384960, r384964);
        double r384966 = 9.354082991670835e-125;
        bool r384967 = r384955 <= r384966;
        double r384968 = r384955 * r384955;
        double r384969 = r384958 * r384962;
        double r384970 = r384968 - r384969;
        double r384971 = sqrt(r384970);
        double r384972 = r384971 - r384955;
        double r384973 = r384972 / r384962;
        double r384974 = -0.5;
        double r384975 = r384959 * r384974;
        double r384976 = r384967 ? r384973 : r384975;
        double r384977 = r384957 ? r384965 : r384976;
        return r384977;
}

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 < -9.088000531423294e+152

    1. Initial program 60.5

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

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

      \[\leadsto \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}}\]
    5. Using strategy rm
    6. Applied associate-*r/60.5

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

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{c}{b_2} - 2 \cdot \frac{b_2}{a}}\]
    9. Simplified1.5

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

    if -9.088000531423294e+152 < b_2 < 9.354082991670835e-125

    1. Initial program 10.9

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

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

      \[\leadsto \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}}\]
    5. Using strategy rm
    6. Applied associate-*r/10.9

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

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

    if 9.354082991670835e-125 < b_2

    1. Initial program 49.8

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

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

      \[\leadsto \color{blue}{\left(\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2\right) \cdot \frac{1}{a}}\]
    5. Using strategy rm
    6. Applied associate-*r/49.8

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

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

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

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

Reproduce

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