Average Error: 34.4 → 10.6
Time: 20.4s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.221067196710922123169723133116561516447 \cdot 10^{149}:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{b}, -2 \cdot \frac{b}{a}\right)}{2}\\ \mathbf{elif}\;b \le 2.898348930695269343280527497904161468201 \cdot 10^{-35}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -2.221067196710922123169723133116561516447 \cdot 10^{149}:\\
\;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{b}, -2 \cdot \frac{b}{a}\right)}{2}\\

\mathbf{elif}\;b \le 2.898348930695269343280527497904161468201 \cdot 10^{-35}:\\
\;\;\;\;\frac{\frac{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - b}{a}}{2}\\

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

\end{array}
double f(double a, double b, double c) {
        double r1577906 = b;
        double r1577907 = -r1577906;
        double r1577908 = r1577906 * r1577906;
        double r1577909 = 4.0;
        double r1577910 = a;
        double r1577911 = r1577909 * r1577910;
        double r1577912 = c;
        double r1577913 = r1577911 * r1577912;
        double r1577914 = r1577908 - r1577913;
        double r1577915 = sqrt(r1577914);
        double r1577916 = r1577907 + r1577915;
        double r1577917 = 2.0;
        double r1577918 = r1577917 * r1577910;
        double r1577919 = r1577916 / r1577918;
        return r1577919;
}

double f(double a, double b, double c) {
        double r1577920 = b;
        double r1577921 = -2.221067196710922e+149;
        bool r1577922 = r1577920 <= r1577921;
        double r1577923 = 2.0;
        double r1577924 = c;
        double r1577925 = r1577924 / r1577920;
        double r1577926 = -2.0;
        double r1577927 = a;
        double r1577928 = r1577920 / r1577927;
        double r1577929 = r1577926 * r1577928;
        double r1577930 = fma(r1577923, r1577925, r1577929);
        double r1577931 = r1577930 / r1577923;
        double r1577932 = 2.8983489306952693e-35;
        bool r1577933 = r1577920 <= r1577932;
        double r1577934 = r1577920 * r1577920;
        double r1577935 = 4.0;
        double r1577936 = r1577924 * r1577935;
        double r1577937 = r1577927 * r1577936;
        double r1577938 = r1577934 - r1577937;
        double r1577939 = sqrt(r1577938);
        double r1577940 = r1577939 - r1577920;
        double r1577941 = r1577940 / r1577927;
        double r1577942 = r1577941 / r1577923;
        double r1577943 = -2.0;
        double r1577944 = r1577943 * r1577925;
        double r1577945 = r1577944 / r1577923;
        double r1577946 = r1577933 ? r1577942 : r1577945;
        double r1577947 = r1577922 ? r1577931 : r1577946;
        return r1577947;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -2.221067196710922e+149

    1. Initial program 62.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified62.3

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{a}}{2}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity62.3

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{\color{blue}{1 \cdot a}}}{2}\]
    5. Applied associate-/r*62.3

      \[\leadsto \frac{\color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{1}}{a}}}{2}\]
    6. Simplified62.3

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - b}}{a}}{2}\]
    7. Taylor expanded around -inf 2.8

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}}}{2}\]
    8. Simplified2.8

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

    if -2.221067196710922e+149 < b < 2.8983489306952693e-35

    1. Initial program 14.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified14.6

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{a}}{2}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity14.6

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{\color{blue}{1 \cdot a}}}{2}\]
    5. Applied associate-/r*14.6

      \[\leadsto \frac{\color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{1}}{a}}}{2}\]
    6. Simplified14.6

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - b}}{a}}{2}\]

    if 2.8983489306952693e-35 < b

    1. Initial program 54.4

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{a}}{2}}\]
    3. Taylor expanded around inf 7.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.221067196710922123169723133116561516447 \cdot 10^{149}:\\ \;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{b}, -2 \cdot \frac{b}{a}\right)}{2}\\ \mathbf{elif}\;b \le 2.898348930695269343280527497904161468201 \cdot 10^{-35}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019171 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))