Average Error: 39.7 → 0.1
Time: 2.1s
Precision: binary64
\[\frac{e^{x} - 1}{x} \]
\[\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{expm1}\left(x\right)}{x}\right)\right) \]
\frac{e^{x} - 1}{x}
\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{expm1}\left(x\right)}{x}\right)\right)
(FPCore (x) :precision binary64 (/ (- (exp x) 1.0) x))
(FPCore (x) :precision binary64 (log1p (expm1 (/ (expm1 x) x))))
double code(double x) {
	return (exp(x) - 1.0) / x;
}
double code(double x) {
	return log1p(expm1(expm1(x) / x));
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.7
Target40.2
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x < 1 \land x > -1:\\ \;\;\;\;\frac{e^{x} - 1}{\log \left(e^{x}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \end{array} \]

Derivation

  1. Initial program 39.7

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

    \[\leadsto \color{blue}{\frac{\mathsf{expm1}\left(x\right)}{x}} \]
  3. Applied log1p-expm1-u_binary640.1

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{expm1}\left(x\right)}{x}\right)\right)} \]
  4. Final simplification0.1

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

Reproduce

herbie shell --seed 2021357 
(FPCore (x)
  :name "Kahan's exp quotient"
  :precision binary64

  :herbie-target
  (if (and (< x 1.0) (> x -1.0)) (/ (- (exp x) 1.0) (log (exp x))) (/ (- (exp x) 1.0) x))

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