Average Error: 39.7 → 0.4
Time: 8.6s
Precision: binary64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -6.4930921653586126 \cdot 10^{-06}:\\ \;\;\;\;\frac{\left(1 + \sqrt{e^{x}}\right) \cdot \left(\sqrt{e^{x}} - 1\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{x \cdot x}{2}}{x}\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \leq -6.4930921653586126 \cdot 10^{-06}:\\
\;\;\;\;\frac{\left(1 + \sqrt{e^{x}}\right) \cdot \left(\sqrt{e^{x}} - 1\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{x + \frac{x \cdot x}{2}}{x}\\

\end{array}
(FPCore (x) :precision binary64 (/ (- (exp x) 1.0) x))
(FPCore (x)
 :precision binary64
 (if (<= x -6.4930921653586126e-06)
   (/ (* (+ 1.0 (sqrt (exp x))) (- (sqrt (exp x)) 1.0)) x)
   (/ (+ x (/ (* x x) 2.0)) x)))
double code(double x) {
	return (exp(x) - 1.0) / x;
}
double code(double x) {
	double tmp;
	if (x <= -6.4930921653586126e-06) {
		tmp = ((1.0 + sqrt(exp(x))) * (sqrt(exp(x)) - 1.0)) / x;
	} else {
		tmp = (x + ((x * x) / 2.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.2
Herbie0.4
\[\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 < -6.4930921653586126e-6

    1. Initial program 0.1

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary640.1

      \[\leadsto \frac{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}} - 1}{x}\]
    4. Applied difference-of-sqr-1_binary640.1

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

      \[\leadsto \frac{\color{blue}{\left(1 + \sqrt{e^{x}}\right)} \cdot \left(\sqrt{e^{x}} - 1\right)}{x}\]

    if -6.4930921653586126e-6 < x

    1. Initial program 60.2

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

      \[\leadsto \frac{\color{blue}{x + \frac{x \cdot x}{2}}}{x}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6.4930921653586126 \cdot 10^{-06}:\\ \;\;\;\;\frac{\left(1 + \sqrt{e^{x}}\right) \cdot \left(\sqrt{e^{x}} - 1\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{x \cdot x}{2}}{x}\\ \end{array}\]

Reproduce

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