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

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

\end{array}
double f(double x) {
        double r90645 = x;
        double r90646 = exp(r90645);
        double r90647 = 1.0;
        double r90648 = r90646 - r90647;
        double r90649 = r90648 / r90645;
        return r90649;
}

double f(double x) {
        double r90650 = x;
        double r90651 = -0.00019799929629834328;
        bool r90652 = r90650 <= r90651;
        double r90653 = exp(r90650);
        double r90654 = 1.0;
        double r90655 = r90653 - r90654;
        double r90656 = exp(r90655);
        double r90657 = log(r90656);
        double r90658 = r90657 / r90650;
        double r90659 = 0.16666666666666666;
        double r90660 = 2.0;
        double r90661 = pow(r90650, r90660);
        double r90662 = r90659 * r90661;
        double r90663 = 0.5;
        double r90664 = r90663 * r90650;
        double r90665 = 1.0;
        double r90666 = r90664 + r90665;
        double r90667 = r90662 + r90666;
        double r90668 = r90652 ? r90658 : r90667;
        return r90668;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.9
Target39.3
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.00019799929629834328

    1. Initial program 0.1

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

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

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

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

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

    if -0.00019799929629834328 < x

    1. Initial program 60.0

      \[\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}\]
    4. Taylor expanded around 0 0.4

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

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

Reproduce

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