Average Error: 20.3 → 7.7
Time: 10.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.615257373542238721197930661559276546696 \cdot 10^{153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\sqrt[3]{{\left(\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\\ \mathbf{elif}\;b \le -6.742598410721509671627125970507806052655 \cdot 10^{-308} \lor \neg \left(b \le 2.976536699626750437221780308255562179441 \cdot 10^{116}\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}\\ \end{array}\\ \mathbf{elif}\;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{\frac{\frac{-\left(4 \cdot a\right) \cdot c}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{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.615257373542238721197930661559276546696 \cdot 10^{153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\sqrt[3]{{\left(\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}^{3}}\\

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\end{array}\\

\mathbf{elif}\;b \le -6.742598410721509671627125970507806052655 \cdot 10^{-308} \lor \neg \left(b \le 2.976536699626750437221780308255562179441 \cdot 10^{116}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \ge 0.0:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}\\

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

\end{array}\\

\mathbf{elif}\;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{\frac{\frac{-\left(4 \cdot a\right) \cdot c}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2}}{a}\\

\end{array}
double f(double a, double b, double c) {
        double r33253 = b;
        double r33254 = 0.0;
        bool r33255 = r33253 >= r33254;
        double r33256 = 2.0;
        double r33257 = c;
        double r33258 = r33256 * r33257;
        double r33259 = -r33253;
        double r33260 = r33253 * r33253;
        double r33261 = 4.0;
        double r33262 = a;
        double r33263 = r33261 * r33262;
        double r33264 = r33263 * r33257;
        double r33265 = r33260 - r33264;
        double r33266 = sqrt(r33265);
        double r33267 = r33259 - r33266;
        double r33268 = r33258 / r33267;
        double r33269 = r33259 + r33266;
        double r33270 = r33256 * r33262;
        double r33271 = r33269 / r33270;
        double r33272 = r33255 ? r33268 : r33271;
        return r33272;
}

double f(double a, double b, double c) {
        double r33273 = b;
        double r33274 = -2.6152573735422387e+153;
        bool r33275 = r33273 <= r33274;
        double r33276 = 0.0;
        bool r33277 = r33273 >= r33276;
        double r33278 = 2.0;
        double r33279 = c;
        double r33280 = r33278 * r33279;
        double r33281 = -r33273;
        double r33282 = r33273 * r33273;
        double r33283 = 4.0;
        double r33284 = a;
        double r33285 = r33283 * r33284;
        double r33286 = r33285 * r33279;
        double r33287 = r33282 - r33286;
        double r33288 = sqrt(r33287);
        double r33289 = r33281 - r33288;
        double r33290 = r33280 / r33289;
        double r33291 = 3.0;
        double r33292 = pow(r33290, r33291);
        double r33293 = cbrt(r33292);
        double r33294 = 1.0;
        double r33295 = r33279 / r33273;
        double r33296 = r33273 / r33284;
        double r33297 = r33295 - r33296;
        double r33298 = r33294 * r33297;
        double r33299 = r33277 ? r33293 : r33298;
        double r33300 = -6.74259841072151e-308;
        bool r33301 = r33273 <= r33300;
        double r33302 = 2.9765366996267504e+116;
        bool r33303 = r33273 <= r33302;
        double r33304 = !r33303;
        bool r33305 = r33301 || r33304;
        double r33306 = r33284 * r33279;
        double r33307 = r33306 / r33273;
        double r33308 = -2.0;
        double r33309 = r33308 * r33273;
        double r33310 = fma(r33278, r33307, r33309);
        double r33311 = r33280 / r33310;
        double r33312 = r33288 - r33273;
        double r33313 = r33312 / r33278;
        double r33314 = r33313 / r33284;
        double r33315 = r33277 ? r33311 : r33314;
        double r33316 = -r33286;
        double r33317 = r33273 + r33288;
        double r33318 = r33316 / r33317;
        double r33319 = r33318 / r33278;
        double r33320 = r33319 / r33284;
        double r33321 = r33277 ? r33290 : r33320;
        double r33322 = r33305 ? r33315 : r33321;
        double r33323 = r33275 ? r33299 : r33322;
        return r33323;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < -2.6152573735422387e+153

    1. Initial program 63.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. Simplified63.8

      \[\leadsto \color{blue}{\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{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}\\ \end{array}}\]
    3. Taylor expanded around -inf 10.5

      \[\leadsto \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{\frac{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{2}}{a}\\ \end{array}\]
    4. Simplified10.5

      \[\leadsto \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{\frac{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}{2}}{a}\\ \end{array}\]
    5. Taylor expanded around 0 2.1

      \[\leadsto \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}:\\ \;\;\;\;1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}\\ \end{array}\]
    6. Simplified2.1

      \[\leadsto \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}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
    7. Using strategy rm
    8. Applied add-cbrt-cube2.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\color{blue}{\sqrt[3]{\left(\left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
    9. Applied add-cbrt-cube2.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot \color{blue}{\sqrt[3]{\left(c \cdot c\right) \cdot c}}}{\sqrt[3]{\left(\left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
    10. Applied add-cbrt-cube2.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\color{blue}{\sqrt[3]{\left(2 \cdot 2\right) \cdot 2}} \cdot \sqrt[3]{\left(c \cdot c\right) \cdot c}}{\sqrt[3]{\left(\left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
    11. Applied cbrt-unprod2.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{\color{blue}{\sqrt[3]{\left(\left(2 \cdot 2\right) \cdot 2\right) \cdot \left(\left(c \cdot c\right) \cdot c\right)}}}{\sqrt[3]{\left(\left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
    12. Applied cbrt-undiv2.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\color{blue}{\sqrt[3]{\frac{\left(\left(2 \cdot 2\right) \cdot 2\right) \cdot \left(\left(c \cdot c\right) \cdot c\right)}{\left(\left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
    13. Simplified2.1

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

    if -2.6152573735422387e+153 < b < -6.74259841072151e-308 or 2.9765366996267504e+116 < b

    1. Initial program 18.5

      \[\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. Simplified18.5

      \[\leadsto \color{blue}{\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{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}\\ \end{array}}\]
    3. Taylor expanded around inf 8.1

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

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

    if -6.74259841072151e-308 < b < 2.9765366996267504e+116

    1. Initial program 8.9

      \[\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. Simplified8.9

      \[\leadsto \color{blue}{\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{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied flip--8.9

      \[\leadsto \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{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b \cdot b}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}{2}}{a}\\ \end{array}\]
    5. Simplified8.9

      \[\leadsto \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{\frac{\frac{0 - \left(4 \cdot a\right) \cdot c}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}{2}}{a}\\ \end{array}\]
    6. Simplified8.9

      \[\leadsto \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{\frac{\frac{0 - \left(4 \cdot a\right) \cdot c}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2}}{a}\\ \end{array}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.615257373542238721197930661559276546696 \cdot 10^{153}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\sqrt[3]{{\left(\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\\ \mathbf{elif}\;b \le -6.742598410721509671627125970507806052655 \cdot 10^{-308} \lor \neg \left(b \le 2.976536699626750437221780308255562179441 \cdot 10^{116}\right):\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0.0:\\ \;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(2, \frac{a \cdot c}{b}, -2 \cdot b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}\\ \end{array}\\ \mathbf{elif}\;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{\frac{\frac{-\left(4 \cdot a\right) \cdot c}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2}}{a}\\ \end{array}\]

Reproduce

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