Average Error: 19.8 → 13.5
Time: 18.8s
Precision: 64
\[\begin{array}{l} \mathbf{if}\;b \ge 0.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 2.284562987196845014129179733727777489847 \cdot 10^{77}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot c, -a, b \cdot b\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\sqrt{\sqrt{\mathsf{fma}\left(4 \cdot c, -a, b \cdot b\right)}}, \sqrt{\sqrt{\mathsf{fma}\left(4 \cdot c, -a, b \cdot b\right)}}, -b\right)}{2}}{a}\\ \end{array}\\ \mathbf{elif}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(4 \cdot c, -a, b \cdot b\right)} - b}{2}}{a}\\ \end{array}\]
\begin{array}{l}
\mathbf{if}\;b \ge 0.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 2.284562987196845014129179733727777489847 \cdot 10^{77}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(4 \cdot c, -a, b \cdot b\right)}}\\

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

\end{array}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r45149 = b;
        double r45150 = 0.0;
        bool r45151 = r45149 >= r45150;
        double r45152 = 2.0;
        double r45153 = c;
        double r45154 = r45152 * r45153;
        double r45155 = -r45149;
        double r45156 = r45149 * r45149;
        double r45157 = 4.0;
        double r45158 = a;
        double r45159 = r45157 * r45158;
        double r45160 = r45159 * r45153;
        double r45161 = r45156 - r45160;
        double r45162 = sqrt(r45161);
        double r45163 = r45155 - r45162;
        double r45164 = r45154 / r45163;
        double r45165 = r45155 + r45162;
        double r45166 = r45152 * r45158;
        double r45167 = r45165 / r45166;
        double r45168 = r45151 ? r45164 : r45167;
        return r45168;
}

double f(double a, double b, double c) {
        double r45169 = b;
        double r45170 = 2.284562987196845e+77;
        bool r45171 = r45169 <= r45170;
        double r45172 = 0.0;
        bool r45173 = r45169 >= r45172;
        double r45174 = 2.0;
        double r45175 = c;
        double r45176 = r45174 * r45175;
        double r45177 = -r45169;
        double r45178 = 4.0;
        double r45179 = r45178 * r45175;
        double r45180 = a;
        double r45181 = -r45180;
        double r45182 = r45169 * r45169;
        double r45183 = fma(r45179, r45181, r45182);
        double r45184 = sqrt(r45183);
        double r45185 = r45177 - r45184;
        double r45186 = r45176 / r45185;
        double r45187 = sqrt(r45184);
        double r45188 = fma(r45187, r45187, r45177);
        double r45189 = r45188 / r45174;
        double r45190 = r45189 / r45180;
        double r45191 = r45173 ? r45186 : r45190;
        double r45192 = r45177 - r45169;
        double r45193 = r45176 / r45192;
        double r45194 = r45184 - r45169;
        double r45195 = r45194 / r45174;
        double r45196 = r45195 / r45180;
        double r45197 = r45173 ? r45193 : r45196;
        double r45198 = r45171 ? r45191 : r45197;
        return r45198;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if b < 2.284562987196845e+77

    1. Initial program 17.0

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Simplified17.0

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

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

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

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

    if 2.284562987196845e+77 < b

    1. Initial program 27.8

      \[\begin{array}{l} \mathbf{if}\;b \ge 0.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. Simplified27.7

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

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

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

Reproduce

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