Average Error: 19.8 → 13.2
Time: 18.1s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 1.889590541215328739023685855570187768551 \cdot 10^{-282}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{-\frac{\mathsf{fma}\left(-c, 4 \cdot a, 0\right)}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\ \end{array}\\ \mathbf{elif}\;b \le 1.47869551036987940503892652554828247399 \cdot 10^{135}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot 2}{\frac{\mathsf{fma}\left(-c, 4 \cdot a, 0\right)}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} + b}}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{a}{b}}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\end{array}
\begin{array}{l}
\mathbf{if}\;b \le 1.889590541215328739023685855570187768551 \cdot 10^{-282}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{-\frac{\mathsf{fma}\left(-c, 4 \cdot a, 0\right)}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\

\end{array}\\

\mathbf{elif}\;b \le 1.47869551036987940503892652554828247399 \cdot 10^{135}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\frac{\mathsf{fma}\left(-c, 4 \cdot a, 0\right)}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} + b}}\\

\end{array}\\

\mathbf{elif}\;b \ge 0.0:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{a}{b}}\\

\end{array}
double f(double a, double b, double c) {
        double r39125 = b;
        double r39126 = 0.0;
        bool r39127 = r39125 >= r39126;
        double r39128 = -r39125;
        double r39129 = r39125 * r39125;
        double r39130 = 4.0;
        double r39131 = a;
        double r39132 = r39130 * r39131;
        double r39133 = c;
        double r39134 = r39132 * r39133;
        double r39135 = r39129 - r39134;
        double r39136 = sqrt(r39135);
        double r39137 = r39128 - r39136;
        double r39138 = 2.0;
        double r39139 = r39138 * r39131;
        double r39140 = r39137 / r39139;
        double r39141 = r39138 * r39133;
        double r39142 = r39128 + r39136;
        double r39143 = r39141 / r39142;
        double r39144 = r39127 ? r39140 : r39143;
        return r39144;
}

double f(double a, double b, double c) {
        double r39145 = b;
        double r39146 = 1.8895905412153287e-282;
        bool r39147 = r39145 <= r39146;
        double r39148 = 0.0;
        bool r39149 = r39145 >= r39148;
        double r39150 = c;
        double r39151 = -r39150;
        double r39152 = 4.0;
        double r39153 = a;
        double r39154 = r39152 * r39153;
        double r39155 = 0.0;
        double r39156 = fma(r39151, r39154, r39155);
        double r39157 = r39145 * r39145;
        double r39158 = fma(r39154, r39151, r39157);
        double r39159 = sqrt(r39158);
        double r39160 = r39159 - r39145;
        double r39161 = r39156 / r39160;
        double r39162 = -r39161;
        double r39163 = 2.0;
        double r39164 = r39163 * r39153;
        double r39165 = r39162 / r39164;
        double r39166 = r39150 * r39163;
        double r39167 = r39166 / r39160;
        double r39168 = r39149 ? r39165 : r39167;
        double r39169 = 1.4786955103698794e+135;
        bool r39170 = r39145 <= r39169;
        double r39171 = -r39145;
        double r39172 = r39171 - r39159;
        double r39173 = r39172 / r39164;
        double r39174 = r39159 + r39145;
        double r39175 = r39156 / r39174;
        double r39176 = r39166 / r39175;
        double r39177 = r39149 ? r39173 : r39176;
        double r39178 = r39171 - r39145;
        double r39179 = r39178 / r39164;
        double r39180 = -1.0;
        double r39181 = r39153 / r39145;
        double r39182 = r39180 / r39181;
        double r39183 = r39149 ? r39179 : r39182;
        double r39184 = r39170 ? r39177 : r39183;
        double r39185 = r39147 ? r39168 : r39184;
        return r39185;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < 1.8895905412153287e-282

    1. Initial program 17.8

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Simplified17.7

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied flip--17.7

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}{\left(-b\right) + \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\ \end{array}\]
    5. Simplified17.7

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\frac{\color{blue}{-\mathsf{fma}\left(-c, 4 \cdot a, 0\right)}}{\left(-b\right) + \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\ \end{array}\]
    6. Simplified17.7

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\frac{-\mathsf{fma}\left(-c, 4 \cdot a, 0\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\ \end{array}\]

    if 1.8895905412153287e-282 < b < 1.4786955103698794e+135

    1. Initial program 9.1

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Simplified9.1

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied flip--9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\color{blue}{\frac{2 \cdot c}{\frac{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} \cdot \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b \cdot b}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} + b}}}\\ \end{array}\]
    5. Simplified9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\color{blue}{2 \cdot c}}{\frac{\mathsf{fma}\left(-c, 4 \cdot a, 0\right)}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} + b}}\\ \end{array}\]
    6. Simplified9.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\frac{\mathsf{fma}\left(-c, 4 \cdot a, 0\right)}{b + \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}}}\\ \end{array}\]

    if 1.4786955103698794e+135 < b

    1. Initial program 56.7

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \end{array}\]
    2. Simplified56.7

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\ \end{array}}\]
    3. Taylor expanded around 0 2.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - \color{blue}{b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\mathsf{fma}\left(4 \cdot a, -c, b \cdot b\right)} - b}\\ \end{array}\]
    4. Taylor expanded around 0 2.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{b}{a}\\ \end{array}\]
    5. Simplified2.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{a}{b}}\\ \end{array}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.2

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

Reproduce

herbie shell --seed 2019195 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 1"
  (if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))