Average Error: 33.5 → 11.5
Time: 11.5s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.269895755919419994119426060411821031835 \cdot 10^{99}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666296592325124947819858789 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le 5.480131987291899458594157601719520740479 \cdot 10^{-168}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{3 \cdot a}\\ \mathbf{elif}\;b \le 6.194358139220983814753525365719850242403 \cdot 10^{-110} \lor \neg \left(b \le 1.846537578115044209159378851836663670838 \cdot 10^{-4}\right):\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(3 \cdot a\right) \cdot c\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + b}}{3 \cdot a}\\ \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}\;b \le -1.269895755919419994119426060411821031835 \cdot 10^{99}:\\
\;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666296592325124947819858789 \cdot \frac{b}{a}\\

\mathbf{elif}\;b \le 5.480131987291899458594157601719520740479 \cdot 10^{-168}:\\
\;\;\;\;\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{3 \cdot a}\\

\mathbf{elif}\;b \le 6.194358139220983814753525365719850242403 \cdot 10^{-110} \lor \neg \left(b \le 1.846537578115044209159378851836663670838 \cdot 10^{-4}\right):\\
\;\;\;\;-0.5 \cdot \frac{c}{b}\\

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

\end{array}
double f(double a, double b, double c) {
        double r113059 = b;
        double r113060 = -r113059;
        double r113061 = r113059 * r113059;
        double r113062 = 3.0;
        double r113063 = a;
        double r113064 = r113062 * r113063;
        double r113065 = c;
        double r113066 = r113064 * r113065;
        double r113067 = r113061 - r113066;
        double r113068 = sqrt(r113067);
        double r113069 = r113060 + r113068;
        double r113070 = r113069 / r113064;
        return r113070;
}

double f(double a, double b, double c) {
        double r113071 = b;
        double r113072 = -1.26989575591942e+99;
        bool r113073 = r113071 <= r113072;
        double r113074 = 0.5;
        double r113075 = c;
        double r113076 = r113075 / r113071;
        double r113077 = r113074 * r113076;
        double r113078 = 0.6666666666666666;
        double r113079 = a;
        double r113080 = r113071 / r113079;
        double r113081 = r113078 * r113080;
        double r113082 = r113077 - r113081;
        double r113083 = 5.480131987291899e-168;
        bool r113084 = r113071 <= r113083;
        double r113085 = r113071 * r113071;
        double r113086 = 3.0;
        double r113087 = r113086 * r113079;
        double r113088 = r113087 * r113075;
        double r113089 = r113085 - r113088;
        double r113090 = sqrt(r113089);
        double r113091 = r113090 - r113071;
        double r113092 = 1.0;
        double r113093 = r113092 / r113087;
        double r113094 = r113091 * r113093;
        double r113095 = 6.194358139220984e-110;
        bool r113096 = r113071 <= r113095;
        double r113097 = 0.00018465375781150442;
        bool r113098 = r113071 <= r113097;
        double r113099 = !r113098;
        bool r113100 = r113096 || r113099;
        double r113101 = -0.5;
        double r113102 = r113101 * r113076;
        double r113103 = fma(r113071, r113071, r113088);
        double r113104 = r113085 - r113103;
        double r113105 = r113090 + r113071;
        double r113106 = r113104 / r113105;
        double r113107 = r113106 / r113087;
        double r113108 = r113100 ? r113102 : r113107;
        double r113109 = r113084 ? r113094 : r113108;
        double r113110 = r113073 ? r113082 : r113109;
        return r113110;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -1.26989575591942e+99

    1. Initial program 46.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified46.5

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}}\]
    3. Taylor expanded around -inf 4.4

      \[\leadsto \color{blue}{0.5 \cdot \frac{c}{b} - 0.6666666666666666296592325124947819858789 \cdot \frac{b}{a}}\]

    if -1.26989575591942e+99 < b < 5.480131987291899e-168

    1. Initial program 10.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified10.3

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv10.4

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

    if 5.480131987291899e-168 < b < 6.194358139220984e-110 or 0.00018465375781150442 < b

    1. Initial program 51.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified51.7

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}}\]
    3. Taylor expanded around inf 10.4

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}}\]

    if 6.194358139220984e-110 < b < 0.00018465375781150442

    1. Initial program 34.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Simplified34.6

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}}\]
    3. Using strategy rm
    4. Applied flip--34.6

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b \cdot b}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + b}}}{3 \cdot a}\]
    5. Simplified34.7

      \[\leadsto \frac{\frac{\color{blue}{b \cdot b - \mathsf{fma}\left(b, b, \left(3 \cdot a\right) \cdot c\right)}}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + b}}{3 \cdot a}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.269895755919419994119426060411821031835 \cdot 10^{99}:\\ \;\;\;\;0.5 \cdot \frac{c}{b} - 0.6666666666666666296592325124947819858789 \cdot \frac{b}{a}\\ \mathbf{elif}\;b \le 5.480131987291899458594157601719520740479 \cdot 10^{-168}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{3 \cdot a}\\ \mathbf{elif}\;b \le 6.194358139220983814753525365719850242403 \cdot 10^{-110} \lor \neg \left(b \le 1.846537578115044209159378851836663670838 \cdot 10^{-4}\right):\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(3 \cdot a\right) \cdot c\right)}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + b}}{3 \cdot a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019350 +o rules:numerics
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3 a) c)))) (* 3 a)))