\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000000000009:\\
\;\;\;\;\left(1 \cdot x + \log 1\right) - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{1 + x}\right)\\
\end{array}double code(double x) {
return log((1.0 + x));
}
double code(double x) {
double VAR;
if (((1.0 + x) <= 1.0000000000000009)) {
VAR = (((1.0 * x) + log(1.0)) - (0.5 * (pow(x, 2.0) / pow(1.0, 2.0))));
} else {
VAR = (log(sqrt((1.0 + x))) + log(sqrt((1.0 + x))));
}
return VAR;
}




Bits error versus x
Results
| Original | 39.0 |
|---|---|
| Target | 0.3 |
| Herbie | 0.7 |
if (+ 1.0 x) < 1.0000000000000009Initial program 59.3
Taylor expanded around 0 0.4
if 1.0000000000000009 < (+ 1.0 x) Initial program 1.1
rmApplied add-sqr-sqrt1.2
Applied log-prod1.1
Final simplification0.7
herbie shell --seed 2020100
(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)))