Average Error: 39.1 → 0.2
Time: 48.8s
Precision: 64
Internal Precision: 1408
\[\log \left(1 + x\right)\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \le 0.00017661073014950401:\\
\;\;\;\;x + \left(x \cdot x\right) \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(\left|\sqrt[3]{x + 1}\right| \cdot \sqrt{\sqrt[3]{1 + x}}\right)\\
\end{array}\]
Target
| Original | 39.1 |
|---|
| Target | 0.2 |
|---|
| Herbie | 0.2 |
|---|
\[\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.00017661073014950401
Initial program 59.0
\[\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(x \cdot x\right) \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right)}\]
if 0.00017661073014950401 < x
Initial program 0.1
\[\log \left(1 + x\right)\]
- Using strategy
rm Applied add-sqr-sqrt0.1
\[\leadsto \log \color{blue}{\left(\sqrt{1 + x} \cdot \sqrt{1 + x}\right)}\]
Applied log-prod0.1
\[\leadsto \color{blue}{\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{1 + x}\right)}\]
- Using strategy
rm Applied add-cube-cbrt0.1
\[\leadsto \log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{\color{blue}{\left(\sqrt[3]{1 + x} \cdot \sqrt[3]{1 + x}\right) \cdot \sqrt[3]{1 + x}}}\right)\]
Applied sqrt-prod0.1
\[\leadsto \log \left(\sqrt{1 + x}\right) + \log \color{blue}{\left(\sqrt{\sqrt[3]{1 + x} \cdot \sqrt[3]{1 + x}} \cdot \sqrt{\sqrt[3]{1 + x}}\right)}\]
Applied simplify0.1
\[\leadsto \log \left(\sqrt{1 + x}\right) + \log \left(\color{blue}{\left|\sqrt[3]{x + 1}\right|} \cdot \sqrt{\sqrt[3]{1 + x}}\right)\]
- Recombined 2 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(3622638036 3041702260 3649696288 21285302 1742518495 296600799)'
(FPCore (x)
:name "ln(1 + x)"
:herbie-target
(if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1)))
(log (+ 1 x)))