Average Error: 40.2 → 0.6
Time: 16.1s
Precision: 64
Internal Precision: 128
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.9923154788567163:\\ \;\;\;\;\left(e^{x} + 1\right) \cdot \frac{e^{x}}{e^{x} \cdot e^{x} - 1}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{x} + \frac{1}{2}\right) + \frac{1}{12} \cdot x\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (exp x) < 0.9923154788567163

    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)}\]

    if 0.9923154788567163 < (exp x)

    1. Initial program 60.1

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

      \[\leadsto \color{blue}{\frac{1}{12} \cdot x + \left(\frac{1}{x} + \frac{1}{2}\right)}\]
    3. Taylor expanded around 0 0.9

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

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

Reproduce

herbie shell --seed 2019068 
(FPCore (x)
  :name "expq2 (section 3.11)"

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

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