Average Error: 40.1 → 0.5
Time: 2.0m
Precision: 64
Internal Precision: 1344
\[\frac{e^{x} - 1}{x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right) \le 36.52280345363933:\\
\;\;\;\;\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{{\left(e^{x} - 1\right)}^{3}}}{x}\\
\end{array}\]
Target
| Original | 40.1 |
|---|
| Target | 39.2 |
|---|
| Herbie | 0.5 |
|---|
\[\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 (+ (* 1/6 (pow x 2)) (+ 1 (* 1/2 x))) < 36.52280345363933
Initial program 59.7
\[\frac{e^{x} - 1}{x}\]
Taylor expanded around 0 0.6
\[\leadsto \color{blue}{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)}\]
if 36.52280345363933 < (+ (* 1/6 (pow x 2)) (+ 1 (* 1/2 x)))
Initial program 0.0
\[\frac{e^{x} - 1}{x}\]
- Using strategy
rm Applied add-cbrt-cube0.2
\[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(e^{x} - 1\right) \cdot \left(e^{x} - 1\right)\right) \cdot \left(e^{x} - 1\right)}}}{x}\]
Applied simplify0.2
\[\leadsto \frac{\sqrt[3]{\color{blue}{{\left(e^{x} - 1\right)}^{3}}}}{x}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1071215679 2002590028 935158157 1944352234 2656991306 2955288481)'
(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))