Average Error: 40.2 → 0.3
Time: 2.2s
Precision: binary64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.00017977753920878645:\\ \;\;\;\;\frac{e^{x}}{x} - \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.00017977753920878645:\\
\;\;\;\;\frac{e^{x}}{x} - \frac{1}{x}\\

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

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.2
Target40.6
Herbie0.3
\[\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 x < -1.7977753920878645e-4

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\frac{e^{x}}{x} - \frac{1}{x}}\]

    if -1.7977753920878645e-4 < x

    1. Initial program 60.1

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

      \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2} + \left(0.5 \cdot x + 1\right)}\]
    3. Simplified0.4

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

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

Reproduce

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