Average Error: 39.8 → 0.3
Time: 4.7s
Precision: binary64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.01890841024590273:\\ \;\;\;\;\frac{1}{\frac{x}{e^{x} - 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(1 + 0.08333333333333333 \cdot {x}^{2}\right) - \left(0.001388888888888889 \cdot {x}^{4} + x \cdot 0.5\right)}\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.01890841024590273:\\
\;\;\;\;\frac{1}{\frac{x}{e^{x} - 1}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(1 + 0.08333333333333333 \cdot {x}^{2}\right) - \left(0.001388888888888889 \cdot {x}^{4} + x \cdot 0.5\right)}\\

\end{array}
(FPCore (x) :precision binary64 (/ (- (exp x) 1.0) x))
(FPCore (x)
 :precision binary64
 (if (<= x -0.01890841024590273)
   (/ 1.0 (/ x (- (exp x) 1.0)))
   (/
    1.0
    (-
     (+ 1.0 (* 0.08333333333333333 (pow x 2.0)))
     (+ (* 0.001388888888888889 (pow x 4.0)) (* x 0.5))))))
double code(double x) {
	return (exp(x) - 1.0) / x;
}
double code(double x) {
	double tmp;
	if (x <= -0.01890841024590273) {
		tmp = 1.0 / (x / (exp(x) - 1.0));
	} else {
		tmp = 1.0 / ((1.0 + (0.08333333333333333 * pow(x, 2.0))) - ((0.001388888888888889 * pow(x, 4.0)) + (x * 0.5)));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.8
Target40.2
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 < -0.0189084102459027

    1. Initial program 0.0

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied clear-num_binary64_14410.0

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{e^{x} - 1}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity_binary64_14420.0

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \frac{x}{e^{x} - 1}}}\]
    6. Applied associate-/r*_binary64_13860.0

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

    if -0.0189084102459027 < x

    1. Initial program 60.0

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied clear-num_binary64_144160.0

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{e^{x} - 1}}}\]
    4. Taylor expanded around 0 0.4

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

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

Reproduce

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