Average Error: 29.1 → 0.5
Time: 34.1s
Precision: 64
Internal Precision: 1408
\[e^{a \cdot x} - 1\]
↓
\[\begin{array}{l}
\mathbf{if}\;e^{a \cdot x} - 1 \le -2.836962126801829 \cdot 10^{-12}:\\
\;\;\;\;\left(\sqrt{e^{a \cdot x}} + 1\right) \cdot \left(\sqrt{e^{a \cdot x}} - 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot a + \left(x \cdot a\right) \cdot \left(\frac{1}{2} \cdot \left(x \cdot a\right)\right)\\
\end{array}\]
Target
| Original | 29.1 |
|---|
| Target | 0.2 |
|---|
| Herbie | 0.5 |
|---|
\[\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 (- (exp (* a x)) 1) < -2.836962126801829e-12
Initial program 0.5
\[e^{a \cdot x} - 1\]
- Using strategy
rm Applied add-sqr-sqrt0.6
\[\leadsto \color{blue}{\sqrt{e^{a \cdot x}} \cdot \sqrt{e^{a \cdot x}}} - 1\]
Applied difference-of-sqr-10.6
\[\leadsto \color{blue}{\left(\sqrt{e^{a \cdot x}} + 1\right) \cdot \left(\sqrt{e^{a \cdot x}} - 1\right)}\]
if -2.836962126801829e-12 < (- (exp (* a x)) 1)
Initial program 44.2
\[e^{a \cdot x} - 1\]
Taylor expanded around 0 13.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)}\]
Taylor expanded around inf 7.5
\[\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 simplify0.5
\[\leadsto \color{blue}{x \cdot a + \left(x \cdot a\right) \cdot \left(\frac{1}{2} \cdot \left(x \cdot a\right)\right)}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1064269945 2896236262 301053905 1701069080 1701464310 1614783279)'
(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))