Average Error: 39.5 → 0.7
Time: 13.4s
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 r1674180 = x;
        double r1674181 = exp(r1674180);
        double r1674182 = 1.0;
        double r1674183 = r1674181 - r1674182;
        double r1674184 = r1674181 / r1674183;
        return r1674184;
}

double f(double x) {
        double r1674185 = x;
        double r1674186 = -2.9436761867628915e-05;
        bool r1674187 = r1674185 <= r1674186;
        double r1674188 = exp(r1674185);
        double r1674189 = r1674188 * r1674188;
        double r1674190 = -1.0;
        double r1674191 = r1674189 + r1674190;
        double r1674192 = 1.0;
        double r1674193 = r1674188 + r1674192;
        double r1674194 = r1674191 / r1674193;
        double r1674195 = r1674188 / r1674194;
        double r1674196 = 0.08333333333333333;
        double r1674197 = r1674196 * r1674185;
        double r1674198 = /* ERROR: no posit support in C */;
        double r1674199 = /* ERROR: no posit support in C */;
        double r1674200 = r1674192 / r1674185;
        double r1674201 = 0.5;
        double r1674202 = r1674200 + r1674201;
        double r1674203 = r1674199 + r1674202;
        double r1674204 = r1674187 ? r1674195 : r1674203;
        return r1674204;
}

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