Average Error: 28.9 → 14.7
Time: 15.2s
Precision: 64
\[1.0536712127723509 \cdot 10^{-08} \lt a \lt 94906265.62425156 \land 1.0536712127723509 \cdot 10^{-08} \lt b \lt 94906265.62425156 \land 1.0536712127723509 \cdot 10^{-08} \lt c \lt 94906265.62425156\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3 \cdot a} \le -1.5312332401541407 \cdot 10^{-07}:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right)} \cdot \mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right) - b \cdot \left(b \cdot b\right)}{\mathsf{fma}\left(\left(\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right)}\right), \left(\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right)} + b\right), \left(b \cdot b\right)\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-1}{2}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3 \cdot a} \le -1.5312332401541407 \cdot 10^{-07}:\\
\;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right)} \cdot \mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right) - b \cdot \left(b \cdot b\right)}{\mathsf{fma}\left(\left(\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right)}\right), \left(\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right)} + b\right), \left(b \cdot b\right)\right)}}{3 \cdot a}\\

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

\end{array}
double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r2973236 = b;
        double r2973237 = -r2973236;
        double r2973238 = r2973236 * r2973236;
        double r2973239 = 3.0;
        double r2973240 = a;
        double r2973241 = r2973239 * r2973240;
        double r2973242 = c;
        double r2973243 = r2973241 * r2973242;
        double r2973244 = r2973238 - r2973243;
        double r2973245 = sqrt(r2973244);
        double r2973246 = r2973237 + r2973245;
        double r2973247 = r2973246 / r2973241;
        return r2973247;
}

double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r2973248 = b;
        double r2973249 = r2973248 * r2973248;
        double r2973250 = 3.0;
        double r2973251 = a;
        double r2973252 = r2973250 * r2973251;
        double r2973253 = c;
        double r2973254 = r2973252 * r2973253;
        double r2973255 = r2973249 - r2973254;
        double r2973256 = sqrt(r2973255);
        double r2973257 = -r2973248;
        double r2973258 = r2973256 + r2973257;
        double r2973259 = r2973258 / r2973252;
        double r2973260 = -1.5312332401541407e-07;
        bool r2973261 = r2973259 <= r2973260;
        double r2973262 = -3.0;
        double r2973263 = r2973253 * r2973251;
        double r2973264 = r2973262 * r2973263;
        double r2973265 = fma(r2973248, r2973248, r2973264);
        double r2973266 = sqrt(r2973265);
        double r2973267 = r2973266 * r2973265;
        double r2973268 = r2973248 * r2973249;
        double r2973269 = r2973267 - r2973268;
        double r2973270 = r2973266 + r2973248;
        double r2973271 = fma(r2973266, r2973270, r2973249);
        double r2973272 = r2973269 / r2973271;
        double r2973273 = r2973272 / r2973252;
        double r2973274 = r2973253 / r2973248;
        double r2973275 = -0.5;
        double r2973276 = r2973274 * r2973275;
        double r2973277 = r2973261 ? r2973273 : r2973276;
        return r2973277;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Derivation

  1. Split input into 2 regimes
  2. if (/ (+ (- b) (sqrt (- (* b b) (* (* 3 a) c)))) (* 3 a)) < -1.5312332401541407e-07

    1. Initial program 18.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Using strategy rm
    3. Applied flip3-+18.6

      \[\leadsto \frac{\color{blue}{\frac{{\left(-b\right)}^{3} + {\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}^{3}}{\left(-b\right) \cdot \left(-b\right) + \left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right) \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}}{3 \cdot a}\]
    4. Simplified18.0

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(b, b, \left(\left(c \cdot a\right) \cdot -3\right)\right)} \cdot \mathsf{fma}\left(b, b, \left(\left(c \cdot a\right) \cdot -3\right)\right) - \left(b \cdot b\right) \cdot b}}{\left(-b\right) \cdot \left(-b\right) + \left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-b\right) \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}\]
    5. Simplified18.0

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

    if -1.5312332401541407e-07 < (/ (+ (- b) (sqrt (- (* b b) (* (* 3 a) c)))) (* 3 a))

    1. Initial program 45.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Taylor expanded around inf 9.7

      \[\leadsto \frac{\color{blue}{\frac{-3}{2} \cdot \frac{a \cdot c}{b}}}{3 \cdot a}\]
    3. Taylor expanded around 0 9.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3 \cdot a} \le -1.5312332401541407 \cdot 10^{-07}:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right)} \cdot \mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right) - b \cdot \left(b \cdot b\right)}{\mathsf{fma}\left(\left(\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right)}\right), \left(\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot \left(c \cdot a\right)\right)\right)} + b\right), \left(b \cdot b\right)\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-1}{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019133 +o rules:numerics
(FPCore (a b c d)
  :name "Cubic critical, narrow range"
  :pre (and (< 1.0536712127723509e-08 a 94906265.62425156) (< 1.0536712127723509e-08 b 94906265.62425156) (< 1.0536712127723509e-08 c 94906265.62425156))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3 a) c)))) (* 3 a)))