Average Error: 41.4 → 0.9
Time: 5.6min
Precision: binary64
Cost: 33153
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 1.0000000004016756:\\ \;\;\;\;\log \left(e^{e^{x} \cdot \left(x \cdot 0.08333333333333333\right)}\right) + e^{x} \cdot \left(\frac{1}{x} - 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 1.0000000004016756:\\
\;\;\;\;\log \left(e^{e^{x} \cdot \left(x \cdot 0.08333333333333333\right)}\right) + e^{x} \cdot \left(\frac{1}{x} - 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;1\\

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Alternatives

Alternative 1
Error0.9
Cost26496
\[e^{x} \cdot \left(\frac{1}{x} - 0.5\right) + \sqrt[3]{{\left(e^{x} \cdot \left(x \cdot 0.08333333333333333\right)\right)}^{3}}\]
Alternative 2
Error0.9
Cost13632
\[e^{x} \cdot \left(x \cdot 0.08333333333333333\right) + e^{x} \cdot \left(\frac{1}{x} - 0.5\right)\]
Alternative 3
Error0.9
Cost7104
\[e^{x} \cdot \left(x \cdot 0.08333333333333333 + \left(\frac{1}{x} - 0.5\right)\right)\]
Alternative 4
Error0.8
Cost7105
\[\begin{array}{l} \mathbf{if}\;x \leq -7.720461622783971 \cdot 10^{-06}:\\ \;\;\;\;\frac{1}{1 - e^{-x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + 0.5\\ \end{array}\]
Alternative 5
Error1.6
Cost6592
\[\frac{e^{x}}{x}\]
Alternative 6
Error0.8
Cost897
\[\begin{array}{l} \mathbf{if}\;x \leq -354.81276147133286:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.08333333333333333 + \left(\frac{1}{x} + 0.5\right)\\ \end{array}\]
Alternative 7
Error1.1
Cost641
\[\begin{array}{l} \mathbf{if}\;x \leq -2.05985498186887:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + 0.5\\ \end{array}\]
Alternative 8
Error1.5
Cost513
\[\begin{array}{l} \mathbf{if}\;x \leq -354.81276147133286:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array}\]
Alternative 9
Error41.0
Cost385
\[\begin{array}{l} \mathbf{if}\;x \leq 5.758332088306613 \cdot 10^{-309}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 10
Error42.1
Cost64
\[0\]
Alternative 11
Error62.0
Cost64
\[-1\]

Error

Derivation

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

    1. Initial program 41.7

      \[\frac{e^{x}}{e^{x} - 1}\]
    2. Using strategy rm
    3. Applied div-inv_binary64_178041.7

      \[\leadsto \color{blue}{e^{x} \cdot \frac{1}{e^{x} - 1}}\]
    4. Taylor expanded around 0 0.2

      \[\leadsto e^{x} \cdot \color{blue}{\left(\left(0.08333333333333333 \cdot x + \frac{1}{x}\right) - 0.5\right)}\]
    5. Simplified0.2

      \[\leadsto e^{x} \cdot \color{blue}{\left(x \cdot 0.08333333333333333 + \left(\frac{1}{x} - 0.5\right)\right)}\]
    6. Using strategy rm
    7. Applied distribute-rgt-in_binary64_17330.2

      \[\leadsto \color{blue}{\left(x \cdot 0.08333333333333333\right) \cdot e^{x} + \left(\frac{1}{x} - 0.5\right) \cdot e^{x}}\]
    8. Using strategy rm
    9. Applied add-log-exp_binary64_18220.2

      \[\leadsto \color{blue}{\log \left(e^{\left(x \cdot 0.08333333333333333\right) \cdot e^{x}}\right)} + \left(\frac{1}{x} - 0.5\right) \cdot e^{x}\]
    10. Simplified0.2

      \[\leadsto \color{blue}{\log \left(e^{\left(x \cdot 0.08333333333333333\right) \cdot e^{x}}\right) + \left(\frac{1}{x} - 0.5\right) \cdot e^{x}}\]

    if 1.0000000004016756 < (exp.f64 x)

    1. Initial program 33.2

      \[1\]
    2. Simplified33.2

      \[\leadsto \color{blue}{1}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

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

Reproduce

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

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

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