Average Error: 40.3 → 0.3
Time: 7.5s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.681655298641986193575875718764223165635 \cdot 10^{-4}:\\ \;\;\;\;\frac{\log \left(e^{{\left(e^{x}\right)}^{2} - 1 \cdot 1}\right)}{x \cdot \left(e^{x} + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right) + 1\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \le -1.681655298641986193575875718764223165635 \cdot 10^{-4}:\\
\;\;\;\;\frac{\log \left(e^{{\left(e^{x}\right)}^{2} - 1 \cdot 1}\right)}{x \cdot \left(e^{x} + 1\right)}\\

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

\end{array}
double f(double x) {
        double r232896 = x;
        double r232897 = exp(r232896);
        double r232898 = 1.0;
        double r232899 = r232897 - r232898;
        double r232900 = r232899 / r232896;
        return r232900;
}

double f(double x) {
        double r232901 = x;
        double r232902 = -0.00016816552986419862;
        bool r232903 = r232901 <= r232902;
        double r232904 = exp(r232901);
        double r232905 = 2.0;
        double r232906 = pow(r232904, r232905);
        double r232907 = 1.0;
        double r232908 = r232907 * r232907;
        double r232909 = r232906 - r232908;
        double r232910 = exp(r232909);
        double r232911 = log(r232910);
        double r232912 = r232904 + r232907;
        double r232913 = r232901 * r232912;
        double r232914 = r232911 / r232913;
        double r232915 = 0.5;
        double r232916 = 0.16666666666666666;
        double r232917 = r232916 * r232901;
        double r232918 = r232915 + r232917;
        double r232919 = r232901 * r232918;
        double r232920 = 1.0;
        double r232921 = r232919 + r232920;
        double r232922 = r232903 ? r232914 : r232921;
        return r232922;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.3
Target40.8
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.00016816552986419862

    1. Initial program 0.1

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

      \[\leadsto \frac{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}{x}\]
    4. Applied associate-/l/0.1

      \[\leadsto \color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{x \cdot \left(e^{x} + 1\right)}}\]
    5. Using strategy rm
    6. Applied add-log-exp0.1

      \[\leadsto \frac{e^{x} \cdot e^{x} - \color{blue}{\log \left(e^{1 \cdot 1}\right)}}{x \cdot \left(e^{x} + 1\right)}\]
    7. Applied add-log-exp0.1

      \[\leadsto \frac{\color{blue}{\log \left(e^{e^{x} \cdot e^{x}}\right)} - \log \left(e^{1 \cdot 1}\right)}{x \cdot \left(e^{x} + 1\right)}\]
    8. Applied diff-log0.1

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{e^{x} \cdot e^{x}}}{e^{1 \cdot 1}}\right)}}{x \cdot \left(e^{x} + 1\right)}\]
    9. Simplified0.1

      \[\leadsto \frac{\log \color{blue}{\left(e^{{\left(e^{x}\right)}^{2} - 1 \cdot 1}\right)}}{x \cdot \left(e^{x} + 1\right)}\]

    if -0.00016816552986419862 < x

    1. Initial program 60.3

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

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

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right) + 1}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

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

Reproduce

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

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

  (/ (- (exp x) 1) x))