Average Error: 41.6 → 0.0
Time: 6.1s
Precision: binary64
Cost: 6656
\[\frac{e^{x}}{e^{x} - 1} \]
\[\frac{-1}{\mathsf{expm1}\left(-x\right)} \]
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x) :precision binary64 (/ -1.0 (expm1 (- x))))
double code(double x) {
	return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
	return -1.0 / expm1(-x);
}
public static double code(double x) {
	return Math.exp(x) / (Math.exp(x) - 1.0);
}
public static double code(double x) {
	return -1.0 / Math.expm1(-x);
}
def code(x):
	return math.exp(x) / (math.exp(x) - 1.0)
def code(x):
	return -1.0 / math.expm1(-x)
function code(x)
	return Float64(exp(x) / Float64(exp(x) - 1.0))
end
function code(x)
	return Float64(-1.0 / expm1(Float64(-x)))
end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(-1.0 / N[(Exp[(-x)] - 1), $MachinePrecision]), $MachinePrecision]
\frac{e^{x}}{e^{x} - 1}
\frac{-1}{\mathsf{expm1}\left(-x\right)}

Error

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. Initial program 41.6

    \[\frac{e^{x}}{e^{x} - 1} \]
  2. Simplified0.4

    \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
    Proof
    (/.f64 (exp.f64 x) (expm1.f64 x)): 0 points increase in error, 0 points decrease in error
    (/.f64 (exp.f64 x) (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 x) 1))): 157 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.4

    \[\leadsto \color{blue}{{\left(\frac{\mathsf{expm1}\left(x\right)}{e^{x}}\right)}^{-1}} \]
  4. Taylor expanded in x around inf 41.6

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

    \[\leadsto {\color{blue}{\left(-\mathsf{expm1}\left(-x\right)\right)}}^{-1} \]
    Proof
    (neg.f64 (expm1.f64 (neg.f64 x))): 0 points increase in error, 0 points decrease in error
    (neg.f64 (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 (neg.f64 x)) 1))): 152 points increase in error, 6 points decrease in error
    (neg.f64 (-.f64 (Rewrite<= rec-exp_binary64 (/.f64 1 (exp.f64 x))) 1)): 3 points increase in error, 3 points decrease in error
    (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (/.f64 1 (exp.f64 x)) 1))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (/.f64 1 (exp.f64 x))) 1)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (/.f64 1 (exp.f64 x)))) 1): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 1 (neg.f64 (/.f64 1 (exp.f64 x))))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> unsub-neg_binary64 (-.f64 1 (/.f64 1 (exp.f64 x)))): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= *-inverses_binary64 (/.f64 (exp.f64 x) (exp.f64 x))) (/.f64 1 (exp.f64 x))): 2 points increase in error, 0 points decrease in error
    (Rewrite<= div-sub_binary64 (/.f64 (-.f64 (exp.f64 x) 1) (exp.f64 x))): 8 points increase in error, 3 points decrease in error
  6. Taylor expanded in x around inf 41.2

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

    \[\leadsto \color{blue}{\frac{-1}{\mathsf{expm1}\left(-x\right)}} \]
    Proof
    (/.f64 -1 (expm1.f64 (neg.f64 x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= metadata-eval (/.f64 1 -1)) (expm1.f64 (neg.f64 x))): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 1 -1) (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 (neg.f64 x)) 1))): 158 points increase in error, 0 points decrease in error
    (Rewrite<= associate-/r*_binary64 (/.f64 1 (*.f64 -1 (-.f64 (exp.f64 (neg.f64 x)) 1)))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (exp.f64 (neg.f64 x)) 1)))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (exp.f64 (neg.f64 x)) 1)))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (exp.f64 (neg.f64 x))) 1))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (exp.f64 (neg.f64 x)))) 1)): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (Rewrite<= +-commutative_binary64 (+.f64 1 (neg.f64 (exp.f64 (neg.f64 x)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (Rewrite<= sub-neg_binary64 (-.f64 1 (exp.f64 (neg.f64 x))))): 0 points increase in error, 0 points decrease in error
  8. Final simplification0.0

    \[\leadsto \frac{-1}{\mathsf{expm1}\left(-x\right)} \]

Alternatives

Alternative 1
Error1.1
Cost708
\[\begin{array}{l} \mathbf{if}\;x \leq -2059700.993233555:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \left(x \cdot 0.08333333333333333 + 0.5\right)\\ \end{array} \]
Alternative 2
Error0.9
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -10.621655339931833:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + 0.5\\ \end{array} \]
Alternative 3
Error2.4
Cost448
\[1 + \left(-1 + \frac{1}{x}\right) \]
Alternative 4
Error2.4
Cost448
\[-1 + \left(1 + \frac{1}{x}\right) \]
Alternative 5
Error41.8
Cost324
\[\begin{array}{l} \mathbf{if}\;x \leq -2059700.993233555:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.08333333333333333\\ \end{array} \]
Alternative 6
Error1.8
Cost324
\[\begin{array}{l} \mathbf{if}\;x \leq -2059700.993233555:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
Alternative 7
Error61.9
Cost64
\[0.5 \]
Alternative 8
Error42.2
Cost64
\[0 \]

Error

Reproduce

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

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

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