Average Error: 41.3 → 0.7
Time: 2.6s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 0.954500155621059:\\ \;\;\;\;\frac{1}{\log \left(\log \left(e^{\frac{e}{e^{\frac{1}{e^{x}}}}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(x \cdot 0.08333333333333333 + \frac{1}{x}\right)\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 0.954500155621059:\\
\;\;\;\;\frac{1}{\log \left(\log \left(e^{\frac{e}{e^{\frac{1}{e^{x}}}}}\right)\right)}\\

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

\end{array}
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
 :precision binary64
 (if (<= (exp x) 0.954500155621059)
   (/ 1.0 (log (log (exp (/ E (exp (/ 1.0 (exp x))))))))
   (+ 0.5 (+ (* x 0.08333333333333333) (/ 1.0 x)))))
double code(double x) {
	return (((double) exp(x)) / ((double) (((double) exp(x)) - 1.0)));
}
double code(double x) {
	double tmp;
	if ((((double) exp(x)) <= 0.954500155621059)) {
		tmp = (1.0 / ((double) log(((double) log(((double) exp((((double) M_E) / ((double) exp((1.0 / ((double) exp(x)))))))))))));
	} else {
		tmp = ((double) (0.5 + ((double) (((double) (x * 0.08333333333333333)) + (1.0 / x)))));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original41.3
Target41.0
Herbie0.7
\[\frac{1}{1 - e^{-x}}\]

Derivation

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

    1. Initial program 0.0

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

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

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

      \[\leadsto \frac{1}{1 - \color{blue}{\log \left(e^{\frac{1}{e^{x}}}\right)}}\]
    7. Applied add-log-exp_binary640.4

      \[\leadsto \frac{1}{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\frac{1}{e^{x}}}\right)}\]
    8. Applied diff-log_binary640.5

      \[\leadsto \frac{1}{\color{blue}{\log \left(\frac{e^{1}}{e^{\frac{1}{e^{x}}}}\right)}}\]
    9. Simplified0.5

      \[\leadsto \frac{1}{\log \color{blue}{\left(\frac{e}{e^{\frac{1}{e^{x}}}}\right)}}\]
    10. Using strategy rm
    11. Applied add-log-exp_binary640.5

      \[\leadsto \frac{1}{\log \color{blue}{\left(\log \left(e^{\frac{e}{e^{\frac{1}{e^{x}}}}}\right)\right)}}\]

    if 0.95450015562105905 < (exp.f64 x)

    1. Initial program 61.8

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

      \[\leadsto \color{blue}{0.5 + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)}\]
    3. Simplified0.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{x} \leq 0.954500155621059:\\ \;\;\;\;\frac{1}{\log \left(\log \left(e^{\frac{e}{e^{\frac{1}{e^{x}}}}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(x \cdot 0.08333333333333333 + \frac{1}{x}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020210 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

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

  (/ (exp x) (- (exp x) 1.0)))