Average Error: 34.4 → 10.7
Time: 20.8s
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}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 2.898348930695269343280527497904161468201 \cdot 10^{-35}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\sqrt{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}, \sqrt{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}, -b\right)}{2}}{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 -2.221067196710922123169723133116561516447 \cdot 10^{149}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r2045677 = b;
        double r2045678 = -r2045677;
        double r2045679 = r2045677 * r2045677;
        double r2045680 = 4.0;
        double r2045681 = a;
        double r2045682 = r2045680 * r2045681;
        double r2045683 = c;
        double r2045684 = r2045682 * r2045683;
        double r2045685 = r2045679 - r2045684;
        double r2045686 = sqrt(r2045685);
        double r2045687 = r2045678 + r2045686;
        double r2045688 = 2.0;
        double r2045689 = r2045688 * r2045681;
        double r2045690 = r2045687 / r2045689;
        return r2045690;
}

double f(double a, double b, double c) {
        double r2045691 = b;
        double r2045692 = -2.221067196710922e+149;
        bool r2045693 = r2045691 <= r2045692;
        double r2045694 = c;
        double r2045695 = r2045694 / r2045691;
        double r2045696 = a;
        double r2045697 = r2045691 / r2045696;
        double r2045698 = r2045695 - r2045697;
        double r2045699 = 1.0;
        double r2045700 = r2045698 * r2045699;
        double r2045701 = 2.8983489306952693e-35;
        bool r2045702 = r2045691 <= r2045701;
        double r2045703 = r2045691 * r2045691;
        double r2045704 = r2045696 * r2045694;
        double r2045705 = 4.0;
        double r2045706 = r2045704 * r2045705;
        double r2045707 = r2045703 - r2045706;
        double r2045708 = sqrt(r2045707);
        double r2045709 = sqrt(r2045708);
        double r2045710 = -r2045691;
        double r2045711 = fma(r2045709, r2045709, r2045710);
        double r2045712 = 2.0;
        double r2045713 = r2045711 / r2045712;
        double r2045714 = r2045713 / r2045696;
        double r2045715 = -1.0;
        double r2045716 = r2045715 * r2045695;
        double r2045717 = r2045702 ? r2045714 : r2045716;
        double r2045718 = r2045693 ? r2045700 : r2045717;
        return r2045718;
}

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 - 4 \cdot \left(c \cdot a\right)} - b}{2}}{a}}\]
    3. Taylor expanded around -inf 2.7

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

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

    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 - 4 \cdot \left(c \cdot a\right)} - b}{2}}{a}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt14.6

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

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}} - b}{2}}{a}\]
    6. Applied fma-neg14.8

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

    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 - 4 \cdot \left(c \cdot a\right)} - b}{2}}{a}}\]
    3. Taylor expanded around inf 7.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.221067196710922123169723133116561516447 \cdot 10^{149}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 2.898348930695269343280527497904161468201 \cdot 10^{-35}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\sqrt{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}, \sqrt{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}, -b\right)}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \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)))