Average Error: 32.4 → 12.7
Time: 30.2s
Precision: 64
Internal precision: 128
\[e^{a \cdot x} - 1\]
⬇
\[\begin{array}{l}
\mathbf{if}\;a \cdot x \le -1.5153768898317694 \cdot 10^{-23}:\\
\;\;\;\;\frac{e^{x \cdot \left(a + a\right)}}{e^{a \cdot x} + 1} - \frac{1}{1 + e^{a \cdot x}}\\
\mathbf{else}:\\
\;\;\;\;\left(\left({a}^3 \cdot {x}^3\right) \cdot \frac{1}{6} + x \cdot a\right) + \frac{1}{2} \cdot {\left(x \cdot a\right)}^2\\
\end{array}\]
Target
| Original | 32.4 |
| Comparison | 5.9 |
| Herbie | 12.7 |
\[ \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) < -1.5153768898317694e-23
Initial program 2.3
\[e^{a \cdot x} - 1\]
- Using strategy
rm
Applied flip-- 2.3
\[\leadsto \color{blue}{\frac{{\left(e^{a \cdot x}\right)}^2 - {1}^2}{e^{a \cdot x} + 1}}\]
- Using strategy
rm
Applied add-exp-log 2.3
\[\leadsto \frac{\color{blue}{e^{\log \left({\left(e^{a \cdot x}\right)}^2\right)}} - {1}^2}{e^{a \cdot x} + 1}\]
Applied simplify 2.3
\[\leadsto \frac{e^{\color{blue}{x \cdot \left(a + a\right)}} - {1}^2}{e^{a \cdot x} + 1}\]
- Using strategy
rm
Applied div-sub 2.3
\[\leadsto \color{blue}{\frac{e^{x \cdot \left(a + a\right)}}{e^{a \cdot x} + 1} - \frac{{1}^2}{e^{a \cdot x} + 1}}\]
Applied simplify 2.3
\[\leadsto \frac{e^{x \cdot \left(a + a\right)}}{e^{a \cdot x} + 1} - \color{blue}{\frac{1}{1 + e^{a \cdot x}}}\]
if -1.5153768898317694e-23 < (* a x)
Initial program 46.3
\[e^{a \cdot x} - 1\]
Applied taylor 17.5
\[\leadsto a \cdot x + \left(\frac{1}{6} \cdot \left({a}^{3} \cdot {x}^{3}\right) + \frac{1}{2} \cdot \left({a}^2 \cdot {x}^2\right)\right)\]
Taylor expanded around 0 17.5
\[\leadsto \color{blue}{a \cdot x + \left(\frac{1}{6} \cdot \left({a}^{3} \cdot {x}^{3}\right) + \frac{1}{2} \cdot \left({a}^2 \cdot {x}^2\right)\right)}\]
Applied simplify 17.5
\[\leadsto \color{blue}{\left(\left({a}^3 \cdot {x}^3\right) \cdot \frac{1}{6} + x \cdot a\right) + \frac{1}{2} \cdot {\left(x \cdot a\right)}^2}\]
- Recombined 2 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(2828272200 303340187 932035863 914110578 2524963528 4077377947)'
(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))