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

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

\end{array}
double f(double x) {
        double r2018756 = x;
        double r2018757 = exp(r2018756);
        double r2018758 = 1.0;
        double r2018759 = r2018757 - r2018758;
        double r2018760 = r2018759 / r2018756;
        return r2018760;
}

double f(double x) {
        double r2018761 = x;
        double r2018762 = -0.0001490270566187492;
        bool r2018763 = r2018761 <= r2018762;
        double r2018764 = exp(r2018761);
        double r2018765 = 1.0;
        double r2018766 = r2018764 - r2018765;
        double r2018767 = r2018766 / r2018761;
        double r2018768 = 0.16666666666666666;
        double r2018769 = r2018761 * r2018768;
        double r2018770 = 0.5;
        double r2018771 = r2018769 + r2018770;
        double r2018772 = r2018761 * r2018771;
        double r2018773 = r2018765 + r2018772;
        double r2018774 = r2018763 ? r2018767 : r2018773;
        return r2018774;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.9
Target38.1
Herbie0.4
\[\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.0001490270566187492

    1. Initial program 0.1

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

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

    if -0.0001490270566187492 < x

    1. Initial program 60.0

      \[\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}{2} + \frac{1}{6} \cdot x\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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