Average Error: 29.0 → 14.9
Time: 17.7s
Precision: 64
\[1.0536712127723509 \cdot 10^{-08} \lt a \lt 94906265.62425156 \land 1.0536712127723509 \cdot 10^{-08} \lt b \lt 94906265.62425156 \land 1.0536712127723509 \cdot 10^{-08} \lt c \lt 94906265.62425156\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3 \cdot a} \le -5.333265036834221 \cdot 10^{-06}:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)} \cdot \mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right) - b \cdot \left(b \cdot b\right)}{b \cdot \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)} + \mathsf{fma}\left(b, b, \mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{c}{b} \cdot \frac{-1}{2}\right)\right)\\ \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{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3 \cdot a} \le -5.333265036834221 \cdot 10^{-06}:\\
\;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)} \cdot \mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right) - b \cdot \left(b \cdot b\right)}{b \cdot \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)} + \mathsf{fma}\left(b, b, \mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)\right)}}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{c}{b} \cdot \frac{-1}{2}\right)\right)\\

\end{array}
double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r3045625 = b;
        double r3045626 = -r3045625;
        double r3045627 = r3045625 * r3045625;
        double r3045628 = 3.0;
        double r3045629 = a;
        double r3045630 = r3045628 * r3045629;
        double r3045631 = c;
        double r3045632 = r3045630 * r3045631;
        double r3045633 = r3045627 - r3045632;
        double r3045634 = sqrt(r3045633);
        double r3045635 = r3045626 + r3045634;
        double r3045636 = r3045635 / r3045630;
        return r3045636;
}

double f(double a, double b, double c, double __attribute__((unused)) d) {
        double r3045637 = b;
        double r3045638 = r3045637 * r3045637;
        double r3045639 = 3.0;
        double r3045640 = a;
        double r3045641 = r3045639 * r3045640;
        double r3045642 = c;
        double r3045643 = r3045641 * r3045642;
        double r3045644 = r3045638 - r3045643;
        double r3045645 = sqrt(r3045644);
        double r3045646 = -r3045637;
        double r3045647 = r3045645 + r3045646;
        double r3045648 = r3045647 / r3045641;
        double r3045649 = -5.333265036834221e-06;
        bool r3045650 = r3045648 <= r3045649;
        double r3045651 = -3.0;
        double r3045652 = r3045651 * r3045640;
        double r3045653 = r3045652 * r3045642;
        double r3045654 = fma(r3045637, r3045637, r3045653);
        double r3045655 = sqrt(r3045654);
        double r3045656 = r3045655 * r3045654;
        double r3045657 = r3045637 * r3045638;
        double r3045658 = r3045656 - r3045657;
        double r3045659 = r3045637 * r3045655;
        double r3045660 = fma(r3045637, r3045637, r3045654);
        double r3045661 = r3045659 + r3045660;
        double r3045662 = r3045658 / r3045661;
        double r3045663 = r3045662 / r3045641;
        double r3045664 = r3045642 / r3045637;
        double r3045665 = -0.5;
        double r3045666 = r3045664 * r3045665;
        double r3045667 = expm1(r3045666);
        double r3045668 = log1p(r3045667);
        double r3045669 = r3045650 ? r3045663 : r3045668;
        return r3045669;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Derivation

  1. Split input into 2 regimes
  2. if (/ (+ (- b) (sqrt (- (* b b) (* (* 3 a) c)))) (* 3 a)) < -5.333265036834221e-06

    1. Initial program 17.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 flip3-+17.7

      \[\leadsto \frac{\color{blue}{\frac{{\left(-b\right)}^{3} + {\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}^{3}}{\left(-b\right) \cdot \left(-b\right) + \left(\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) \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}}{3 \cdot a}\]
    4. Simplified17.0

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-3 \cdot a\right)\right)} \cdot \mathsf{fma}\left(b, b, c \cdot \left(-3 \cdot a\right)\right) - \left(b \cdot b\right) \cdot b}}{\left(-b\right) \cdot \left(-b\right) + \left(\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) \cdot \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}\]
    5. Simplified17.1

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

    if -5.333265036834221e-06 < (/ (+ (- b) (sqrt (- (* b b) (* (* 3 a) c)))) (* 3 a))

    1. Initial program 41.0

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

      \[\leadsto \frac{\color{blue}{\frac{-3}{2} \cdot \frac{a \cdot c}{b}}}{3 \cdot a}\]
    3. Using strategy rm
    4. Applied clear-num12.8

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{a}{\frac{-1}{2}}}{\frac{a}{b} \cdot c}}}\]
    6. Using strategy rm
    7. Applied log1p-expm1-u12.7

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\frac{\frac{a}{\frac{-1}{2}}}{\frac{a}{b} \cdot c}}\right)\right)}\]
    8. Simplified12.6

      \[\leadsto \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\frac{-1}{2} \cdot \frac{c}{1 \cdot b}\right)}\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}{3 \cdot a} \le -5.333265036834221 \cdot 10^{-06}:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)} \cdot \mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right) - b \cdot \left(b \cdot b\right)}{b \cdot \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)} + \mathsf{fma}\left(b, b, \mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{c}{b} \cdot \frac{-1}{2}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019135 +o rules:numerics
(FPCore (a b c d)
  :name "Cubic critical, narrow range"
  :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)))