\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000000019218915:\\
\;\;\;\;\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) + \frac{1}{2} \cdot \log \left(1 + x\right)\\
\end{array}double f(double x) {
double r51662 = 1.0;
double r51663 = x;
double r51664 = r51662 + r51663;
double r51665 = log(r51664);
return r51665;
}
double f(double x) {
double r51666 = 1.0;
double r51667 = x;
double r51668 = r51666 + r51667;
double r51669 = 1.0000000001921892;
bool r51670 = r51668 <= r51669;
double r51671 = log(r51666);
double r51672 = 0.5;
double r51673 = 2.0;
double r51674 = pow(r51667, r51673);
double r51675 = pow(r51666, r51673);
double r51676 = r51674 / r51675;
double r51677 = r51672 * r51676;
double r51678 = r51671 - r51677;
double r51679 = fma(r51667, r51666, r51678);
double r51680 = sqrt(r51668);
double r51681 = log(r51680);
double r51682 = log(r51668);
double r51683 = r51672 * r51682;
double r51684 = r51681 + r51683;
double r51685 = r51670 ? r51679 : r51684;
return r51685;
}




Bits error versus x
| Original | 39.0 |
|---|---|
| Target | 0.2 |
| Herbie | 0.4 |
if (+ 1.0 x) < 1.0000000001921892Initial program 59.3
Taylor expanded around 0 0.3
Simplified0.3
if 1.0000000001921892 < (+ 1.0 x) Initial program 0.5
rmApplied add-sqr-sqrt0.6
Applied log-prod0.5
rmApplied pow1/20.5
Applied log-pow0.5
Final simplification0.4
herbie shell --seed 2020034 +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)))