Average Error: 39.6 → 0.4
Time: 20.6s
Precision: 64
Internal Precision: 1408
\[\frac{e^{x} - 1}{x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{\left(\frac{1}{6} \cdot x + \frac{1}{2}\right) \cdot \left(x \cdot x\right) + x}{x} \le 1.0000000000056495:\\
\;\;\;\;\frac{\left(\frac{1}{6} \cdot x + \frac{1}{2}\right) \cdot \left(x \cdot x\right) + x}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\sqrt{e^{x}} + 1\right) \cdot \left(\sqrt{e^{x}} - 1\right)}{x}\\
\end{array}\]
Target
| Original | 39.6 |
|---|
| Target | 38.8 |
|---|
| Herbie | 0.4 |
|---|
\[\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 x) 1/2) (* x x)) x) x) < 1.0000000000056495
Initial program 60.7
\[\frac{e^{x} - 1}{x}\]
Taylor expanded around 0 0.3
\[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot {x}^{2} + \left(\frac{1}{6} \cdot {x}^{3} + x\right)}}{x}\]
Applied simplify0.3
\[\leadsto \color{blue}{\frac{\left(\frac{1}{6} \cdot x + \frac{1}{2}\right) \cdot \left(x \cdot x\right) + x}{x}}\]
if 1.0000000000056495 < (/ (+ (* (+ (* 1/6 x) 1/2) (* x x)) x) x)
Initial program 0.5
\[\frac{e^{x} - 1}{x}\]
- Using strategy
rm Applied add-sqr-sqrt0.5
\[\leadsto \frac{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}} - 1}{x}\]
Applied difference-of-sqr-10.5
\[\leadsto \frac{\color{blue}{\left(\sqrt{e^{x}} + 1\right) \cdot \left(\sqrt{e^{x}} - 1\right)}}{x}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1151762963 887253659 3096734101 777879090 2714024476 786371635)'
(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))