Average Error: 40.1 → 0.7
Time: 8.7s
Precision: 64
Internal Precision: 128
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.6978818580996201:\\ \;\;\;\;(e^{\log_* (1 + \frac{e^{x}}{(e^{x} - 1)^*})} - 1)^*\\ \mathbf{else}:\\ \;\;\;\;(x \cdot \frac{1}{12} + \frac{1}{2})_* + \frac{1}{x}\\ \end{array}\]

Error

Bits error versus x

Target

Original40.1
Target39.7
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied expm1-def0.0

      \[\leadsto \frac{e^{x}}{\color{blue}{(e^{x} - 1)^*}}\]
    4. Using strategy rm
    5. Applied expm1-log1p-u0.0

      \[\leadsto \color{blue}{(e^{\log_* (1 + \frac{e^{x}}{(e^{x} - 1)^*})} - 1)^*}\]

    if -0.6978818580996201 < x

    1. Initial program 59.8

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied expm1-def0.5

      \[\leadsto \frac{e^{x}}{\color{blue}{(e^{x} - 1)^*}}\]
    4. Using strategy rm
    5. Applied expm1-log1p-u34.7

      \[\leadsto \color{blue}{(e^{\log_* (1 + \frac{e^{x}}{(e^{x} - 1)^*})} - 1)^*}\]
    6. Taylor expanded around 0 35.0

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

      \[\leadsto \color{blue}{\frac{1}{x} + (x \cdot \frac{1}{12} + \frac{1}{2})_*}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.6978818580996201:\\ \;\;\;\;(e^{\log_* (1 + \frac{e^{x}}{(e^{x} - 1)^*})} - 1)^*\\ \mathbf{else}:\\ \;\;\;\;(x \cdot \frac{1}{12} + \frac{1}{2})_* + \frac{1}{x}\\ \end{array}\]

Reproduce

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

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

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