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

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

\end{array}
double f(double x) {
        double r46177 = x;
        double r46178 = exp(r46177);
        double r46179 = 1.0;
        double r46180 = r46178 - r46179;
        double r46181 = r46180 / r46177;
        return r46181;
}

double f(double x) {
        double r46182 = x;
        double r46183 = -0.0001767842498543489;
        bool r46184 = r46182 <= r46183;
        double r46185 = exp(r46182);
        double r46186 = 1.0;
        double r46187 = r46185 - r46186;
        double r46188 = r46187 / r46182;
        double r46189 = 2.0;
        double r46190 = pow(r46182, r46189);
        double r46191 = 0.5;
        double r46192 = 0.16666666666666666;
        double r46193 = r46182 * r46192;
        double r46194 = r46191 + r46193;
        double r46195 = r46190 * r46194;
        double r46196 = r46195 + r46182;
        double r46197 = r46196 / r46182;
        double r46198 = r46184 ? r46188 : r46197;
        return r46198;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

    1. Initial program 0.0

      \[\frac{e^{x} - 1}{x}\]

    if -0.0001767842498543489 < x

    1. Initial program 60.4

      \[\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(\frac{1}{2} + x \cdot \frac{1}{6}\right) + x}}{x}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

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

Reproduce

herbie shell --seed 2019199 
(FPCore (x)
  :name "Kahan's exp quotient"

  :herbie-target
  (if (and (< x 1.0) (> x -1.0)) (/ (- (exp x) 1.0) (log (exp x))) (/ (- (exp x) 1.0) x))

  (/ (- (exp x) 1.0) x))