Average Error: 39.8 → 0.3
Time: 2.2s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.2533085297236449 \cdot 10^{-4}:\\ \;\;\;\;\frac{\log \left(e^{\frac{e^{x} - 1}{2}}\right) + \log \left(e^{\frac{e^{x} - 1}{2}}\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 -2.2533085297236449 \cdot 10^{-4}:\\
\;\;\;\;\frac{\log \left(e^{\frac{e^{x} - 1}{2}}\right) + \log \left(e^{\frac{e^{x} - 1}{2}}\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 r83569 = x;
        double r83570 = exp(r83569);
        double r83571 = 1.0;
        double r83572 = r83570 - r83571;
        double r83573 = r83572 / r83569;
        return r83573;
}

double f(double x) {
        double r83574 = x;
        double r83575 = -0.0002253308529723645;
        bool r83576 = r83574 <= r83575;
        double r83577 = exp(r83574);
        double r83578 = 1.0;
        double r83579 = r83577 - r83578;
        double r83580 = 2.0;
        double r83581 = r83579 / r83580;
        double r83582 = exp(r83581);
        double r83583 = log(r83582);
        double r83584 = r83583 + r83583;
        double r83585 = r83584 / r83574;
        double r83586 = 0.16666666666666666;
        double r83587 = pow(r83574, r83580);
        double r83588 = r83586 * r83587;
        double r83589 = 0.5;
        double r83590 = r83589 * r83574;
        double r83591 = 1.0;
        double r83592 = r83590 + r83591;
        double r83593 = r83588 + r83592;
        double r83594 = r83576 ? r83585 : r83593;
        return r83594;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

    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}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.1

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

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

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

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

    if -0.0002253308529723645 < x

    1. Initial program 60.2

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

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

Reproduce

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