Average Error: 39.8 → 0.3
Time: 2.2s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.2533085297236449 \cdot 10^{-4}:\\ \;\;\;\;\frac{\log \left(e^{\frac{e^{x} - 1}{2}}\right) + \log \left(e^{\frac{e^{x} - 1}{2}}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{6} \cdot {x}^{2} + \left(\frac{1}{2} \cdot x + 1\right)\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \le -2.2533085297236449 \cdot 10^{-4}:\\
\;\;\;\;\frac{\log \left(e^{\frac{e^{x} - 1}{2}}\right) + \log \left(e^{\frac{e^{x} - 1}{2}}\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{6} \cdot {x}^{2} + \left(\frac{1}{2} \cdot x + 1\right)\\

\end{array}
double f(double x) {
        double r106382 = x;
        double r106383 = exp(r106382);
        double r106384 = 1.0;
        double r106385 = r106383 - r106384;
        double r106386 = r106385 / r106382;
        return r106386;
}

double f(double x) {
        double r106387 = x;
        double r106388 = -0.0002253308529723645;
        bool r106389 = r106387 <= r106388;
        double r106390 = exp(r106387);
        double r106391 = 1.0;
        double r106392 = r106390 - r106391;
        double r106393 = 2.0;
        double r106394 = r106392 / r106393;
        double r106395 = exp(r106394);
        double r106396 = log(r106395);
        double r106397 = r106396 + r106396;
        double r106398 = r106397 / r106387;
        double r106399 = 0.16666666666666666;
        double r106400 = pow(r106387, r106393);
        double r106401 = r106399 * r106400;
        double r106402 = 0.5;
        double r106403 = r106402 * r106387;
        double r106404 = 1.0;
        double r106405 = r106403 + r106404;
        double r106406 = r106401 + r106405;
        double r106407 = r106389 ? r106398 : r106406;
        return r106407;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.8
Target40.3
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x \lt 1 \land x \gt -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.0002253308529723645

    1. Initial program 0.1

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

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

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

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

      \[\leadsto \frac{\log \color{blue}{\left(e^{e^{x} - 1}\right)}}{x}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.1

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

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

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

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

    if -0.0002253308529723645 < x

    1. Initial program 60.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.2533085297236449 \cdot 10^{-4}:\\ \;\;\;\;\frac{\log \left(e^{\frac{e^{x} - 1}{2}}\right) + \log \left(e^{\frac{e^{x} - 1}{2}}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{6} \cdot {x}^{2} + \left(\frac{1}{2} \cdot x + 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020062 
(FPCore (x)
  :name "Kahan's exp quotient"
  :precision binary64

  :herbie-target
  (if (and (< x 1) (> x -1)) (/ (- (exp x) 1) (log (exp x))) (/ (- (exp x) 1) x))

  (/ (- (exp x) 1) x))