Average Error: 39.9 → 0.3
Time: 9.9s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0001908225032694281:\\ \;\;\;\;\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.0001908225032694281:\\
\;\;\;\;\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 r6223795 = x;
        double r6223796 = exp(r6223795);
        double r6223797 = 1.0;
        double r6223798 = r6223796 - r6223797;
        double r6223799 = r6223798 / r6223795;
        return r6223799;
}

double f(double x) {
        double r6223800 = x;
        double r6223801 = -0.0001908225032694281;
        bool r6223802 = r6223800 <= r6223801;
        double r6223803 = exp(r6223800);
        double r6223804 = r6223803 / r6223800;
        double r6223805 = 1.0;
        double r6223806 = r6223805 / r6223800;
        double r6223807 = r6223804 - r6223806;
        double r6223808 = 0.5;
        double r6223809 = 0.16666666666666666;
        double r6223810 = r6223800 * r6223809;
        double r6223811 = r6223808 + r6223810;
        double r6223812 = r6223811 * r6223800;
        double r6223813 = r6223805 + r6223812;
        double r6223814 = r6223802 ? r6223807 : r6223813;
        return r6223814;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.9
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.0001908225032694281

    1. Initial program 0.0

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

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

    if -0.0001908225032694281 < x

    1. Initial program 60.0

      \[\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.0001908225032694281:\\ \;\;\;\;\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 2019104 
(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))