\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000780384010967694052851584274321795:\\
\;\;\;\;\mathsf{fma}\left(x, 1, \log 1 - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \left(\log \left(\sqrt{\sqrt{1 + x}}\right) + \log \left(\sqrt{\sqrt{1 + x}}\right)\right)\\
\end{array}double f(double x) {
double r81456 = 1.0;
double r81457 = x;
double r81458 = r81456 + r81457;
double r81459 = log(r81458);
return r81459;
}
double f(double x) {
double r81460 = 1.0;
double r81461 = x;
double r81462 = r81460 + r81461;
double r81463 = 1.000000780384011;
bool r81464 = r81462 <= r81463;
double r81465 = log(r81460);
double r81466 = 0.5;
double r81467 = 2.0;
double r81468 = pow(r81461, r81467);
double r81469 = pow(r81460, r81467);
double r81470 = r81468 / r81469;
double r81471 = r81466 * r81470;
double r81472 = r81465 - r81471;
double r81473 = fma(r81461, r81460, r81472);
double r81474 = sqrt(r81462);
double r81475 = log(r81474);
double r81476 = sqrt(r81474);
double r81477 = log(r81476);
double r81478 = r81477 + r81477;
double r81479 = r81475 + r81478;
double r81480 = r81464 ? r81473 : r81479;
return r81480;
}




Bits error versus x
| Original | 38.6 |
|---|---|
| Target | 0.3 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.000000780384011Initial program 59.1
Taylor expanded around 0 0.4
Simplified0.4
if 1.000000780384011 < (+ 1.0 x) Initial program 0.1
rmApplied add-sqr-sqrt0.1
Applied log-prod0.1
rmApplied add-sqr-sqrt0.1
Applied sqrt-prod0.1
Applied log-prod0.1
Final simplification0.3
herbie shell --seed 2020002 +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)))