\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \leq 1.0000456952497132:\\
\;\;\;\;\frac{x + {x}^{3} \cdot \left(\left(x \cdot 0.3333333333333333 + -0.5\right) \cdot \left(0.5 - x \cdot 0.3333333333333333\right)\right)}{1 - x \cdot \left(x \cdot 0.3333333333333333 + -0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{1 + x}\right) + \log \left(\sqrt{1 + x}\right)\\
\end{array}(FPCore (x) :precision binary64 (log (+ 1.0 x)))
(FPCore (x)
:precision binary64
(if (<= (+ 1.0 x) 1.0000456952497132)
(/
(+
x
(*
(pow x 3.0)
(* (+ (* x 0.3333333333333333) -0.5) (- 0.5 (* x 0.3333333333333333)))))
(- 1.0 (* x (+ (* x 0.3333333333333333) -0.5))))
(+ (log (sqrt (+ 1.0 x))) (log (sqrt (+ 1.0 x))))))double code(double x) {
return log(1.0 + x);
}
double code(double x) {
double tmp;
if ((1.0 + x) <= 1.0000456952497132) {
tmp = (x + (pow(x, 3.0) * (((x * 0.3333333333333333) + -0.5) * (0.5 - (x * 0.3333333333333333))))) / (1.0 - (x * ((x * 0.3333333333333333) + -0.5)));
} else {
tmp = log(sqrt(1.0 + x)) + log(sqrt(1.0 + x));
}
return tmp;
}




Bits error versus x
Results
| Original | 39.4 |
|---|---|
| Target | 0.3 |
| Herbie | 0.2 |
if (+.f64 1 x) < 1.00004569524971321Initial program 58.9
Taylor expanded around 0 0.3
Simplified0.3
rmApplied flip-+_binary64_13990.3
Applied associate-*r/_binary64_13690.3
Simplified0.3
if 1.00004569524971321 < (+.f64 1 x) Initial program 0.1
rmApplied add-sqr-sqrt_binary64_14460.1
Applied log-prod_binary64_15080.1
Final simplification0.2
herbie shell --seed 2020281
(FPCore (x)
:name "ln(1 + x)"
:precision binary64
:herbie-target
(if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0)))
(log (+ 1.0 x)))