Average Error: 28.4 → 15.0
Time: 4.4s
Precision: 64
\[1.05367121277235087 \cdot 10^{-8} \lt a \lt 94906265.6242515594 \land 1.05367121277235087 \cdot 10^{-8} \lt b \lt 94906265.6242515594 \land 1.05367121277235087 \cdot 10^{-8} \lt c \lt 94906265.6242515594\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \le -9.4953561267927016 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\ \mathbf{elif}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \le -2.96023529826703576 \cdot 10^{-5}:\\ \;\;\;\;\frac{\left(-1.5 \cdot \frac{a}{\sqrt{b}}\right) \cdot \frac{c}{\sqrt{b}}}{3 \cdot a}\\ \mathbf{elif}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \le -9.1599124166711329 \cdot 10^{-7}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \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{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \le -9.4953561267927016 \cdot 10^{-5}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\

\mathbf{elif}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \le -2.96023529826703576 \cdot 10^{-5}:\\
\;\;\;\;\frac{\left(-1.5 \cdot \frac{a}{\sqrt{b}}\right) \cdot \frac{c}{\sqrt{b}}}{3 \cdot a}\\

\mathbf{elif}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \le -9.1599124166711329 \cdot 10^{-7}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\

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

\end{array}
double f(double a, double b, double c) {
        double r88281 = b;
        double r88282 = -r88281;
        double r88283 = r88281 * r88281;
        double r88284 = 3.0;
        double r88285 = a;
        double r88286 = r88284 * r88285;
        double r88287 = c;
        double r88288 = r88286 * r88287;
        double r88289 = r88283 - r88288;
        double r88290 = sqrt(r88289);
        double r88291 = r88282 + r88290;
        double r88292 = r88291 / r88286;
        return r88292;
}

double f(double a, double b, double c) {
        double r88293 = b;
        double r88294 = -r88293;
        double r88295 = r88293 * r88293;
        double r88296 = 3.0;
        double r88297 = a;
        double r88298 = r88296 * r88297;
        double r88299 = c;
        double r88300 = r88298 * r88299;
        double r88301 = r88295 - r88300;
        double r88302 = sqrt(r88301);
        double r88303 = r88294 + r88302;
        double r88304 = r88303 / r88298;
        double r88305 = -9.495356126792702e-05;
        bool r88306 = r88304 <= r88305;
        double r88307 = -r88301;
        double r88308 = fma(r88293, r88293, r88307);
        double r88309 = r88294 - r88302;
        double r88310 = r88308 / r88309;
        double r88311 = r88310 / r88298;
        double r88312 = -2.9602352982670358e-05;
        bool r88313 = r88304 <= r88312;
        double r88314 = -1.5;
        double r88315 = sqrt(r88293);
        double r88316 = r88297 / r88315;
        double r88317 = r88314 * r88316;
        double r88318 = r88299 / r88315;
        double r88319 = r88317 * r88318;
        double r88320 = r88319 / r88298;
        double r88321 = -9.159912416671133e-07;
        bool r88322 = r88304 <= r88321;
        double r88323 = -0.5;
        double r88324 = r88299 / r88293;
        double r88325 = r88323 * r88324;
        double r88326 = r88322 ? r88311 : r88325;
        double r88327 = r88313 ? r88320 : r88326;
        double r88328 = r88306 ? r88311 : r88327;
        return r88328;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)) < -9.495356126792702e-05 or -2.9602352982670358e-05 < (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)) < -9.159912416671133e-07

    1. Initial program 17.8

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

      \[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \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) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}}{3 \cdot a}\]
    4. Simplified17.0

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

    if -9.495356126792702e-05 < (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)) < -2.9602352982670358e-05

    1. Initial program 22.6

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

      \[\leadsto \frac{\color{blue}{-1.5 \cdot \frac{a \cdot c}{b}}}{3 \cdot a}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt26.6

      \[\leadsto \frac{-1.5 \cdot \frac{a \cdot c}{\color{blue}{\sqrt{b} \cdot \sqrt{b}}}}{3 \cdot a}\]
    5. Applied times-frac26.6

      \[\leadsto \frac{-1.5 \cdot \color{blue}{\left(\frac{a}{\sqrt{b}} \cdot \frac{c}{\sqrt{b}}\right)}}{3 \cdot a}\]
    6. Applied associate-*r*26.6

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

    if -9.159912416671133e-07 < (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a))

    1. Initial program 42.4

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \le -9.4953561267927016 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\ \mathbf{elif}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \le -2.96023529826703576 \cdot 10^{-5}:\\ \;\;\;\;\frac{\left(-1.5 \cdot \frac{a}{\sqrt{b}}\right) \cdot \frac{c}{\sqrt{b}}}{3 \cdot a}\\ \mathbf{elif}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \le -9.1599124166711329 \cdot 10^{-7}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020060 +o rules:numerics
(FPCore (a b c)
  :name "Cubic critical, narrow range"
  :precision binary64
  :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)))