Average Error: 34.2 → 7.6
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.645242538569152 \cdot 10^{+26}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{3}{2}, \left(\frac{a}{\frac{b}{c}}\right), \left(b \cdot -2\right)\right)}{3 \cdot a}\\ \mathbf{elif}\;b \le -6.309006248913749 \cdot 10^{-291}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3}}{a}\\ \mathbf{elif}\;b \le 2.0133657228761008 \cdot 10^{+37}:\\ \;\;\;\;\frac{c}{\left(-b\right) - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}\\ \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}\;b \le -2.645242538569152 \cdot 10^{+26}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{3}{2}, \left(\frac{a}{\frac{b}{c}}\right), \left(b \cdot -2\right)\right)}{3 \cdot a}\\

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

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

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

\end{array}
double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r16762696 = b;
        double r16762697 = -r16762696;
        double r16762698 = r16762696 * r16762696;
        double r16762699 = 3.0;
        double r16762700 = a;
        double r16762701 = r16762699 * r16762700;
        double r16762702 = c;
        double r16762703 = r16762701 * r16762702;
        double r16762704 = r16762698 - r16762703;
        double r16762705 = sqrt(r16762704);
        double r16762706 = r16762697 + r16762705;
        double r16762707 = r16762706 / r16762701;
        return r16762707;
}

double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r16762708 = b;
        double r16762709 = -2.645242538569152e+26;
        bool r16762710 = r16762708 <= r16762709;
        double r16762711 = 1.5;
        double r16762712 = a;
        double r16762713 = c;
        double r16762714 = r16762708 / r16762713;
        double r16762715 = r16762712 / r16762714;
        double r16762716 = -2.0;
        double r16762717 = r16762708 * r16762716;
        double r16762718 = fma(r16762711, r16762715, r16762717);
        double r16762719 = 3.0;
        double r16762720 = r16762719 * r16762712;
        double r16762721 = r16762718 / r16762720;
        double r16762722 = -6.309006248913749e-291;
        bool r16762723 = r16762708 <= r16762722;
        double r16762724 = r16762708 * r16762708;
        double r16762725 = r16762720 * r16762713;
        double r16762726 = r16762724 - r16762725;
        double r16762727 = sqrt(r16762726);
        double r16762728 = -r16762708;
        double r16762729 = r16762727 + r16762728;
        double r16762730 = r16762729 / r16762719;
        double r16762731 = r16762730 / r16762712;
        double r16762732 = 2.0133657228761008e+37;
        bool r16762733 = r16762708 <= r16762732;
        double r16762734 = r16762728 - r16762727;
        double r16762735 = r16762713 / r16762734;
        double r16762736 = r16762713 / r16762708;
        double r16762737 = -0.5;
        double r16762738 = r16762736 * r16762737;
        double r16762739 = r16762733 ? r16762735 : r16762738;
        double r16762740 = r16762723 ? r16762731 : r16762739;
        double r16762741 = r16762710 ? r16762721 : r16762740;
        return r16762741;
}

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.645242538569152e+26

    1. Initial program 34.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.2

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

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

    if -2.645242538569152e+26 < b < -6.309006248913749e-291

    1. Initial program 9.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 associate-/r*9.7

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

    if -6.309006248913749e-291 < b < 2.0133657228761008e+37

    1. Initial program 28.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 flip-+28.7

      \[\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/33.8

      \[\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. Simplified23.8

      \[\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*18.0

      \[\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 0 10.5

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

    if 2.0133657228761008e+37 < b

    1. Initial program 56.2

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

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

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

Reproduce

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