Average Error: 40.1 → 0.3
Time: 25.8s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.00011222905447604574:\\ \;\;\;\;\frac{\log \left(e^{e^{\left(x + x\right) + x} + -1}\right)}{x \cdot \left(e^{x} \cdot e^{x} + \left(1 + e^{x}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{1}{6} + \frac{1}{2}\right) + 1\\ \end{array}\]
double f(double x) {
        double r7968394 = x;
        double r7968395 = exp(r7968394);
        double r7968396 = 1.0;
        double r7968397 = r7968395 - r7968396;
        double r7968398 = r7968397 / r7968394;
        return r7968398;
}

double f(double x) {
        double r7968399 = x;
        double r7968400 = -0.00011222905447604574;
        bool r7968401 = r7968399 <= r7968400;
        double r7968402 = r7968399 + r7968399;
        double r7968403 = r7968402 + r7968399;
        double r7968404 = exp(r7968403);
        double r7968405 = -1.0;
        double r7968406 = r7968404 + r7968405;
        double r7968407 = exp(r7968406);
        double r7968408 = log(r7968407);
        double r7968409 = exp(r7968399);
        double r7968410 = r7968409 * r7968409;
        double r7968411 = 1.0;
        double r7968412 = r7968411 + r7968409;
        double r7968413 = r7968410 + r7968412;
        double r7968414 = r7968399 * r7968413;
        double r7968415 = r7968408 / r7968414;
        double r7968416 = 0.16666666666666666;
        double r7968417 = r7968399 * r7968416;
        double r7968418 = 0.5;
        double r7968419 = r7968417 + r7968418;
        double r7968420 = r7968399 * r7968419;
        double r7968421 = r7968420 + r7968411;
        double r7968422 = r7968401 ? r7968415 : r7968421;
        return r7968422;
}

\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \le -0.00011222905447604574:\\
\;\;\;\;\frac{\log \left(e^{e^{\left(x + x\right) + x} + -1}\right)}{x \cdot \left(e^{x} \cdot e^{x} + \left(1 + e^{x}\right)\right)}\\

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

\end{array}

Error

Bits error versus x

Target

Original40.1
Target39.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.00011222905447604574

    1. Initial program 0.1

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

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

      \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{x \cdot \left(e^{x} \cdot e^{x} + \left(1 \cdot 1 + e^{x} \cdot 1\right)\right)}}\]
    5. Simplified0.0

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

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

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

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

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

    if -0.00011222905447604574 < 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}{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.00011222905447604574:\\ \;\;\;\;\frac{\log \left(e^{e^{\left(x + x\right) + x} + -1}\right)}{x \cdot \left(e^{x} \cdot e^{x} + \left(1 + e^{x}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot \frac{1}{6} + \frac{1}{2}\right) + 1\\ \end{array}\]

Reproduce

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