\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000780384010967694052851584274321795:\\
\;\;\;\;\left(1 \cdot x + \log 1\right) - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\\
\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 r52623 = 1.0;
double r52624 = x;
double r52625 = r52623 + r52624;
double r52626 = log(r52625);
return r52626;
}
double f(double x) {
double r52627 = 1.0;
double r52628 = x;
double r52629 = r52627 + r52628;
double r52630 = 1.000000780384011;
bool r52631 = r52629 <= r52630;
double r52632 = r52627 * r52628;
double r52633 = log(r52627);
double r52634 = r52632 + r52633;
double r52635 = 0.5;
double r52636 = 2.0;
double r52637 = pow(r52628, r52636);
double r52638 = pow(r52627, r52636);
double r52639 = r52637 / r52638;
double r52640 = r52635 * r52639;
double r52641 = r52634 - r52640;
double r52642 = sqrt(r52629);
double r52643 = log(r52642);
double r52644 = sqrt(r52642);
double r52645 = log(r52644);
double r52646 = r52645 + r52645;
double r52647 = r52643 + r52646;
double r52648 = r52631 ? r52641 : r52647;
return r52648;
}




Bits error versus x
Results
| Original | 38.6 |
|---|---|
| Target | 0.3 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.000000780384011Initial program 59.1
Taylor expanded around 0 0.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
(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)))