Average Error: 40.1 → 0.2
Time: 42.7s
Precision: 64
Internal Precision: 1344
\[\frac{e^{x} - 1}{x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\sqrt{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)} \cdot \left(\log \left(e^{\frac{5}{96} \cdot {x}^{2}}\right) + \left(1 + \frac{1}{4} \cdot x\right)\right) \le 1.0262104794077462:\\
\;\;\;\;\sqrt{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)} \cdot \left(\log \left(e^{\frac{5}{96} \cdot {x}^{2}}\right) + \left(1 + \frac{1}{4} \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x}}{x} - \frac{1}{x}\\
\end{array}\]
Try it out
Enter valid numbers for all inputs
Target
| Original | 40.1 |
|---|
| Target | 39.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 (* (sqrt (+ (* 1/6 (pow x 2)) (+ 1 (* 1/2 x)))) (+ (log (exp (* 5/96 (pow x 2)))) (+ 1 (* 1/4 x)))) < 1.0262104794077462
Initial program 60.0
\[\frac{e^{x} - 1}{x}\]
Taylor expanded around 0 0.4
\[\leadsto \color{blue}{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)}\]
- Using strategy
rm Applied add-sqr-sqrt0.4
\[\leadsto \color{blue}{\sqrt{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)} \cdot \sqrt{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)}}\]
Taylor expanded around 0 0.4
\[\leadsto \sqrt{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)} \cdot \color{blue}{\left(\frac{5}{96} \cdot {x}^{2} + \left(1 + \frac{1}{4} \cdot x\right)\right)}\]
- Using strategy
rm Applied add-log-exp0.4
\[\leadsto \sqrt{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)} \cdot \left(\color{blue}{\log \left(e^{\frac{5}{96} \cdot {x}^{2}}\right)} + \left(1 + \frac{1}{4} \cdot x\right)\right)\]
if 1.0262104794077462 < (* (sqrt (+ (* 1/6 (pow x 2)) (+ 1 (* 1/2 x)))) (+ (log (exp (* 5/96 (pow x 2)))) (+ 1 (* 1/4 x))))
Initial program 0.0
\[\frac{e^{x} - 1}{x}\]
- Using strategy
rm Applied div-sub0.0
\[\leadsto \color{blue}{\frac{e^{x}}{x} - \frac{1}{x}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed 2018206
(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))