Average Error: 40.4 → 0.7
Time: 39.2s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1.0}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.043762652068368615:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{e^{x}}{e^{x} - 1.0}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{1}{12}, \frac{1}{2}\right) + \frac{1}{x}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1.0}
\begin{array}{l}
\mathbf{if}\;x \le -0.043762652068368615:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{e^{x}}{e^{x} - 1.0}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{1}{12}, \frac{1}{2}\right) + \frac{1}{x}\\

\end{array}
double f(double x) {
        double r4218134 = x;
        double r4218135 = exp(r4218134);
        double r4218136 = 1.0;
        double r4218137 = r4218135 - r4218136;
        double r4218138 = r4218135 / r4218137;
        return r4218138;
}

double f(double x) {
        double r4218139 = x;
        double r4218140 = -0.043762652068368615;
        bool r4218141 = r4218139 <= r4218140;
        double r4218142 = exp(r4218139);
        double r4218143 = 1.0;
        double r4218144 = r4218142 - r4218143;
        double r4218145 = r4218142 / r4218144;
        double r4218146 = expm1(r4218145);
        double r4218147 = log1p(r4218146);
        double r4218148 = 0.08333333333333333;
        double r4218149 = 0.5;
        double r4218150 = fma(r4218139, r4218148, r4218149);
        double r4218151 = 1.0;
        double r4218152 = r4218151 / r4218139;
        double r4218153 = r4218150 + r4218152;
        double r4218154 = r4218141 ? r4218147 : r4218153;
        return r4218154;
}

Error

Bits error versus x

Target

Original40.4
Target40.0
Herbie0.7
\[\frac{1.0}{1.0 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1.0}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.0

      \[\leadsto \frac{e^{x}}{e^{x} - \color{blue}{\sqrt{1.0} \cdot \sqrt{1.0}}}\]
    4. Applied add-sqr-sqrt0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}} - \sqrt{1.0} \cdot \sqrt{1.0}}\]
    5. Applied difference-of-squares0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{\left(\sqrt{e^{x}} + \sqrt{1.0}\right) \cdot \left(\sqrt{e^{x}} - \sqrt{1.0}\right)}}\]
    6. Applied *-un-lft-identity0.0

      \[\leadsto \frac{\color{blue}{1 \cdot e^{x}}}{\left(\sqrt{e^{x}} + \sqrt{1.0}\right) \cdot \left(\sqrt{e^{x}} - \sqrt{1.0}\right)}\]
    7. Applied times-frac0.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{e^{x}} + \sqrt{1.0}} \cdot \frac{e^{x}}{\sqrt{e^{x}} - \sqrt{1.0}}}\]
    8. Using strategy rm
    9. Applied log1p-expm1-u0.0

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\sqrt{e^{x}} + \sqrt{1.0}} \cdot \frac{e^{x}}{\sqrt{e^{x}} - \sqrt{1.0}}\right)\right)}\]
    10. Simplified0.0

      \[\leadsto \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\frac{e^{x}}{e^{x} - 1.0}\right)}\right)\]

    if -0.043762652068368615 < x

    1. Initial program 61.7

      \[\frac{e^{x}}{e^{x} - 1.0}\]
    2. Taylor expanded around 0 1.2

      \[\leadsto \frac{e^{x}}{\color{blue}{x + \left(\frac{1}{6} \cdot {x}^{3} + \frac{1}{2} \cdot {x}^{2}\right)}}\]
    3. Simplified1.2

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

      \[\leadsto \color{blue}{\frac{1}{12} \cdot x + \left(\frac{1}{x} + \frac{1}{2}\right)}\]
    5. Simplified1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.043762652068368615:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{e^{x}}{e^{x} - 1.0}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{1}{12}, \frac{1}{2}\right) + \frac{1}{x}\\ \end{array}\]

Reproduce

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

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

  (/ (exp x) (- (exp x) 1.0)))