\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000003968673248033738332196662668138742:\\
\;\;\;\;\mathsf{fma}\left(x, 1, \log 1 - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \log \left(1 + x\right) + \log \left(\sqrt{1 + x}\right)\\
\end{array}double f(double x) {
double r104285 = 1.0;
double r104286 = x;
double r104287 = r104285 + r104286;
double r104288 = log(r104287);
return r104288;
}
double f(double x) {
double r104289 = 1.0;
double r104290 = x;
double r104291 = r104289 + r104290;
double r104292 = 1.000003968673248;
bool r104293 = r104291 <= r104292;
double r104294 = log(r104289);
double r104295 = 0.5;
double r104296 = 2.0;
double r104297 = pow(r104290, r104296);
double r104298 = pow(r104289, r104296);
double r104299 = r104297 / r104298;
double r104300 = r104295 * r104299;
double r104301 = r104294 - r104300;
double r104302 = fma(r104290, r104289, r104301);
double r104303 = log(r104291);
double r104304 = r104295 * r104303;
double r104305 = sqrt(r104291);
double r104306 = log(r104305);
double r104307 = r104304 + r104306;
double r104308 = r104293 ? r104302 : r104307;
return r104308;
}




Bits error versus x
| Original | 39.4 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.000003968673248Initial program 59.2
Taylor expanded around 0 0.3
Simplified0.3
if 1.000003968673248 < (+ 1.0 x) Initial program 0.2
rmApplied add-sqr-sqrt0.2
Applied log-prod0.2
rmApplied pow1/20.2
Applied log-pow0.2
Final simplification0.3
herbie shell --seed 2019356 +o rules:numerics
(FPCore (x)
:name "ln(1 + x)"
:precision binary64
:herbie-target
(if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1)))
(log (+ 1 x)))