Average Error: 42.9 → 0.2
Time: 1.6m
Precision: 64
Internal Precision: 1408
\[\frac{e^{x} - 1}{x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \le -9.72316615530548 \cdot 10^{-09}:\\
\;\;\;\;\frac{\frac{\log \left(e^{e^{x + x} - 1}\right)}{e^{x} + 1}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)\\
\end{array}\]
Target
| Original | 42.9 |
|---|
| Target | 42.2 |
|---|
| Herbie | 0.2 |
|---|
\[\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 < -9.72316615530548e-09
Initial program 0.3
\[\frac{e^{x} - 1}{x}\]
- Using strategy
rm Applied flip--0.3
\[\leadsto \frac{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}{x}\]
Applied simplify0.3
\[\leadsto \frac{\frac{\color{blue}{e^{x + x} - 1}}{e^{x} + 1}}{x}\]
- Using strategy
rm Applied add-log-exp0.3
\[\leadsto \frac{\frac{\color{blue}{\log \left(e^{e^{x + x} - 1}\right)}}{e^{x} + 1}}{x}\]
if -9.72316615530548e-09 < x
Initial program 60.6
\[\frac{e^{x} - 1}{x}\]
Taylor expanded around 0 0.1
\[\leadsto \color{blue}{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)}\]
- Recombined 2 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1062930989 876886121 3990119081 3032829768 3060892583 1929069376)'
(FPCore (x)
:name "Kahan's exp quotient"
:herbie-target
(if (and (< x 1) (> x -1)) (/ (- (exp x) 1) (log (exp x))) (/ (- (exp x) 1) x))
(/ (- (exp x) 1) x))