Average Error: 39.2 → 0.4
Time: 5.6s
Precision: 64
$\frac{1 - e^{-x}}{x}$
$\begin{array}{l} \mathbf{if}\;x \le 1.619478639329793683010461080584718729369 \cdot 10^{-4}:\\ \;\;\;\;1 + x \cdot \left(\frac{1}{6} \cdot x + \frac{-1}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - \frac{e^{-x}}{x}\\ \end{array}$
\frac{1 - e^{-x}}{x}
\begin{array}{l}
\mathbf{if}\;x \le 1.619478639329793683010461080584718729369 \cdot 10^{-4}:\\
\;\;\;\;1 + x \cdot \left(\frac{1}{6} \cdot x + \frac{-1}{2}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{x} - \frac{e^{-x}}{x}\\

\end{array}
double f(double x) {
double r685965 = 1.0;
double r685966 = x;
double r685967 = -r685966;
double r685968 = exp(r685967);
double r685969 = r685965 - r685968;
double r685970 = r685969 / r685966;
return r685970;
}


double f(double x) {
double r685971 = x;
double r685972 = 0.00016194786393297937;
bool r685973 = r685971 <= r685972;
double r685974 = 1.0;
double r685975 = 0.16666666666666666;
double r685976 = r685975 * r685971;
double r685977 = -0.5;
double r685978 = r685976 + r685977;
double r685979 = r685971 * r685978;
double r685980 = r685974 + r685979;
double r685981 = 1.0;
double r685982 = r685981 / r685971;
double r685983 = -r685971;
double r685984 = exp(r685983);
double r685985 = r685984 / r685971;
double r685986 = r685982 - r685985;
double r685987 = r685973 ? r685980 : r685986;
return r685987;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 2 regimes
2. ## if x < 0.00016194786393297937

1. Initial program 59.9

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

$\leadsto \color{blue}{\left(\frac{1}{6} \cdot {x}^{2} + 1\right) - \frac{1}{2} \cdot x}$
3. Simplified0.5

$\leadsto \color{blue}{1 + x \cdot \left(\frac{1}{6} \cdot x + \frac{-1}{2}\right)}$

## if 0.00016194786393297937 < x

1. Initial program 0.1

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

$\leadsto \color{blue}{\frac{1}{x} - \frac{e^{-x}}{x}}$
3. Recombined 2 regimes into one program.
4. Final simplification0.4

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

# Reproduce

herbie shell --seed 1
(FPCore (x)
:name "(1-exp(-x))/x"
:precision binary64
(/ (- 1 (exp (- x))) x))