Average Error: 41.2 → 0.7
Time: 3.4s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0090606316929431226:\\ \;\;\;\;\left(\frac{\sqrt{e^{x}}}{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}} \cdot \frac{\sqrt{e^{x}}}{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}\right) \cdot \left(e^{x} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-x, \frac{1}{12}, \mathsf{fma}\left({x}^{3}, \frac{7}{720}, \frac{\frac{1}{2}}{x}\right)\right) \cdot \left(e^{x} + 1\right)\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \le -0.0090606316929431226:\\
\;\;\;\;\left(\frac{\sqrt{e^{x}}}{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}} \cdot \frac{\sqrt{e^{x}}}{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}\right) \cdot \left(e^{x} + 1\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, \frac{1}{12}, \mathsf{fma}\left({x}^{3}, \frac{7}{720}, \frac{\frac{1}{2}}{x}\right)\right) \cdot \left(e^{x} + 1\right)\\

\end{array}
double f(double x) {
        double r56129 = x;
        double r56130 = exp(r56129);
        double r56131 = 1.0;
        double r56132 = r56130 - r56131;
        double r56133 = r56130 / r56132;
        return r56133;
}

double f(double x) {
        double r56134 = x;
        double r56135 = -0.009060631692943123;
        bool r56136 = r56134 <= r56135;
        double r56137 = exp(r56134);
        double r56138 = sqrt(r56137);
        double r56139 = 1.0;
        double r56140 = -r56139;
        double r56141 = r56134 + r56134;
        double r56142 = exp(r56141);
        double r56143 = fma(r56140, r56139, r56142);
        double r56144 = cbrt(r56143);
        double r56145 = r56144 * r56144;
        double r56146 = r56138 / r56145;
        double r56147 = r56138 / r56144;
        double r56148 = r56146 * r56147;
        double r56149 = r56137 + r56139;
        double r56150 = r56148 * r56149;
        double r56151 = -r56134;
        double r56152 = 0.08333333333333333;
        double r56153 = 3.0;
        double r56154 = pow(r56134, r56153);
        double r56155 = 0.009722222222222222;
        double r56156 = 0.5;
        double r56157 = r56156 / r56134;
        double r56158 = fma(r56154, r56155, r56157);
        double r56159 = fma(r56151, r56152, r56158);
        double r56160 = r56159 * r56149;
        double r56161 = r56136 ? r56150 : r56160;
        return r56161;
}

Error

Bits error versus x

Target

Original41.2
Target40.8
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -0.009060631692943123

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied flip--0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}\]
    4. Applied associate-/r/0.0

      \[\leadsto \color{blue}{\frac{e^{x}}{e^{x} \cdot e^{x} - 1 \cdot 1} \cdot \left(e^{x} + 1\right)}\]
    5. Simplified0.0

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}} \cdot \left(e^{x} + 1\right)\]
    6. Using strategy rm
    7. Applied add-cube-cbrt0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}} \cdot \left(e^{x} + 1\right)\]
    8. Applied add-sqr-sqrt0.0

      \[\leadsto \frac{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}}}{\left(\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}} \cdot \left(e^{x} + 1\right)\]
    9. Applied times-frac0.0

      \[\leadsto \color{blue}{\left(\frac{\sqrt{e^{x}}}{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}} \cdot \frac{\sqrt{e^{x}}}{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}\right)} \cdot \left(e^{x} + 1\right)\]

    if -0.009060631692943123 < x

    1. Initial program 61.9

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied flip--62.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}\]
    4. Applied associate-/r/62.0

      \[\leadsto \color{blue}{\frac{e^{x}}{e^{x} \cdot e^{x} - 1 \cdot 1} \cdot \left(e^{x} + 1\right)}\]
    5. Simplified61.9

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}} \cdot \left(e^{x} + 1\right)\]
    6. Taylor expanded around 0 1.0

      \[\leadsto \color{blue}{\left(\left(\frac{7}{720} \cdot {x}^{3} + \frac{1}{2} \cdot \frac{1}{x}\right) - \frac{1}{12} \cdot x\right)} \cdot \left(e^{x} + 1\right)\]
    7. Simplified1.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(-x, \frac{1}{12}, \mathsf{fma}\left({x}^{3}, \frac{7}{720}, \frac{\frac{1}{2}}{x}\right)\right)} \cdot \left(e^{x} + 1\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0090606316929431226:\\ \;\;\;\;\left(\frac{\sqrt{e^{x}}}{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}} \cdot \frac{\sqrt{e^{x}}}{\sqrt[3]{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}}\right) \cdot \left(e^{x} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-x, \frac{1}{12}, \mathsf{fma}\left({x}^{3}, \frac{7}{720}, \frac{\frac{1}{2}}{x}\right)\right) \cdot \left(e^{x} + 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020089 +o rules:numerics
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

  :herbie-target
  (/ 1 (- 1 (exp (- x))))

  (/ (exp x) (- (exp x) 1)))