Average Error: 38.7 → 0.5
Time: 12.3s
Precision: 64
Internal Precision: 1344
\[\log \left(1 + x\right)\]
↓
\[\begin{array}{l}
\mathbf{if}\;\log \left(1 + x\right) \le 2.620126338115335 \cdot 10^{-14}:\\
\;\;\;\;x - \left(\frac{1}{2} - x \cdot \frac{1}{3}\right) \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}\]
Target
| Original | 38.7 |
|---|
| Target | 0.3 |
|---|
| Herbie | 0.5 |
|---|
\[\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 (log (+ 1 x)) < 2.620126338115335e-14
Initial program 59.4
\[\log \left(1 + x\right)\]
Taylor expanded around 0 0.2
\[\leadsto \color{blue}{\left(\frac{1}{3} \cdot {x}^{3} + x\right) - \frac{1}{2} \cdot {x}^{2}}\]
Applied simplify0.2
\[\leadsto \color{blue}{x - \left(\frac{1}{2} - x \cdot \frac{1}{3}\right) \cdot \left(x \cdot x\right)}\]
if 2.620126338115335e-14 < (log (+ 1 x))
Initial program 0.9
\[\log \left(1 + x\right)\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1072107073 2127697367 3936270018 2300570620 2134894798 4023771849)'
(FPCore (x)
:name "ln(1 + x)"
:herbie-target
(if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1)))
(log (+ 1 x)))