Average Error: 40.0 → 0.3
Time: 9.2s
Precision: 64
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.002149798604784803040396168327674786269199:\\ \;\;\;\;\frac{e^{x}}{x} - \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(\frac{1}{12} \cdot {x}^{2} + 1\right) - \frac{1}{2} \cdot x}\\ \end{array}\]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \le -0.002149798604784803040396168327674786269199:\\
\;\;\;\;\frac{e^{x}}{x} - \frac{1}{x}\\

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

\end{array}
double f(double x) {
        double r56573 = x;
        double r56574 = exp(r56573);
        double r56575 = 1.0;
        double r56576 = r56574 - r56575;
        double r56577 = r56576 / r56573;
        return r56577;
}

double f(double x) {
        double r56578 = x;
        double r56579 = -0.002149798604784803;
        bool r56580 = r56578 <= r56579;
        double r56581 = exp(r56578);
        double r56582 = r56581 / r56578;
        double r56583 = 1.0;
        double r56584 = r56583 / r56578;
        double r56585 = r56582 - r56584;
        double r56586 = 1.0;
        double r56587 = 0.08333333333333333;
        double r56588 = 2.0;
        double r56589 = pow(r56578, r56588);
        double r56590 = r56587 * r56589;
        double r56591 = r56590 + r56586;
        double r56592 = 0.5;
        double r56593 = r56592 * r56578;
        double r56594 = r56591 - r56593;
        double r56595 = r56586 / r56594;
        double r56596 = r56580 ? r56585 : r56595;
        return r56596;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.0
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.002149798604784803

    1. Initial program 0.0

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied div-sub0.0

      \[\leadsto \color{blue}{\frac{e^{x}}{x} - \frac{1}{x}}\]

    if -0.002149798604784803 < x

    1. Initial program 59.7

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

      \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot {x}^{2} + \left(\frac{1}{6} \cdot {x}^{3} + x\right)}}{x}\]
    3. Using strategy rm
    4. Applied clear-num0.6

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{\frac{1}{2} \cdot {x}^{2} + \left(\frac{1}{6} \cdot {x}^{3} + x\right)}}}\]
    5. Taylor expanded around 0 0.4

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

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

Reproduce

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