Average Error: 19.1 → 12.8
Time: 20.1s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;b \le 1.5386020478423979 \cdot 10^{+121}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)}} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(a \cdot c\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

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

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r445147 = b;
        double r445148 = 0.0;
        bool r445149 = r445147 >= r445148;
        double r445150 = 2.0;
        double r445151 = c;
        double r445152 = r445150 * r445151;
        double r445153 = -r445147;
        double r445154 = r445147 * r445147;
        double r445155 = 4.0;
        double r445156 = a;
        double r445157 = r445155 * r445156;
        double r445158 = r445157 * r445151;
        double r445159 = r445154 - r445158;
        double r445160 = sqrt(r445159);
        double r445161 = r445153 - r445160;
        double r445162 = r445152 / r445161;
        double r445163 = r445153 + r445160;
        double r445164 = r445150 * r445156;
        double r445165 = r445163 / r445164;
        double r445166 = r445149 ? r445162 : r445165;
        return r445166;
}

double f(double a, double b, double c) {
        double r445167 = b;
        double r445168 = 1.5386020478423979e+121;
        bool r445169 = r445167 <= r445168;
        double r445170 = 0.0;
        bool r445171 = r445167 >= r445170;
        double r445172 = 2.0;
        double r445173 = c;
        double r445174 = r445172 * r445173;
        double r445175 = -r445167;
        double r445176 = -4.0;
        double r445177 = a;
        double r445178 = r445177 * r445173;
        double r445179 = r445167 * r445167;
        double r445180 = fma(r445176, r445178, r445179);
        double r445181 = sqrt(r445180);
        double r445182 = sqrt(r445181);
        double r445183 = r445182 * r445182;
        double r445184 = r445175 - r445183;
        double r445185 = r445174 / r445184;
        double r445186 = r445183 - r445167;
        double r445187 = r445172 * r445177;
        double r445188 = r445186 / r445187;
        double r445189 = r445171 ? r445185 : r445188;
        double r445190 = r445175 - r445167;
        double r445191 = r445174 / r445190;
        double r445192 = r445181 - r445167;
        double r445193 = r445192 / r445187;
        double r445194 = r445171 ? r445191 : r445193;
        double r445195 = r445169 ? r445189 : r445194;
        return r445195;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 1.5386020478423979e+121

    1. Initial program 15.4

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)}} - b}{2 \cdot a}\\ \end{array}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt15.6

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

    if 1.5386020478423979e+121 < b

    1. Initial program 32.8

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, \left(c \cdot a\right), \left(b \cdot b\right)\right)} - b}{2 \cdot a}\\ \end{array}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification12.8

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

Reproduce

herbie shell --seed 2019128 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 2"
  (if (>= b 0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))))