Average Error: 39.7 → 0.3
Time: 12.5s
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 r57553 = x;
        double r57554 = exp(r57553);
        double r57555 = 1.0;
        double r57556 = r57554 - r57555;
        double r57557 = r57556 / r57553;
        return r57557;
}

double f(double x) {
        double r57558 = x;
        double r57559 = -0.00012192187032837518;
        bool r57560 = r57558 <= r57559;
        double r57561 = exp(r57558);
        double r57562 = r57561 / r57558;
        double r57563 = 1.0;
        double r57564 = r57563 / r57558;
        double r57565 = r57562 - r57564;
        double r57566 = 0.5;
        double r57567 = 0.16666666666666666;
        double r57568 = r57567 * r57558;
        double r57569 = r57566 + r57568;
        double r57570 = r57558 * r57569;
        double r57571 = 1.0;
        double r57572 = r57570 + r57571;
        double r57573 = r57560 ? r57565 : r57572;
        return r57573;
}

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))