Average Error: 29.6 → 0.3
Time: 1.1m
Precision: 64
Internal Precision: 1408
\[e^{a \cdot x} - 1\]
↓
\[\begin{array}{l}
\mathbf{if}\;a \cdot x \le -0.00016458823680732482:\\
\;\;\;\;\log \left(e^{e^{a \cdot x} - 1}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{6} \cdot {\left(a \cdot x\right)}^{3} + \left(\frac{1}{2} \cdot {\left(a \cdot x\right)}^{2} + a \cdot x\right)\\
\end{array}\]
Target
| Original | 29.6 |
|---|
| Target | 0.2 |
|---|
| 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) < -0.00016458823680732482
Initial program 0.0
\[e^{a \cdot x} - 1\]
- Using strategy
rm Applied add-log-exp0.1
\[\leadsto \color{blue}{\log \left(e^{e^{a \cdot x} - 1}\right)}\]
if -0.00016458823680732482 < (* a x)
Initial program 44.4
\[e^{a \cdot x} - 1\]
Taylor expanded around 0 14.1
\[\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)}\]
- Using strategy
rm Applied pow-prod-down8.1
\[\leadsto \frac{1}{6} \cdot \color{blue}{{\left(a \cdot x\right)}^{3}} + \left(\frac{1}{2} \cdot \left({a}^{2} \cdot {x}^{2}\right) + a \cdot x\right)\]
- Using strategy
rm Applied pow-prod-down0.5
\[\leadsto \frac{1}{6} \cdot {\left(a \cdot x\right)}^{3} + \left(\frac{1}{2} \cdot \color{blue}{{\left(a \cdot x\right)}^{2}} + a \cdot x\right)\]
- Recombined 2 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063185673 2139736501 2393378123 1907444849 1070993796 1007244912)'
(FPCore (a x)
:name "expax (section 3.5)"
:herbie-target
(if (< (fabs (* a x)) 1/10) (* (* a x) (+ 1 (+ (/ (* a x) 2) (/ (pow (* a x) 2) 6)))) (- (exp (* a x)) 1))
(- (exp (* a x)) 1))