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

\mathbf{else}:\\
\;\;\;\;\frac{e^{x}}{x} - \frac{1}{x}\\

\end{array}
double f(double x) {
        double r5102882 = x;
        double r5102883 = exp(r5102882);
        double r5102884 = 1.0;
        double r5102885 = r5102883 - r5102884;
        double r5102886 = r5102885 / r5102882;
        return r5102886;
}

double f(double x) {
        double r5102887 = x;
        double r5102888 = exp(r5102887);
        double r5102889 = 1.0;
        double r5102890 = r5102888 - r5102889;
        double r5102891 = r5102890 / r5102887;
        double r5102892 = 0.0;
        bool r5102893 = r5102891 <= r5102892;
        double r5102894 = 1.0;
        double r5102895 = 0.16666666666666666;
        double r5102896 = r5102895 * r5102887;
        double r5102897 = 0.5;
        double r5102898 = r5102896 + r5102897;
        double r5102899 = r5102887 * r5102898;
        double r5102900 = r5102894 + r5102899;
        double r5102901 = r5102888 / r5102887;
        double r5102902 = r5102889 / r5102887;
        double r5102903 = r5102901 - r5102902;
        double r5102904 = r5102893 ? r5102900 : r5102903;
        return r5102904;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.8
Target40.0
Herbie0.6
\[\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 (/ (- (exp x) 1.0) x) < 0.0

    1. Initial program 62.0

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

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

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{6} \cdot x + \frac{1}{2}\right) + 1}\]

    if 0.0 < (/ (- (exp x) 1.0) x)

    1. Initial program 2.7

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

      \[\leadsto \color{blue}{\frac{e^{x}}{x} - \frac{1}{x}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

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

Reproduce

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

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

  (/ (- (exp x) 1.0) x))