Average Error: 40.3 → 0.3
Time: 8.5s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.00023107496311143165:\\ \;\;\;\;\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.00023107496311143165:\\
\;\;\;\;\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 r1274717 = x;
        double r1274718 = exp(r1274717);
        double r1274719 = 1.0;
        double r1274720 = r1274718 - r1274719;
        double r1274721 = r1274720 / r1274717;
        return r1274721;
}

double f(double x) {
        double r1274722 = x;
        double r1274723 = -0.00023107496311143165;
        bool r1274724 = r1274722 <= r1274723;
        double r1274725 = exp(r1274722);
        double r1274726 = r1274725 / r1274722;
        double r1274727 = 1.0;
        double r1274728 = r1274727 / r1274722;
        double r1274729 = r1274726 - r1274728;
        double r1274730 = 0.5;
        double r1274731 = 0.16666666666666666;
        double r1274732 = r1274722 * r1274731;
        double r1274733 = r1274730 + r1274732;
        double r1274734 = r1274733 * r1274722;
        double r1274735 = r1274727 + r1274734;
        double r1274736 = r1274724 ? r1274729 : r1274735;
        return r1274736;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.3
Target39.5
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.00023107496311143165

    1. Initial program 0.0

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

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

    if -0.00023107496311143165 < x

    1. Initial program 60.3

      \[\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.00023107496311143165:\\ \;\;\;\;\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 2019156 
(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))