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

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{expm1}\left(\left(\sqrt[3]{\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)\right)} \cdot \sqrt[3]{\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)\right)}\right) \cdot \sqrt[3]{\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)\right)}\right)\right) + \frac{1}{x}\\

\end{array}
double f(double x) {
        double r4959468 = x;
        double r4959469 = exp(r4959468);
        double r4959470 = 1.0;
        double r4959471 = r4959469 - r4959470;
        double r4959472 = r4959469 / r4959471;
        return r4959472;
}

double f(double x) {
        double r4959473 = x;
        double r4959474 = -0.0015746675324234964;
        bool r4959475 = r4959473 <= r4959474;
        double r4959476 = exp(r4959473);
        double r4959477 = 2.0;
        double r4959478 = fma(r4959473, r4959477, r4959473);
        double r4959479 = exp(r4959478);
        double r4959480 = 1.0;
        double r4959481 = r4959480 * r4959480;
        double r4959482 = r4959481 * r4959480;
        double r4959483 = r4959479 - r4959482;
        double r4959484 = r4959476 + r4959480;
        double r4959485 = r4959480 * r4959484;
        double r4959486 = fma(r4959476, r4959476, r4959485);
        double r4959487 = r4959483 / r4959486;
        double r4959488 = r4959476 / r4959487;
        double r4959489 = 0.08333333333333333;
        double r4959490 = 0.5;
        double r4959491 = fma(r4959489, r4959473, r4959490);
        double r4959492 = log1p(r4959491);
        double r4959493 = log1p(r4959492);
        double r4959494 = cbrt(r4959493);
        double r4959495 = r4959494 * r4959494;
        double r4959496 = r4959495 * r4959494;
        double r4959497 = expm1(r4959496);
        double r4959498 = expm1(r4959497);
        double r4959499 = 1.0;
        double r4959500 = r4959499 / r4959473;
        double r4959501 = r4959498 + r4959500;
        double r4959502 = r4959475 ? r4959488 : r4959501;
        return r4959502;
}

Error

Bits error versus x

Target

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

Derivation

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

    1. Initial program 0.0

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

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

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

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

    if -0.0015746675324234964 < x

    1. Initial program 61.7

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

      \[\leadsto \color{blue}{\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)}\]
    3. Simplified0.8

      \[\leadsto \color{blue}{\frac{1}{x} + \mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)}\]
    4. Using strategy rm
    5. Applied expm1-log1p-u0.8

      \[\leadsto \frac{1}{x} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)\right)}\]
    6. Using strategy rm
    7. Applied expm1-log1p-u0.8

      \[\leadsto \frac{1}{x} + \mathsf{expm1}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{2}\right)\right)\right)\right)}\right)\]
    8. Using strategy rm
    9. Applied add-cube-cbrt0.8

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

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

Reproduce

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

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

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