Average Error: 39.7 → 0.6
Time: 2.6s
Precision: binary64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{e^{x} - 1}{x} \leq 0:\\ \;\;\;\;\frac{x}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x}{e^{x}}} - \frac{1}{x}\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;\frac{e^{x} - 1}{x} \leq 0:\\
\;\;\;\;\frac{x}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{e^{x}}} - \frac{1}{x}\\

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.7
Target40.1
Herbie0.6
\[\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. Split input into 2 regimes
  2. if (/.f64 (-.f64 (exp.f64 x) 1) x) < 0.0

    1. Initial program 62.0

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

      \[\leadsto \frac{\color{blue}{x}}{x}\]

    if 0.0 < (/.f64 (-.f64 (exp.f64 x) 1) x)

    1. Initial program 2.2

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

      \[\leadsto \color{blue}{\frac{e^{x}}{x} - \frac{1}{x}}\]
    4. Using strategy rm
    5. Applied clear-num_binary64_17821.6

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{e^{x}}}} - \frac{1}{x}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{x} - 1}{x} \leq 0:\\ \;\;\;\;\frac{x}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x}{e^{x}}} - \frac{1}{x}\\ \end{array}\]

Reproduce

herbie shell --seed 2021012 
(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))