Average Error: 28.4 → 15.0
Time: 4.2s
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 r89834 = b;
        double r89835 = -r89834;
        double r89836 = r89834 * r89834;
        double r89837 = 3.0;
        double r89838 = a;
        double r89839 = r89837 * r89838;
        double r89840 = c;
        double r89841 = r89839 * r89840;
        double r89842 = r89836 - r89841;
        double r89843 = sqrt(r89842);
        double r89844 = r89835 + r89843;
        double r89845 = r89844 / r89839;
        return r89845;
}

double f(double a, double b, double c) {
        double r89846 = b;
        double r89847 = -r89846;
        double r89848 = r89846 * r89846;
        double r89849 = 3.0;
        double r89850 = a;
        double r89851 = r89849 * r89850;
        double r89852 = c;
        double r89853 = r89851 * r89852;
        double r89854 = r89848 - r89853;
        double r89855 = sqrt(r89854);
        double r89856 = r89847 + r89855;
        double r89857 = r89856 / r89851;
        double r89858 = -9.495356126792702e-05;
        bool r89859 = r89857 <= r89858;
        double r89860 = -r89854;
        double r89861 = fma(r89846, r89846, r89860);
        double r89862 = r89847 - r89855;
        double r89863 = r89861 / r89862;
        double r89864 = r89863 / r89851;
        double r89865 = -2.9602352982670358e-05;
        bool r89866 = r89857 <= r89865;
        double r89867 = -1.5;
        double r89868 = sqrt(r89846);
        double r89869 = r89850 / r89868;
        double r89870 = r89867 * r89869;
        double r89871 = r89852 / r89868;
        double r89872 = r89870 * r89871;
        double r89873 = r89872 / r89851;
        double r89874 = -9.159912416671133e-07;
        bool r89875 = r89857 <= r89874;
        double r89876 = -0.5;
        double r89877 = r89852 / r89846;
        double r89878 = r89876 * r89877;
        double r89879 = r89875 ? r89864 : r89878;
        double r89880 = r89866 ? r89873 : r89879;
        double r89881 = r89859 ? r89864 : r89880;
        return r89881;
}

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)))