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

\mathbf{elif}\;\frac{e^{x} - 1}{x} \leq 0.9991313213421796:\\
\;\;\;\;\frac{1}{\frac{x}{e^{x} - 1}}\\

\mathbf{elif}\;\frac{e^{x} - 1}{x} \leq 1.1353713195078663:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(e^{x} - 1\right) + \log 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)
   (+ 1.0 (* x (+ 0.5 (* x 0.16666666666666666))))
   (if (<= (/ (- (exp x) 1.0) x) 0.9991313213421796)
     (/ 1.0 (/ x (- (exp x) 1.0)))
     (if (<= (/ (- (exp x) 1.0) x) 1.1353713195078663)
       (+ 1.0 (* x (+ 0.5 (* x 0.16666666666666666))))
       (/ (+ (- (exp x) 1.0) (log 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 = 1.0 + (x * (0.5 + (x * 0.16666666666666666)));
	} else if (((exp(x) - 1.0) / x) <= 0.9991313213421796) {
		tmp = 1.0 / (x / (exp(x) - 1.0));
	} else if (((exp(x) - 1.0) / x) <= 1.1353713195078663) {
		tmp = 1.0 + (x * (0.5 + (x * 0.16666666666666666)));
	} else {
		tmp = ((exp(x) - 1.0) + log(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

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 3 regimes
  2. if (/.f64 (-.f64 (exp.f64 x) 1) x) < -0.0 or 0.999131321342179635 < (/.f64 (-.f64 (exp.f64 x) 1) x) < 1.13537131950786629

    1. Initial program 60.4

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

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

      \[\leadsto \color{blue}{1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)}\]

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

    1. Initial program 0.4

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

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

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

    1. Initial program 3.5

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied add-log-exp_binary64_28453.5

      \[\leadsto \frac{e^{x} - \color{blue}{\log \left(e^{1}\right)}}{x}\]
    4. Applied add-log-exp_binary64_284536.8

      \[\leadsto \frac{\color{blue}{\log \left(e^{e^{x}}\right)} - \log \left(e^{1}\right)}{x}\]
    5. Applied diff-log_binary64_289836.8

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{e^{x}}}{e^{1}}\right)}}{x}\]
    6. Simplified36.4

      \[\leadsto \frac{\log \color{blue}{\left(e^{e^{x} - 1}\right)}}{x}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity_binary64_280636.4

      \[\leadsto \frac{\log \color{blue}{\left(1 \cdot e^{e^{x} - 1}\right)}}{x}\]
    9. Applied log-prod_binary64_289236.4

      \[\leadsto \frac{\color{blue}{\log 1 + \log \left(e^{e^{x} - 1}\right)}}{x}\]
    10. Simplified3.5

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

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

Reproduce

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