Average Error: 41.0 → 0.8
Time: 3.4s
Precision: binary64
Cost: 897
\[\frac{e^{x}}{e^{x} - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -355.9775248099111:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + \frac{1}{x}\right) + x \cdot 0.08333333333333333\\ \end{array}\]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -355.9775248099111:\\
\;\;\;\;0\\

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

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Alternatives

Alternative 1
Error1.0
Cost7232
\[\frac{e^{x}}{x + x \cdot \left(x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)}\]
Alternative 2
Error1.2
Cost6976
\[\frac{e^{x}}{x + 0.5 \cdot \left(x \cdot x\right)}\]
Alternative 3
Error1.6
Cost6592
\[\frac{e^{x}}{x}\]
Alternative 4
Error1.1
Cost641
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9853155584823636:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5 + \frac{1}{x}\\ \end{array}\]
Alternative 5
Error1.6
Cost513
\[\begin{array}{l} \mathbf{if}\;x \leq -355.9775248099111:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array}\]
Alternative 6
Error41.8
Cost64
\[0\]
Alternative 7
Error61.5
Cost64
\[1\]

Error

Derivation

  1. Split input into 2 regimes
  2. if x < -355.97752480991107

    1. Initial program 0.1

      \[0\]

    if -355.97752480991107 < x

    1. Initial program 61.4

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

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

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

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

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

Reproduce

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

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

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