Average Error: 34.2 → 10.4
Time: 10.5s
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 -4.12310353364421125 \cdot 10^{95}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.446447862996811 \cdot 10^{-75}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{\frac{1}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \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 -4.12310353364421125 \cdot 10^{95}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r76885 = b;
        double r76886 = -r76885;
        double r76887 = r76885 * r76885;
        double r76888 = 4.0;
        double r76889 = a;
        double r76890 = r76888 * r76889;
        double r76891 = c;
        double r76892 = r76890 * r76891;
        double r76893 = r76887 - r76892;
        double r76894 = sqrt(r76893);
        double r76895 = r76886 + r76894;
        double r76896 = 2.0;
        double r76897 = r76896 * r76889;
        double r76898 = r76895 / r76897;
        return r76898;
}

double f(double a, double b, double c) {
        double r76899 = b;
        double r76900 = -4.123103533644211e+95;
        bool r76901 = r76899 <= r76900;
        double r76902 = 1.0;
        double r76903 = c;
        double r76904 = r76903 / r76899;
        double r76905 = a;
        double r76906 = r76899 / r76905;
        double r76907 = r76904 - r76906;
        double r76908 = r76902 * r76907;
        double r76909 = 3.446447862996811e-75;
        bool r76910 = r76899 <= r76909;
        double r76911 = r76899 * r76899;
        double r76912 = 4.0;
        double r76913 = r76912 * r76905;
        double r76914 = r76913 * r76903;
        double r76915 = r76911 - r76914;
        double r76916 = sqrt(r76915);
        double r76917 = r76916 - r76899;
        double r76918 = 1.0;
        double r76919 = r76918 / r76905;
        double r76920 = 2.0;
        double r76921 = r76919 / r76920;
        double r76922 = r76917 * r76921;
        double r76923 = -1.0;
        double r76924 = r76923 * r76904;
        double r76925 = r76910 ? r76922 : r76924;
        double r76926 = r76901 ? r76908 : r76925;
        return r76926;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -4.123103533644211e+95

    1. Initial program 47.3

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    4. Simplified3.8

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

    if -4.123103533644211e+95 < b < 3.446447862996811e-75

    1. Initial program 13.3

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}}\]
    5. Using strategy rm
    6. Applied div-inv13.4

      \[\leadsto \frac{1}{\frac{a}{\color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2}}}}\]
    7. Applied *-un-lft-identity13.4

      \[\leadsto \frac{1}{\frac{\color{blue}{1 \cdot a}}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2}}}\]
    8. Applied times-frac13.5

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \frac{a}{\frac{1}{2}}}}\]
    9. Applied add-cube-cbrt13.5

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{1}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b} \cdot \frac{a}{\frac{1}{2}}}\]
    10. Applied times-frac13.5

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

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

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

    if 3.446447862996811e-75 < b

    1. Initial program 52.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.12310353364421125 \cdot 10^{95}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.446447862996811 \cdot 10^{-75}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{\frac{1}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020042 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))