Average Error: 33.6 → 0.3
Time: 11.0s
Precision: 64
Internal precision: 1408
\[e^{a \cdot x} - 1\]
⬇
\[\begin{array}{l}
\mathbf{if}\;a \cdot x \le -9.437845517826107 \cdot 10^{-14}:\\
\;\;\;\;\frac{{\left(e^{a \cdot x}\right)}^2 - {1}^2}{e^{a \cdot x} + 1}\\
\mathbf{else}:\\
\;\;\;\;x \cdot a + {\left(a \cdot x\right)}^2 \cdot \frac{1}{2}\\
\end{array}\]
Target
| Original | 33.6 |
| Comparison | 8.1 |
| Herbie | 0.3 |
\[ \begin{array}{l}
\mathbf{if}\;\left|a \cdot x\right| \lt \frac{1}{10}:\\
\;\;\;\;\left(a \cdot x\right) \cdot \left(1 + \left(\frac{a \cdot x}{2} + \frac{{\left(a \cdot x\right)}^2}{6}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;e^{a \cdot x} - 1\\
\end{array} \]
Derivation
- Split input into 2 regimes.
-
if (* a x) < -9.437845517826107e-14
Initial program 0.8
\[e^{a \cdot x} - 1\]
- Using strategy
rm
Applied flip-- 0.8
\[\leadsto \color{blue}{\frac{{\left(e^{a \cdot x}\right)}^2 - {1}^2}{e^{a \cdot x} + 1}}\]
if -9.437845517826107e-14 < (* a x)
Initial program 48.0
\[e^{a \cdot x} - 1\]
Applied taylor 43.3
\[\leadsto \left(1 + \left(\frac{1}{2} \cdot \left({a}^2 \cdot {x}^2\right) + a \cdot x\right)\right) - 1\]
Taylor expanded around 0 43.3
\[\leadsto \color{blue}{\left(1 + \left(\frac{1}{2} \cdot \left({a}^2 \cdot {x}^2\right) + a \cdot x\right)\right)} - 1\]
Applied simplify 0.1
\[\leadsto \color{blue}{\left(a \cdot x + 0\right) + {\left(a \cdot x\right)}^2 \cdot \frac{1}{2}}\]
Applied simplify 0.1
\[\leadsto \color{blue}{x \cdot a} + {\left(a \cdot x\right)}^2 \cdot \frac{1}{2}\]
- Recombined 2 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1067773715 2765207660 218871639 3688798924 2755544087 2054563380)'
(FPCore (a x)
:name "expax (section 3.5)"
:target
(if (< (fabs (* a x)) 1/10) (* (* a x) (+ 1 (+ (/ (* a x) 2) (/ (sqr (* a x)) 6)))) (- (exp (* a x)) 1))
(- (exp (* a x)) 1))