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

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

\end{array}
double f(double x) {
        double r46356 = x;
        double r46357 = exp(r46356);
        double r46358 = 1.0;
        double r46359 = r46357 - r46358;
        double r46360 = r46359 / r46356;
        return r46360;
}

double f(double x) {
        double r46361 = x;
        double r46362 = -0.00014841222714399082;
        bool r46363 = r46361 <= r46362;
        double r46364 = exp(r46361);
        double r46365 = 1.0;
        double r46366 = r46364 - r46365;
        double r46367 = exp(r46366);
        double r46368 = log(r46367);
        double r46369 = r46368 / r46361;
        double r46370 = 2.0;
        double r46371 = pow(r46361, r46370);
        double r46372 = 0.16666666666666666;
        double r46373 = r46361 * r46372;
        double r46374 = 0.5;
        double r46375 = r46373 + r46374;
        double r46376 = r46371 * r46375;
        double r46377 = r46376 + r46361;
        double r46378 = r46377 / r46361;
        double r46379 = r46363 ? r46369 : r46378;
        return r46379;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.8
Target40.2
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.00014841222714399082

    1. Initial program 0.0

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied add-log-exp0.0

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

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

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

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

    if -0.00014841222714399082 < x

    1. Initial program 60.2

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

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

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

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

Reproduce

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