Average Error: 41.6 → 0.0
Time: 2.1s
Precision: binary64
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.002362592664977423:\\ \;\;\;\;\frac{1}{1 - e^{-x}}\\ \mathbf{elif}\;x \leq 0.0021021084497481325:\\ \;\;\;\;x \cdot 0.08333333333333333 + \left(0.5 + \frac{1}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\log \left(e^{1 - e^{-x}}\right)}\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -0.002362592664977423:\\
\;\;\;\;\frac{1}{1 - e^{-x}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\log \left(e^{1 - e^{-x}}\right)}\\

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -0.0023625926649774231

    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 - e^{-x}}}\]

    if -0.0023625926649774231 < x < 0.0021021084497481325

    1. Initial program 62.5

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

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

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

    if 0.0021021084497481325 < x

    1. Initial program 33.0

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

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

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

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

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

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

      \[\leadsto \frac{1}{\log \color{blue}{\left(e^{1 - e^{-x}}\right)}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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

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

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