Average Error: 39.7 → 0.3
Time: 11.1s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.219218703283751786175040376924982865603 \cdot 10^{-4}:\\ \;\;\;\;\frac{e^{x}}{x} - \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.219218703283751786175040376924982865603 \cdot 10^{-4}:\\
\;\;\;\;\frac{e^{x}}{x} - \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 r96423 = x;
        double r96424 = exp(r96423);
        double r96425 = 1.0;
        double r96426 = r96424 - r96425;
        double r96427 = r96426 / r96423;
        return r96427;
}

double f(double x) {
        double r96428 = x;
        double r96429 = -0.00012192187032837518;
        bool r96430 = r96428 <= r96429;
        double r96431 = exp(r96428);
        double r96432 = r96431 / r96428;
        double r96433 = 1.0;
        double r96434 = r96433 / r96428;
        double r96435 = r96432 - r96434;
        double r96436 = 0.5;
        double r96437 = 0.16666666666666666;
        double r96438 = r96437 * r96428;
        double r96439 = r96436 + r96438;
        double r96440 = r96428 * r96439;
        double r96441 = 1.0;
        double r96442 = r96440 + r96441;
        double r96443 = r96430 ? r96435 : r96442;
        return r96443;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.7
Target40.1
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.00012192187032837518

    1. Initial program 0.0

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

Reproduce

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