Average Error: 33.4 → 0.2
Time: 18.4s
Precision: 64
Internal precision: 1408
\[e^{a \cdot x} - 1\]
⬇
\[\begin{array}{l}
\mathbf{if}\;a \cdot x \le -4.770999575039998 \cdot 10^{-09}:\\
\;\;\;\;\frac{{\left(e^{a \cdot x}\right)}^2 - {1}^2}{e^{a \cdot x} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot {\left(a \cdot x\right)}^2 + x \cdot a\\
\end{array}\]
Target
| Original | 33.4 |
| Comparison | 8.1 |
| Herbie | 0.2 |
\[ \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) < -4.770999575039998e-09
Initial program 0.3
\[e^{a \cdot x} - 1\]
- Using strategy
rm
Applied flip-- 0.3
\[\leadsto \color{blue}{\frac{{\left(e^{a \cdot x}\right)}^2 - {1}^2}{e^{a \cdot x} + 1}}\]
if -4.770999575039998e-09 < (* a x)
Initial program 48.0
\[e^{a \cdot x} - 1\]
Applied taylor 22.5
\[\leadsto \frac{1}{6} \cdot \left({a}^{3} \cdot {x}^{3}\right) + \left(\frac{1}{2} \cdot \left({a}^2 \cdot {x}^2\right) + a \cdot x\right)\]
Taylor expanded around 0 22.5
\[\leadsto \color{blue}{\frac{1}{6} \cdot \left({a}^{3} \cdot {x}^{3}\right) + \left(\frac{1}{2} \cdot \left({a}^2 \cdot {x}^2\right) + a \cdot x\right)}\]
Applied taylor 12.4
\[\leadsto \frac{1}{6} \cdot 0 + \left(\frac{1}{2} \cdot \left({a}^2 \cdot {x}^2\right) + a \cdot x\right)\]
Taylor expanded around inf 12.4
\[\leadsto \frac{1}{6} \cdot \color{blue}{0} + \left(\frac{1}{2} \cdot \left({a}^2 \cdot {x}^2\right) + a \cdot x\right)\]
Applied simplify 0.1
\[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\left(x \cdot a\right) \cdot \left(x \cdot a\right)\right) + x \cdot a}\]
Applied simplify 0.1
\[\leadsto \color{blue}{\frac{1}{2} \cdot {\left(a \cdot x\right)}^2} + x \cdot a\]
- Recombined 2 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(644180380 3784176976 401987740 22459203 1940947670 3323606534)'
(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))