Average Error: 41.2 → 0.6
Time: 45.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 r4244503 = x;
        double r4244504 = exp(r4244503);
        double r4244505 = 1.0;
        double r4244506 = r4244504 - r4244505;
        double r4244507 = r4244504 / r4244506;
        return r4244507;
}

double f(double x) {
        double r4244508 = x;
        double r4244509 = -0.0015746675324234964;
        bool r4244510 = r4244508 <= r4244509;
        double r4244511 = exp(r4244508);
        double r4244512 = 2.0;
        double r4244513 = fma(r4244508, r4244512, r4244508);
        double r4244514 = exp(r4244513);
        double r4244515 = 1.0;
        double r4244516 = r4244515 * r4244515;
        double r4244517 = r4244516 * r4244515;
        double r4244518 = r4244514 - r4244517;
        double r4244519 = r4244511 + r4244515;
        double r4244520 = r4244515 * r4244519;
        double r4244521 = fma(r4244511, r4244511, r4244520);
        double r4244522 = r4244518 / r4244521;
        double r4244523 = r4244511 / r4244522;
        double r4244524 = 0.08333333333333333;
        double r4244525 = 0.5;
        double r4244526 = fma(r4244524, r4244508, r4244525);
        double r4244527 = log1p(r4244526);
        double r4244528 = log1p(r4244527);
        double r4244529 = cbrt(r4244528);
        double r4244530 = r4244529 * r4244529;
        double r4244531 = r4244530 * r4244529;
        double r4244532 = expm1(r4244531);
        double r4244533 = expm1(r4244532);
        double r4244534 = 1.0;
        double r4244535 = r4244534 / r4244508;
        double r4244536 = r4244533 + r4244535;
        double r4244537 = r4244510 ? r4244523 : r4244536;
        return r4244537;
}

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)))