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

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

\end{array}
double f(double x) {
        double r5749428 = x;
        double r5749429 = exp(r5749428);
        double r5749430 = 1.0;
        double r5749431 = r5749429 - r5749430;
        double r5749432 = r5749431 / r5749428;
        return r5749432;
}

double f(double x) {
        double r5749433 = x;
        double r5749434 = -0.00017458508862795038;
        bool r5749435 = r5749433 <= r5749434;
        double r5749436 = exp(r5749433);
        double r5749437 = 1.0;
        double r5749438 = r5749436 - r5749437;
        double r5749439 = r5749438 / r5749433;
        double r5749440 = 0.16666666666666666;
        double r5749441 = r5749440 * r5749433;
        double r5749442 = 0.5;
        double r5749443 = r5749441 + r5749442;
        double r5749444 = r5749433 * r5749443;
        double r5749445 = r5749437 + r5749444;
        double r5749446 = r5749435 ? r5749439 : r5749445;
        return r5749446;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.0
Target39.2
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.00017458508862795038

    1. Initial program 0.0

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

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

    if -0.00017458508862795038 < x

    1. Initial program 60.1

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

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

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

Reproduce

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