Average Error: 33.7 → 13.8
Time: 20.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 3.540658906187422 \cdot 10^{-306}:\\ \;\;\;\;\frac{\frac{1}{3}}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b\right)\\ \mathbf{elif}\;b \le 1.1954432159183648 \cdot 10^{+151}:\\ \;\;\;\;\frac{-c}{b + \sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{3}}{a} \cdot \mathsf{fma}\left(c, \left(-3 \cdot a\right), 0\right)}{b + 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 3.540658906187422 \cdot 10^{-306}:\\
\;\;\;\;\frac{\frac{1}{3}}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b\right)\\

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

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

\end{array}
double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r3950802 = b;
        double r3950803 = -r3950802;
        double r3950804 = r3950802 * r3950802;
        double r3950805 = 3.0;
        double r3950806 = a;
        double r3950807 = r3950805 * r3950806;
        double r3950808 = c;
        double r3950809 = r3950807 * r3950808;
        double r3950810 = r3950804 - r3950809;
        double r3950811 = sqrt(r3950810);
        double r3950812 = r3950803 + r3950811;
        double r3950813 = r3950812 / r3950807;
        return r3950813;
}

double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r3950814 = b;
        double r3950815 = 3.540658906187422e-306;
        bool r3950816 = r3950814 <= r3950815;
        double r3950817 = 0.3333333333333333;
        double r3950818 = a;
        double r3950819 = r3950817 / r3950818;
        double r3950820 = c;
        double r3950821 = -3.0;
        double r3950822 = r3950821 * r3950818;
        double r3950823 = r3950814 * r3950814;
        double r3950824 = fma(r3950820, r3950822, r3950823);
        double r3950825 = sqrt(r3950824);
        double r3950826 = r3950825 - r3950814;
        double r3950827 = r3950819 * r3950826;
        double r3950828 = 1.1954432159183648e+151;
        bool r3950829 = r3950814 <= r3950828;
        double r3950830 = -r3950820;
        double r3950831 = r3950814 + r3950825;
        double r3950832 = r3950830 / r3950831;
        double r3950833 = 0.0;
        double r3950834 = fma(r3950820, r3950822, r3950833);
        double r3950835 = r3950819 * r3950834;
        double r3950836 = r3950814 + r3950814;
        double r3950837 = r3950835 / r3950836;
        double r3950838 = r3950829 ? r3950832 : r3950837;
        double r3950839 = r3950816 ? r3950827 : r3950838;
        return r3950839;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Derivation

  1. Split input into 3 regimes
  2. if b < 3.540658906187422e-306

    1. Initial program 20.9

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

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

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

      \[\leadsto \left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b\right) \cdot \color{blue}{\frac{\frac{1}{3}}{a}}\]
    6. Using strategy rm
    7. Applied div-inv21.1

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

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

    if 3.540658906187422e-306 < b < 1.1954432159183648e+151

    1. Initial program 34.7

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

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

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

      \[\leadsto \left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b\right) \cdot \color{blue}{\frac{\frac{1}{3}}{a}}\]
    6. Using strategy rm
    7. Applied div-inv34.8

      \[\leadsto \left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b\right) \cdot \color{blue}{\left(\frac{1}{3} \cdot \frac{1}{a}\right)}\]
    8. Using strategy rm
    9. Applied flip--34.8

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} \cdot \sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b \cdot b}{\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} + b}} \cdot \left(\frac{1}{3} \cdot \frac{1}{a}\right)\]
    10. Applied associate-*l/34.9

      \[\leadsto \color{blue}{\frac{\left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} \cdot \sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b \cdot b\right) \cdot \left(\frac{1}{3} \cdot \frac{1}{a}\right)}{\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} + b}}\]
    11. Simplified14.9

      \[\leadsto \frac{\color{blue}{\frac{\frac{1}{3}}{a} \cdot \mathsf{fma}\left(c, \left(a \cdot -3\right), 0\right)}}{\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} + b}\]
    12. Taylor expanded around 0 8.5

      \[\leadsto \frac{\color{blue}{-1 \cdot c}}{\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} + b}\]
    13. Simplified8.5

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

    if 1.1954432159183648e+151 < b

    1. Initial program 62.5

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

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

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

      \[\leadsto \left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b\right) \cdot \color{blue}{\frac{\frac{1}{3}}{a}}\]
    6. Using strategy rm
    7. Applied div-inv62.6

      \[\leadsto \left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b\right) \cdot \color{blue}{\left(\frac{1}{3} \cdot \frac{1}{a}\right)}\]
    8. Using strategy rm
    9. Applied flip--62.6

      \[\leadsto \color{blue}{\frac{\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} \cdot \sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b \cdot b}{\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} + b}} \cdot \left(\frac{1}{3} \cdot \frac{1}{a}\right)\]
    10. Applied associate-*l/62.6

      \[\leadsto \color{blue}{\frac{\left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} \cdot \sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b \cdot b\right) \cdot \left(\frac{1}{3} \cdot \frac{1}{a}\right)}{\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} + b}}\]
    11. Simplified38.0

      \[\leadsto \frac{\color{blue}{\frac{\frac{1}{3}}{a} \cdot \mathsf{fma}\left(c, \left(a \cdot -3\right), 0\right)}}{\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} + b}\]
    12. Taylor expanded around 0 6.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 3.540658906187422 \cdot 10^{-306}:\\ \;\;\;\;\frac{\frac{1}{3}}{a} \cdot \left(\sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)} - b\right)\\ \mathbf{elif}\;b \le 1.1954432159183648 \cdot 10^{+151}:\\ \;\;\;\;\frac{-c}{b + \sqrt{\mathsf{fma}\left(c, \left(-3 \cdot a\right), \left(b \cdot b\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{3}}{a} \cdot \mathsf{fma}\left(c, \left(-3 \cdot a\right), 0\right)}{b + b}\\ \end{array}\]

Reproduce

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