Average Error: 33.4 → 0.1
Time: 12.7s
Precision: 64
Internal precision: 1408
\[e^{a \cdot x} - 1\]
⬇
\[\begin{array}{l}
\mathbf{if}\;a \cdot x \le -4.230530163534557 \cdot 10^{-06}:\\
\;\;\;\;\log \left(e^{e^{a \cdot x} - 1}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(x \cdot a\right) \cdot \left(x \cdot a\right)\right) \cdot \frac{1}{2} + x \cdot a\\
\end{array}\]
Target
| Original | 33.4 |
| Comparison | 8.1 |
| Herbie | 0.1 |
\[ \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.230530163534557e-06
Initial program 0.1
\[e^{a \cdot x} - 1\]
- Using strategy
rm
Applied add-log-exp 0.1
\[\leadsto \color{blue}{\log \left(e^{e^{a \cdot x} - 1}\right)}\]
if -4.230530163534557e-06 < (* a x)
Initial program 47.5
\[e^{a \cdot x} - 1\]
Applied taylor 43.6
\[\leadsto \left(a \cdot x + \left(1 + \frac{1}{2} \cdot \left({a}^{2} \cdot {x}^{2}\right)\right)\right) - 1\]
Taylor expanded around 0 43.6
\[\leadsto \color{blue}{\left(a \cdot x + \left(1 + \frac{1}{2} \cdot \left({a}^{2} \cdot {x}^{2}\right)\right)\right)} - 1\]
Applied simplify 0.1
\[\leadsto \color{blue}{\left(\left(x \cdot a\right) \cdot \left(x \cdot a\right)\right) \cdot \frac{1}{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 '#(1067901057 3396600083 3715501224 3126139233 3908045574 1593683916)'
(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))