Average Error: 39.8 → 0.3
Time: 13.1s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.639055473548935301045942347641926062352 \cdot 10^{-4}:\\ \;\;\;\;\log \left(e^{e^{x} - 1}\right) \cdot \frac{1}{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.639055473548935301045942347641926062352 \cdot 10^{-4}:\\
\;\;\;\;\log \left(e^{e^{x} - 1}\right) \cdot \frac{1}{x}\\

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

\end{array}
double f(double x) {
        double r46533 = x;
        double r46534 = exp(r46533);
        double r46535 = 1.0;
        double r46536 = r46534 - r46535;
        double r46537 = r46536 / r46533;
        return r46537;
}

double f(double x) {
        double r46538 = x;
        double r46539 = -0.00016390554735489353;
        bool r46540 = r46538 <= r46539;
        double r46541 = exp(r46538);
        double r46542 = 1.0;
        double r46543 = r46541 - r46542;
        double r46544 = exp(r46543);
        double r46545 = log(r46544);
        double r46546 = 1.0;
        double r46547 = r46546 / r46538;
        double r46548 = r46545 * r46547;
        double r46549 = 0.5;
        double r46550 = 0.16666666666666666;
        double r46551 = r46550 * r46538;
        double r46552 = r46549 + r46551;
        double r46553 = r46538 * r46552;
        double r46554 = r46553 + r46546;
        double r46555 = r46540 ? r46548 : r46554;
        return r46555;
}

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.00016390554735489353

    1. Initial program 0.0

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

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

      \[\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.0

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

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

    if -0.00016390554735489353 < 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.639055473548935301045942347641926062352 \cdot 10^{-4}:\\ \;\;\;\;\log \left(e^{e^{x} - 1}\right) \cdot \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right) + 1\\ \end{array}\]

Reproduce

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