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

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

\end{array}
double f(double x) {
        double r57586 = x;
        double r57587 = exp(r57586);
        double r57588 = 1.0;
        double r57589 = r57587 - r57588;
        double r57590 = r57589 / r57586;
        return r57590;
}

double f(double x) {
        double r57591 = x;
        double r57592 = -0.00011835590321932839;
        bool r57593 = r57591 <= r57592;
        double r57594 = exp(r57591);
        double r57595 = 1.0;
        double r57596 = r57594 - r57595;
        double r57597 = exp(r57596);
        double r57598 = log(r57597);
        double r57599 = r57598 / r57591;
        double r57600 = 0.5;
        double r57601 = 0.16666666666666666;
        double r57602 = r57601 * r57591;
        double r57603 = r57600 + r57602;
        double r57604 = r57591 * r57603;
        double r57605 = 1.0;
        double r57606 = r57604 + r57605;
        double r57607 = r57593 ? r57599 : r57606;
        return r57607;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.6
Target40.0
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.00011835590321932839

    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}\]

    if -0.00011835590321932839 < x

    1. Initial program 60.1

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

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

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

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

Reproduce

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