\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \leq 1.0000000008461332:\\
\;\;\;\;\left(\left({x}^{3} - 0.5 \cdot {x}^{6}\right) + {x}^{9} \cdot 0.3333333333333333\right) - \left(\left(x \cdot x\right) \cdot \left(0.5 + x \cdot 0.6666666666666666\right) + \left({x}^{4} \cdot 0.25 - x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}(FPCore (x) :precision binary64 (log (+ 1.0 x)))
(FPCore (x)
:precision binary64
(if (<= (+ 1.0 x) 1.0000000008461332)
(-
(+ (- (pow x 3.0) (* 0.5 (pow x 6.0))) (* (pow x 9.0) 0.3333333333333333))
(+
(* (* x x) (+ 0.5 (* x 0.6666666666666666)))
(- (* (pow x 4.0) 0.25) x)))
(log (+ 1.0 x))))double code(double x) {
return log(1.0 + x);
}
double code(double x) {
double tmp;
if ((1.0 + x) <= 1.0000000008461332) {
tmp = ((pow(x, 3.0) - (0.5 * pow(x, 6.0))) + (pow(x, 9.0) * 0.3333333333333333)) - (((x * x) * (0.5 + (x * 0.6666666666666666))) + ((pow(x, 4.0) * 0.25) - x));
} else {
tmp = log(1.0 + x);
}
return tmp;
}














Bits error versus x
Results
| Original | 38.9 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 21185 |
| Alternative 2 | |
|---|---|
| Error | 0.3 |
| Cost | 7873 |
| Alternative 3 | |
|---|---|
| Error | 0.3 |
| Cost | 7041 |
| Alternative 4 | |
|---|---|
| Error | 0.5 |
| Cost | 6785 |
| Alternative 5 | |
|---|---|
| Error | 18.7 |
| Cost | 1281 |
| Alternative 6 | |
|---|---|
| Error | 18.7 |
| Cost | 1025 |
| Alternative 7 | |
|---|---|
| Error | 18.9 |
| Cost | 769 |
| Alternative 8 | |
|---|---|
| Error | 18.9 |
| Cost | 769 |
| Alternative 9 | |
|---|---|
| Error | 19.4 |
| Cost | 385 |
| Alternative 10 | |
|---|---|
| Error | 21.2 |
| Cost | 64 |


if (+.f64 1 x) < 1.00000000084613316Initial program 59.2
rmApplied flip3-+_binary64_76359.3
Applied log-div_binary64_84759.3
Simplified59.3
Simplified59.3
Taylor expanded around 0 0.2
Simplified0.2
Taylor expanded around 0 0.2
Simplified0.2
Simplified0.2
if 1.00000000084613316 < (+.f64 1 x) Initial program 0.4
Simplified0.4
Final simplification0.3
herbie shell --seed 2021040
(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)))