Average Error: 39.5 → 0.7
Time: 15.3s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.9436761867628915 \cdot 10^{-05}:\\ \;\;\;\;\frac{e^{x}}{\frac{e^{x} \cdot e^{x} + -1}{e^{x} + 1}}\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\frac{1}{12} \cdot x\right)\right) + \left(\frac{1}{x} + \frac{1}{2}\right)\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \le -2.9436761867628915 \cdot 10^{-05}:\\
\;\;\;\;\frac{e^{x}}{\frac{e^{x} \cdot e^{x} + -1}{e^{x} + 1}}\\

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

\end{array}
double f(double x) {
        double r1771138 = x;
        double r1771139 = exp(r1771138);
        double r1771140 = 1.0;
        double r1771141 = r1771139 - r1771140;
        double r1771142 = r1771139 / r1771141;
        return r1771142;
}

double f(double x) {
        double r1771143 = x;
        double r1771144 = -2.9436761867628915e-05;
        bool r1771145 = r1771143 <= r1771144;
        double r1771146 = exp(r1771143);
        double r1771147 = r1771146 * r1771146;
        double r1771148 = -1.0;
        double r1771149 = r1771147 + r1771148;
        double r1771150 = 1.0;
        double r1771151 = r1771146 + r1771150;
        double r1771152 = r1771149 / r1771151;
        double r1771153 = r1771146 / r1771152;
        double r1771154 = 0.08333333333333333;
        double r1771155 = r1771154 * r1771143;
        double r1771156 = /* ERROR: no posit support in C */;
        double r1771157 = /* ERROR: no posit support in C */;
        double r1771158 = r1771150 / r1771143;
        double r1771159 = 0.5;
        double r1771160 = r1771158 + r1771159;
        double r1771161 = r1771157 + r1771160;
        double r1771162 = r1771145 ? r1771153 : r1771161;
        return r1771162;
}

Error

Bits error versus x

Target

Original39.5
Target39.2
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -2.9436761867628915e-05

    1. Initial program 0.1

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

      \[\leadsto \frac{e^{x}}{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}\]
    4. Simplified0.1

      \[\leadsto \frac{e^{x}}{\frac{\color{blue}{-1 + e^{x} \cdot e^{x}}}{e^{x} + 1}}\]

    if -2.9436761867628915e-05 < x

    1. Initial program 60.4

      \[\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. Using strategy rm
    4. Applied insert-posit161.0

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

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

Reproduce

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

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

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