Average Error: 39.9 → 0.2
Time: 1.1m
Precision: 64
Internal Precision: 1408
\[\frac{e^{x} - 1}{x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{\left(\sqrt[3]{x + \left(x \cdot x\right) \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)} \cdot \sqrt[3]{x + \left(x \cdot x\right) \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)}\right) \cdot \sqrt[3]{\left(\frac{1}{2} + \frac{1}{6} \cdot x\right) \cdot \left(x \cdot x\right) + x}}{x} \le 1.0003521562566515:\\
\;\;\;\;\sqrt[3]{{\left(\left(x \cdot \frac{1}{6}\right) \cdot x + \left(1 + \frac{1}{2} \cdot x\right)\right)}^{3}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{e^{x + x} - 1}{e^{x} + 1}}{x}\\
\end{array}\]
Target
| Original | 39.9 |
|---|
| Target | 39.1 |
|---|
| 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 (/ (* (* (cbrt (+ x (* (* x x) (+ 1/2 (* 1/6 x))))) (cbrt (+ x (* (* x x) (+ 1/2 (* 1/6 x)))))) (cbrt (+ (* (+ 1/2 (* 1/6 x)) (* x x)) x))) x) < 1.0003521562566515
Initial program 60.3
\[\frac{e^{x} - 1}{x}\]
Taylor expanded around 0 0.2
\[\leadsto \color{blue}{\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)}\]
- Using strategy
rm Applied add-cbrt-cube0.2
\[\leadsto \color{blue}{\sqrt[3]{\left(\left(\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)\right) \cdot \left(\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)\right)\right) \cdot \left(\frac{1}{6} \cdot {x}^{2} + \left(1 + \frac{1}{2} \cdot x\right)\right)}}\]
Applied simplify0.2
\[\leadsto \sqrt[3]{\color{blue}{{\left(\left(x \cdot \frac{1}{6}\right) \cdot x + \left(1 + \frac{1}{2} \cdot x\right)\right)}^{3}}}\]
if 1.0003521562566515 < (/ (* (* (cbrt (+ x (* (* x x) (+ 1/2 (* 1/6 x))))) (cbrt (+ x (* (* x x) (+ 1/2 (* 1/6 x)))))) (cbrt (+ (* (+ 1/2 (* 1/6 x)) (* x x)) x))) x)
Initial program 0.0
\[\frac{e^{x} - 1}{x}\]
- Using strategy
rm Applied flip--0.1
\[\leadsto \frac{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}{x}\]
Applied simplify0.0
\[\leadsto \frac{\frac{\color{blue}{e^{x + x} - 1}}{e^{x} + 1}}{x}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1070960995 739739648 2531964651 3069671617 351857262 3877178482)'
(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))