Average Error: 41.5 → 0.1
Time: 38.1s
Precision: 64
Internal Precision: 1408
\[\log \left(1 + x\right)\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \le 0.00013873916960373275:\\
\;\;\;\;x + \left(x \cdot x\right) \cdot \left(x \cdot \frac{1}{3} - \frac{1}{2}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}\]
Target
| Original | 41.5 |
|---|
| Target | 6.8 |
|---|
| Herbie | 0.1 |
|---|
\[\begin{array}{l}
\mathbf{if}\;1 + x = 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \log \left(1 + x\right)}{\left(1 + x\right) - 1}\\
\end{array}\]
Derivation
- Split input into 2 regimes
if x < 0.00013873916960373275
Initial program 59.7
\[\log \left(1 + x\right)\]
Taylor expanded around 0 0.1
\[\leadsto \color{blue}{\left(\frac{1}{3} \cdot {x}^{3} + x\right) - \frac{1}{2} \cdot {x}^{2}}\]
Applied simplify0.1
\[\leadsto \color{blue}{x + \left(x \cdot x\right) \cdot \left(x \cdot \frac{1}{3} - \frac{1}{2}\right)}\]
if 0.00013873916960373275 < x
Initial program 0.1
\[\log \left(1 + x\right)\]
- Recombined 2 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1062930989 876886121 3990119081 3032829768 3060892583 1929069376)'
(FPCore (x)
:name "ln(1 + x)"
:herbie-target
(if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1)))
(log (+ 1 x)))