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

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

\end{array}
double f(double x) {
        double r59494 = x;
        double r59495 = exp(r59494);
        double r59496 = 1.0;
        double r59497 = r59495 - r59496;
        double r59498 = r59497 / r59494;
        return r59498;
}

double f(double x) {
        double r59499 = x;
        double r59500 = -0.00019061484402488725;
        bool r59501 = r59499 <= r59500;
        double r59502 = exp(r59499);
        double r59503 = r59502 / r59499;
        double r59504 = 1.0;
        double r59505 = r59504 / r59499;
        double r59506 = r59503 - r59505;
        double r59507 = 1.0;
        double r59508 = 0.16666666666666666;
        double r59509 = r59499 * r59508;
        double r59510 = 0.5;
        double r59511 = r59509 + r59510;
        double r59512 = r59499 * r59511;
        double r59513 = exp(r59512);
        double r59514 = log(r59513);
        double r59515 = r59507 + r59514;
        double r59516 = r59501 ? r59506 : r59515;
        return r59516;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.4
Target39.8
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.00019061484402488725

    1. Initial program 0.1

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied div-sub0.1

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

    if -0.00019061484402488725 < x

    1. Initial program 60.0

      \[\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}{1 + x \cdot \left(x \cdot \frac{1}{6} + \frac{1}{2}\right)}\]
    4. Using strategy rm
    5. Applied add-log-exp0.4

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

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

Reproduce

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