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

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

\end{array}
double f(double x) {
        double r3260426 = x;
        double r3260427 = exp(r3260426);
        double r3260428 = 1.0;
        double r3260429 = r3260427 - r3260428;
        double r3260430 = r3260429 / r3260426;
        return r3260430;
}

double f(double x) {
        double r3260431 = x;
        double r3260432 = -0.00018203218551224193;
        bool r3260433 = r3260431 <= r3260432;
        double r3260434 = exp(r3260431);
        double r3260435 = 1.0;
        double r3260436 = r3260434 - r3260435;
        double r3260437 = r3260435 / r3260431;
        double r3260438 = r3260436 * r3260437;
        double r3260439 = 0.5;
        double r3260440 = 0.16666666666666666;
        double r3260441 = r3260431 * r3260440;
        double r3260442 = r3260439 + r3260441;
        double r3260443 = r3260442 * r3260431;
        double r3260444 = r3260443 + r3260435;
        double r3260445 = r3260433 ? r3260438 : r3260444;
        return r3260445;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.7
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.00018203218551224193

    1. Initial program 0.1

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

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

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

Reproduce

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