Average Error: 33.8 → 9.7
Time: 15.6s
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.4758305599808076 \cdot 10^{+144}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\ \mathbf{elif}\;b_2 \le 1.739098950628615 \cdot 10^{-79}:\\ \;\;\;\;\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}}\\ \mathbf{elif}\;b_2 \le 1.8656332031849816 \cdot 10^{-25}:\\ \;\;\;\;\frac{c}{b_2} \cdot \frac{-1}{2}\\ \mathbf{elif}\;b_2 \le 5.297236684235463 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{\left(b_2 \cdot b_2 - c \cdot a\right) - b_2 \cdot b_2}{\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 -1.4758305599808076 \cdot 10^{+144}:\\
\;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\

\mathbf{elif}\;b_2 \le 1.739098950628615 \cdot 10^{-79}:\\
\;\;\;\;\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}}\\

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

\mathbf{elif}\;b_2 \le 5.297236684235463 \cdot 10^{-16}:\\
\;\;\;\;\frac{\frac{\left(b_2 \cdot b_2 - c \cdot a\right) - b_2 \cdot b_2}{\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 r390989 = b_2;
        double r390990 = -r390989;
        double r390991 = r390989 * r390989;
        double r390992 = a;
        double r390993 = c;
        double r390994 = r390992 * r390993;
        double r390995 = r390991 - r390994;
        double r390996 = sqrt(r390995);
        double r390997 = r390990 + r390996;
        double r390998 = r390997 / r390992;
        return r390998;
}

double f(double a, double b_2, double c) {
        double r390999 = b_2;
        double r391000 = -1.4758305599808076e+144;
        bool r391001 = r390999 <= r391000;
        double r391002 = -2.0;
        double r391003 = a;
        double r391004 = r390999 / r391003;
        double r391005 = 0.5;
        double r391006 = c;
        double r391007 = r391006 / r390999;
        double r391008 = r391005 * r391007;
        double r391009 = fma(r391002, r391004, r391008);
        double r391010 = 1.739098950628615e-79;
        bool r391011 = r390999 <= r391010;
        double r391012 = 1.0;
        double r391013 = r390999 * r390999;
        double r391014 = r391006 * r391003;
        double r391015 = r391013 - r391014;
        double r391016 = sqrt(r391015);
        double r391017 = r391016 - r390999;
        double r391018 = r391003 / r391017;
        double r391019 = r391012 / r391018;
        double r391020 = 1.8656332031849816e-25;
        bool r391021 = r390999 <= r391020;
        double r391022 = -0.5;
        double r391023 = r391007 * r391022;
        double r391024 = 5.297236684235463e-16;
        bool r391025 = r390999 <= r391024;
        double r391026 = r391015 - r391013;
        double r391027 = r391016 + r390999;
        double r391028 = r391026 / r391027;
        double r391029 = r391028 / r391003;
        double r391030 = r391025 ? r391029 : r391023;
        double r391031 = r391021 ? r391023 : r391030;
        double r391032 = r391011 ? r391019 : r391031;
        double r391033 = r391001 ? r391009 : r391032;
        return r391033;
}

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.4758305599808076e+144

    1. Initial program 58.0

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

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

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

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

    if -1.4758305599808076e+144 < b_2 < 1.739098950628615e-79

    1. Initial program 11.8

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

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

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

    if 1.739098950628615e-79 < b_2 < 1.8656332031849816e-25 or 5.297236684235463e-16 < b_2

    1. Initial program 53.1

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

      \[\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}}\]

    if 1.8656332031849816e-25 < b_2 < 5.297236684235463e-16

    1. Initial program 42.7

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

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

      \[\leadsto \frac{\color{blue}{\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}}}{a}\]
    5. Simplified42.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b_2 \le -1.4758305599808076 \cdot 10^{+144}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{b_2}{a}, \frac{1}{2} \cdot \frac{c}{b_2}\right)\\ \mathbf{elif}\;b_2 \le 1.739098950628615 \cdot 10^{-79}:\\ \;\;\;\;\frac{1}{\frac{a}{\sqrt{b_2 \cdot b_2 - c \cdot a} - b_2}}\\ \mathbf{elif}\;b_2 \le 1.8656332031849816 \cdot 10^{-25}:\\ \;\;\;\;\frac{c}{b_2} \cdot \frac{-1}{2}\\ \mathbf{elif}\;b_2 \le 5.297236684235463 \cdot 10^{-16}:\\ \;\;\;\;\frac{\frac{\left(b_2 \cdot b_2 - c \cdot a\right) - b_2 \cdot b_2}{\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 2019156 +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))