Average Error: 32.9 → 28.7
Time: 1.5m
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 7.844448680425584 \cdot 10^{+101}:\\ \;\;\;\;\frac{\frac{1}{2}}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c, \left(a \cdot -4\right), \left(b \cdot b\right)\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \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 7.844448680425584 \cdot 10^{+101}:\\
\;\;\;\;\frac{\frac{1}{2}}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c, \left(a \cdot -4\right), \left(b \cdot b\right)\right)} - b\right)\\

\mathbf{else}:\\
\;\;\;\;0\\

\end{array}
double f(double a, double b, double c) {
        double r3182151 = b;
        double r3182152 = -r3182151;
        double r3182153 = r3182151 * r3182151;
        double r3182154 = 4.0;
        double r3182155 = a;
        double r3182156 = r3182154 * r3182155;
        double r3182157 = c;
        double r3182158 = r3182156 * r3182157;
        double r3182159 = r3182153 - r3182158;
        double r3182160 = sqrt(r3182159);
        double r3182161 = r3182152 + r3182160;
        double r3182162 = 2.0;
        double r3182163 = r3182162 * r3182155;
        double r3182164 = r3182161 / r3182163;
        return r3182164;
}

double f(double a, double b, double c) {
        double r3182165 = b;
        double r3182166 = 7.844448680425584e+101;
        bool r3182167 = r3182165 <= r3182166;
        double r3182168 = 0.5;
        double r3182169 = a;
        double r3182170 = r3182168 / r3182169;
        double r3182171 = c;
        double r3182172 = -4.0;
        double r3182173 = r3182169 * r3182172;
        double r3182174 = r3182165 * r3182165;
        double r3182175 = fma(r3182171, r3182173, r3182174);
        double r3182176 = sqrt(r3182175);
        double r3182177 = r3182176 - r3182165;
        double r3182178 = r3182170 * r3182177;
        double r3182179 = 0.0;
        double r3182180 = r3182167 ? r3182178 : r3182179;
        return r3182180;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 7.844448680425584e+101

    1. Initial program 25.3

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

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

      \[\leadsto \frac{\frac{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b}{2}}{\color{blue}{1 \cdot a}}\]
    5. Applied div-inv25.3

      \[\leadsto \frac{\color{blue}{\left(\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b\right) \cdot \frac{1}{2}}}{1 \cdot a}\]
    6. Applied times-frac25.4

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b}{1} \cdot \frac{\frac{1}{2}}{a}}\]
    7. Simplified25.4

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(c, \left(a \cdot -4\right), \left(b \cdot b\right)\right)} - b\right)} \cdot \frac{\frac{1}{2}}{a}\]
    8. Simplified25.4

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

    if 7.844448680425584e+101 < b

    1. Initial program 59.0

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

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

      \[\leadsto \frac{\frac{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b}{2}}{\color{blue}{1 \cdot a}}\]
    5. Applied div-inv59.0

      \[\leadsto \frac{\color{blue}{\left(\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b\right) \cdot \frac{1}{2}}}{1 \cdot a}\]
    6. Applied times-frac59.0

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(c, \left(-4 \cdot a\right), \left(b \cdot b\right)\right)} - b}{1} \cdot \frac{\frac{1}{2}}{a}}\]
    7. Simplified59.0

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(c, \left(a \cdot -4\right), \left(b \cdot b\right)\right)} - b\right)} \cdot \frac{\frac{1}{2}}{a}\]
    8. Simplified59.0

      \[\leadsto \left(\sqrt{\mathsf{fma}\left(c, \left(a \cdot -4\right), \left(b \cdot b\right)\right)} - b\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}}\]
    9. Taylor expanded around 0 39.9

      \[\leadsto \color{blue}{0}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 7.844448680425584 \cdot 10^{+101}:\\ \;\;\;\;\frac{\frac{1}{2}}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c, \left(a \cdot -4\right), \left(b \cdot b\right)\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Reproduce

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