Average Error: 34.0 → 9.8
Time: 16.3s
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 -1.285761821828269498914963771383359026418 \cdot 10^{115}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 4.089744618622775294902023307017914843593 \cdot 10^{-73}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}\\ \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 -1.285761821828269498914963771383359026418 \cdot 10^{115}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r46054 = b;
        double r46055 = -r46054;
        double r46056 = r46054 * r46054;
        double r46057 = 4.0;
        double r46058 = a;
        double r46059 = r46057 * r46058;
        double r46060 = c;
        double r46061 = r46059 * r46060;
        double r46062 = r46056 - r46061;
        double r46063 = sqrt(r46062);
        double r46064 = r46055 + r46063;
        double r46065 = 2.0;
        double r46066 = r46065 * r46058;
        double r46067 = r46064 / r46066;
        return r46067;
}

double f(double a, double b, double c) {
        double r46068 = b;
        double r46069 = -1.2857618218282695e+115;
        bool r46070 = r46068 <= r46069;
        double r46071 = 1.0;
        double r46072 = c;
        double r46073 = r46072 / r46068;
        double r46074 = a;
        double r46075 = r46068 / r46074;
        double r46076 = r46073 - r46075;
        double r46077 = r46071 * r46076;
        double r46078 = 4.089744618622775e-73;
        bool r46079 = r46068 <= r46078;
        double r46080 = r46068 * r46068;
        double r46081 = 4.0;
        double r46082 = r46081 * r46074;
        double r46083 = r46082 * r46072;
        double r46084 = r46080 - r46083;
        double r46085 = sqrt(r46084);
        double r46086 = r46085 - r46068;
        double r46087 = 2.0;
        double r46088 = r46087 * r46074;
        double r46089 = r46086 / r46088;
        double r46090 = -1.0;
        double r46091 = r46090 * r46073;
        double r46092 = r46079 ? r46089 : r46091;
        double r46093 = r46070 ? r46077 : r46092;
        return r46093;
}

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 < -1.2857618218282695e+115

    1. Initial program 50.6

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

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

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

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

    if -1.2857618218282695e+115 < b < 4.089744618622775e-73

    1. Initial program 12.6

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

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

    if 4.089744618622775e-73 < b

    1. Initial program 53.3

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

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

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

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

Reproduce

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