Average Error: 39.8 → 0.3
Time: 13.5s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.00017793669281872875:\\ \;\;\;\;\frac{e^{x} + -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.00017793669281872875:\\
\;\;\;\;\frac{e^{x} + -1}{x}\\

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

\end{array}
double f(double x) {
        double r12823320 = x;
        double r12823321 = exp(r12823320);
        double r12823322 = 1.0;
        double r12823323 = r12823321 - r12823322;
        double r12823324 = r12823323 / r12823320;
        return r12823324;
}

double f(double x) {
        double r12823325 = x;
        double r12823326 = -0.00017793669281872875;
        bool r12823327 = r12823325 <= r12823326;
        double r12823328 = exp(r12823325);
        double r12823329 = -1.0;
        double r12823330 = r12823328 + r12823329;
        double r12823331 = r12823330 / r12823325;
        double r12823332 = 1.0;
        double r12823333 = 0.5;
        double r12823334 = 0.16666666666666666;
        double r12823335 = r12823325 * r12823334;
        double r12823336 = r12823333 + r12823335;
        double r12823337 = r12823336 * r12823325;
        double r12823338 = r12823332 + r12823337;
        double r12823339 = r12823327 ? r12823331 : r12823338;
        return r12823339;
}

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.00017793669281872875

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{-1 \cdot \frac{1 - e^{x}}{x}}\]
    3. Simplified0.1

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

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

Reproduce

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