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

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

\end{array}
double f(double x) {
        double r4584143 = x;
        double r4584144 = exp(r4584143);
        double r4584145 = 1.0;
        double r4584146 = r4584144 - r4584145;
        double r4584147 = r4584146 / r4584143;
        return r4584147;
}

double f(double x) {
        double r4584148 = x;
        double r4584149 = -0.0002116977350152651;
        bool r4584150 = r4584148 <= r4584149;
        double r4584151 = exp(r4584148);
        double r4584152 = r4584151 / r4584148;
        double r4584153 = 1.0;
        double r4584154 = r4584153 / r4584148;
        double r4584155 = r4584152 - r4584154;
        double r4584156 = 0.5;
        double r4584157 = 0.16666666666666666;
        double r4584158 = r4584148 * r4584157;
        double r4584159 = r4584156 + r4584158;
        double r4584160 = r4584159 * r4584148;
        double r4584161 = r4584153 + r4584160;
        double r4584162 = r4584150 ? r4584155 : r4584161;
        return r4584162;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

    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.0002116977350152651 < x

    1. Initial program 60.1

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

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

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

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

Reproduce

herbie shell --seed 2019144 
(FPCore (x)
  :name "Kahan's exp quotient"

  :herbie-target
  (if (and (< x 1) (> x -1)) (/ (- (exp x) 1) (log (exp x))) (/ (- (exp x) 1) x))

  (/ (- (exp x) 1) x))