Average Error: 33.3 → 6.4
Time: 2.2m
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 -3.263941314600607 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -4.687918346756617 \cdot 10^{-254}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(a \cdot -4\right)\right)\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.463606471108268 \cdot 10^{+121}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(a \cdot -4\right)\right)\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;-\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 -3.263941314600607 \cdot 10^{+152}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \le -4.687918346756617 \cdot 10^{-254}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(a \cdot -4\right)\right)\right)} - b}{2 \cdot a}\\

\mathbf{elif}\;b \le 3.463606471108268 \cdot 10^{+121}:\\
\;\;\;\;\frac{c \cdot -2}{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(a \cdot -4\right)\right)\right)} + b}\\

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

\end{array}
double f(double a, double b, double c) {
        double r13848557 = b;
        double r13848558 = -r13848557;
        double r13848559 = r13848557 * r13848557;
        double r13848560 = 4.0;
        double r13848561 = a;
        double r13848562 = r13848560 * r13848561;
        double r13848563 = c;
        double r13848564 = r13848562 * r13848563;
        double r13848565 = r13848559 - r13848564;
        double r13848566 = sqrt(r13848565);
        double r13848567 = r13848558 + r13848566;
        double r13848568 = 2.0;
        double r13848569 = r13848568 * r13848561;
        double r13848570 = r13848567 / r13848569;
        return r13848570;
}

double f(double a, double b, double c) {
        double r13848571 = b;
        double r13848572 = -3.263941314600607e+152;
        bool r13848573 = r13848571 <= r13848572;
        double r13848574 = c;
        double r13848575 = r13848574 / r13848571;
        double r13848576 = a;
        double r13848577 = r13848571 / r13848576;
        double r13848578 = r13848575 - r13848577;
        double r13848579 = -4.687918346756617e-254;
        bool r13848580 = r13848571 <= r13848579;
        double r13848581 = -4.0;
        double r13848582 = r13848576 * r13848581;
        double r13848583 = r13848574 * r13848582;
        double r13848584 = fma(r13848571, r13848571, r13848583);
        double r13848585 = sqrt(r13848584);
        double r13848586 = r13848585 - r13848571;
        double r13848587 = 2.0;
        double r13848588 = r13848587 * r13848576;
        double r13848589 = r13848586 / r13848588;
        double r13848590 = 3.463606471108268e+121;
        bool r13848591 = r13848571 <= r13848590;
        double r13848592 = -2.0;
        double r13848593 = r13848574 * r13848592;
        double r13848594 = r13848585 + r13848571;
        double r13848595 = r13848593 / r13848594;
        double r13848596 = -r13848575;
        double r13848597 = r13848591 ? r13848595 : r13848596;
        double r13848598 = r13848580 ? r13848589 : r13848597;
        double r13848599 = r13848573 ? r13848578 : r13848598;
        return r13848599;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -3.263941314600607e+152

    1. Initial program 60.1

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

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

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]

    if -3.263941314600607e+152 < b < -4.687918346756617e-254

    1. Initial program 7.8

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)} - b}{2}}{a}}\]
    3. Using strategy rm
    4. Applied associate-/l/7.8

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

    if -4.687918346756617e-254 < b < 3.463606471108268e+121

    1. Initial program 31.6

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

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

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

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

      \[\leadsto \frac{\frac{\frac{c \cdot \left(-4 \cdot a\right)}{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)} + b}}{2}}{\color{blue}{1 \cdot a}}\]
    8. Applied *-un-lft-identity15.5

      \[\leadsto \frac{\frac{\frac{c \cdot \left(-4 \cdot a\right)}{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)} + b}}{\color{blue}{1 \cdot 2}}}{1 \cdot a}\]
    9. Applied *-un-lft-identity15.5

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

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

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

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

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

    if 3.463606471108268e+121 < b

    1. Initial program 59.8

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(-4 \cdot a\right)\right)\right)} - b}{2}}{a}}\]
    3. Using strategy rm
    4. Applied associate-/l/59.8

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified2.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.263941314600607 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -4.687918346756617 \cdot 10^{-254}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(a \cdot -4\right)\right)\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.463606471108268 \cdot 10^{+121}:\\ \;\;\;\;\frac{c \cdot -2}{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot \left(a \cdot -4\right)\right)\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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