\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000084552092:\\
\;\;\;\;\mathsf{fma}\left(x, 1, \log 1 - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(2 \cdot \log \left(\sqrt{1 + x}\right)\right) \cdot \log \left(1 + x\right)}\\
\end{array}double f(double x) {
double r100305 = 1.0;
double r100306 = x;
double r100307 = r100305 + r100306;
double r100308 = log(r100307);
return r100308;
}
double f(double x) {
double r100309 = 1.0;
double r100310 = x;
double r100311 = r100309 + r100310;
double r100312 = 1.0000000084552092;
bool r100313 = r100311 <= r100312;
double r100314 = log(r100309);
double r100315 = 0.5;
double r100316 = 2.0;
double r100317 = pow(r100310, r100316);
double r100318 = pow(r100309, r100316);
double r100319 = r100317 / r100318;
double r100320 = r100315 * r100319;
double r100321 = r100314 - r100320;
double r100322 = fma(r100310, r100309, r100321);
double r100323 = sqrt(r100311);
double r100324 = log(r100323);
double r100325 = r100316 * r100324;
double r100326 = log(r100311);
double r100327 = r100325 * r100326;
double r100328 = sqrt(r100327);
double r100329 = r100313 ? r100322 : r100328;
return r100329;
}




Bits error versus x
| Original | 39.3 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.0000000084552092Initial program 59.4
Taylor expanded around 0 0.3
Simplified0.3
if 1.0000000084552092 < (+ 1.0 x) Initial program 0.3
rmApplied add-sqr-sqrt0.8
rmApplied add-sqr-sqrt0.8
Applied log-prod0.8
rmApplied sqrt-unprod0.3
Simplified0.3
Final simplification0.3
herbie shell --seed 2020039 +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)))