Average Error: 41.3 → 1.0
Time: 20.4s
Precision: 64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \le 0.0:\\ \;\;\;\;\frac{\frac{1}{\sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}} \cdot \sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}}} \cdot \frac{1}{\sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}}}}{1 - \frac{\sqrt{1}}{\sqrt{e^{x}}}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.0:\\
\;\;\;\;\frac{\frac{1}{\sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}} \cdot \sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}}} \cdot \frac{1}{\sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}}}}{1 - \frac{\sqrt{1}}{\sqrt{e^{x}}}}\\

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

\end{array}
double f(double x) {
        double r67078 = x;
        double r67079 = exp(r67078);
        double r67080 = 1.0;
        double r67081 = r67079 - r67080;
        double r67082 = r67079 / r67081;
        return r67082;
}

double f(double x) {
        double r67083 = x;
        double r67084 = exp(r67083);
        double r67085 = 0.0;
        bool r67086 = r67084 <= r67085;
        double r67087 = 1.0;
        double r67088 = 1.0;
        double r67089 = sqrt(r67088);
        double r67090 = sqrt(r67084);
        double r67091 = r67089 / r67090;
        double r67092 = r67087 + r67091;
        double r67093 = cbrt(r67092);
        double r67094 = r67093 * r67093;
        double r67095 = r67087 / r67094;
        double r67096 = r67087 / r67093;
        double r67097 = r67095 * r67096;
        double r67098 = r67087 - r67091;
        double r67099 = r67097 / r67098;
        double r67100 = 0.08333333333333333;
        double r67101 = r67087 / r67083;
        double r67102 = fma(r67100, r67083, r67101);
        double r67103 = 0.5;
        double r67104 = r67102 + r67103;
        double r67105 = r67086 ? r67099 : r67104;
        return r67105;
}

Error

Bits error versus x

Target

Original41.3
Target40.8
Herbie1.0
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0

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

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

      \[\leadsto \frac{1}{\color{blue}{1 - \frac{1}{e^{x}}}}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt0

      \[\leadsto \frac{1}{1 - \frac{1}{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}}}}\]
    7. Applied add-sqr-sqrt0

      \[\leadsto \frac{1}{1 - \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}}}\]
    8. Applied times-frac0

      \[\leadsto \frac{1}{1 - \color{blue}{\frac{\sqrt{1}}{\sqrt{e^{x}}} \cdot \frac{\sqrt{1}}{\sqrt{e^{x}}}}}\]
    9. Applied add-sqr-sqrt0

      \[\leadsto \frac{1}{\color{blue}{\sqrt{1} \cdot \sqrt{1}} - \frac{\sqrt{1}}{\sqrt{e^{x}}} \cdot \frac{\sqrt{1}}{\sqrt{e^{x}}}}\]
    10. Applied difference-of-squares0

      \[\leadsto \frac{1}{\color{blue}{\left(\sqrt{1} + \frac{\sqrt{1}}{\sqrt{e^{x}}}\right) \cdot \left(\sqrt{1} - \frac{\sqrt{1}}{\sqrt{e^{x}}}\right)}}\]
    11. Applied associate-/r*0

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

      \[\leadsto \frac{\color{blue}{\frac{1}{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}}}}{\sqrt{1} - \frac{\sqrt{1}}{\sqrt{e^{x}}}}\]
    13. Using strategy rm
    14. Applied add-cube-cbrt0

      \[\leadsto \frac{\frac{1}{\color{blue}{\left(\sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}} \cdot \sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}}\right) \cdot \sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}}}}}{\sqrt{1} - \frac{\sqrt{1}}{\sqrt{e^{x}}}}\]
    15. Applied add-cube-cbrt0

      \[\leadsto \frac{\frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\left(\sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}} \cdot \sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}}\right) \cdot \sqrt[3]{1 + \frac{\sqrt{1}}{\sqrt{e^{x}}}}}}{\sqrt{1} - \frac{\sqrt{1}}{\sqrt{e^{x}}}}\]
    16. Applied times-frac0

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

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

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

    if 0.0 < (exp x)

    1. Initial program 61.1

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

      \[\leadsto \color{blue}{\frac{1}{2} + \left(\frac{1}{12} \cdot x + \frac{1}{x}\right)}\]
    3. Simplified1.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.0

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

Reproduce

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

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

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