Average Error: 33.2 → 6.8
Time: 1.9m
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 -2.460834059807099 \cdot 10^{+151}:\\ \;\;\;\;(\left(\frac{c}{b}\right) \cdot \frac{1}{2} + \left(b \cdot \frac{\frac{-2}{3}}{a}\right))_*\\ \mathbf{elif}\;b \le -1.9411282949730873 \cdot 10^{-271}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} + \left(-b\right)}{3}}{a}\\ \mathbf{elif}\;b \le 3.7064366554203504 \cdot 10^{+36}:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \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}\;b \le -2.460834059807099 \cdot 10^{+151}:\\
\;\;\;\;(\left(\frac{c}{b}\right) \cdot \frac{1}{2} + \left(b \cdot \frac{\frac{-2}{3}}{a}\right))_*\\

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

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

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

\end{array}
double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r15394761 = b;
        double r15394762 = -r15394761;
        double r15394763 = r15394761 * r15394761;
        double r15394764 = 3.0;
        double r15394765 = a;
        double r15394766 = r15394764 * r15394765;
        double r15394767 = c;
        double r15394768 = r15394766 * r15394767;
        double r15394769 = r15394763 - r15394768;
        double r15394770 = sqrt(r15394769);
        double r15394771 = r15394762 + r15394770;
        double r15394772 = r15394771 / r15394766;
        return r15394772;
}

double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r15394773 = b;
        double r15394774 = -2.460834059807099e+151;
        bool r15394775 = r15394773 <= r15394774;
        double r15394776 = c;
        double r15394777 = r15394776 / r15394773;
        double r15394778 = 0.5;
        double r15394779 = -0.6666666666666666;
        double r15394780 = a;
        double r15394781 = r15394779 / r15394780;
        double r15394782 = r15394773 * r15394781;
        double r15394783 = fma(r15394777, r15394778, r15394782);
        double r15394784 = -1.9411282949730873e-271;
        bool r15394785 = r15394773 <= r15394784;
        double r15394786 = r15394773 * r15394773;
        double r15394787 = 3.0;
        double r15394788 = r15394787 * r15394780;
        double r15394789 = r15394776 * r15394788;
        double r15394790 = r15394786 - r15394789;
        double r15394791 = sqrt(r15394790);
        double r15394792 = -r15394773;
        double r15394793 = r15394791 + r15394792;
        double r15394794 = r15394793 / r15394787;
        double r15394795 = r15394794 / r15394780;
        double r15394796 = 3.7064366554203504e+36;
        bool r15394797 = r15394773 <= r15394796;
        double r15394798 = r15394792 - r15394791;
        double r15394799 = r15394776 / r15394798;
        double r15394800 = -0.5;
        double r15394801 = r15394800 * r15394777;
        double r15394802 = r15394797 ? r15394799 : r15394801;
        double r15394803 = r15394785 ? r15394795 : r15394802;
        double r15394804 = r15394775 ? r15394783 : r15394803;
        return r15394804;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Derivation

  1. Split input into 4 regimes
  2. if b < -2.460834059807099e+151

    1. Initial program 59.7

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{c}{b} - \frac{2}{3} \cdot \frac{b}{a}}\]
    3. Simplified2.1

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

    if -2.460834059807099e+151 < b < -1.9411282949730873e-271

    1. Initial program 8.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-/r*8.5

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

    if -1.9411282949730873e-271 < b < 3.7064366554203504e+36

    1. Initial program 26.5

      \[\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-+26.6

      \[\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. Applied associate-/l/31.9

      \[\leadsto \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(3 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}\]
    5. Simplified22.0

      \[\leadsto \frac{\color{blue}{3 \cdot \left(c \cdot a\right)}}{\left(3 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}\]
    6. Using strategy rm
    7. Applied associate-/r*16.2

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

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

    if 3.7064366554203504e+36 < b

    1. Initial program 56.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.460834059807099 \cdot 10^{+151}:\\ \;\;\;\;(\left(\frac{c}{b}\right) \cdot \frac{1}{2} + \left(b \cdot \frac{\frac{-2}{3}}{a}\right))_*\\ \mathbf{elif}\;b \le -1.9411282949730873 \cdot 10^{-271}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} + \left(-b\right)}{3}}{a}\\ \mathbf{elif}\;b \le 3.7064366554203504 \cdot 10^{+36}:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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