Average Error: 42.8 → 2.9
Time: 9.0s
Precision: 64
Internal precision: 1408
\[\frac{e^{x} - 1}{x}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;x \le -1.3260991409638585 \cdot 10^{-12}:\\
\;\;\;\;\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{\left({\left(e^{x}\right)}^2 + \left(e^{x} + 1\right)\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^2 \cdot \left(x \cdot \frac{1}{6} + \frac{1}{2}\right) + x}{x}\\
\end{array}\]
Target
| Original | 42.8 |
| Comparison | 42.2 |
| Herbie | 2.9 |
\[ \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
- Split input into 2 regimes.
-
if x < -1.3260991409638585e-12
Initial program 0.6
\[\frac{e^{x} - 1}{x}\]
- Using strategy
rm
Applied flip3-- 0.6
\[\leadsto \frac{\color{blue}{\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{{\left(e^{x}\right)}^2 + \left({1}^2 + e^{x} \cdot 1\right)}}}{x}\]
Applied associate-/l/ 0.6
\[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{x \cdot \left({\left(e^{x}\right)}^2 + \left({1}^2 + e^{x} \cdot 1\right)\right)}}\]
Applied simplify 0.6
\[\leadsto \frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{\color{blue}{\left(e^{x + x} + \left(e^{x} + 1\right)\right) \cdot x}}\]
Applied simplify 0.6
\[\leadsto \frac{{\left(e^{x}\right)}^{3} - {1}^{3}}{\color{blue}{\left({\left(e^{x}\right)}^2 + \left(e^{x} + 1\right)\right)} \cdot x}\]
if -1.3260991409638585e-12 < x
Initial program 60.9
\[\frac{e^{x} - 1}{x}\]
Applied taylor 4.0
\[\leadsto \frac{\frac{1}{2} \cdot {x}^2 + \left(\frac{1}{6} \cdot {x}^{3} + x\right)}{x}\]
Taylor expanded around 0 4.0
\[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot {x}^2 + \left(\frac{1}{6} \cdot {x}^{3} + x\right)}}{x}\]
Applied simplify 4.0
\[\leadsto \color{blue}{\frac{{x}^2 \cdot \left(x \cdot \frac{1}{6} + \frac{1}{2}\right) + x}{x}}\]
- Recombined 2 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(FPCore (x)
:name "Kahan's exp quotient"
:target
(if (and (< x 1) (> x -1)) (/ (- (exp x) 1) (log (exp x))) (/ (- (exp x) 1) x))
(/ (- (exp x) 1) x))