(FPCore (n) :precision binary64 (- (- (* (+ n 1.0) (log (+ n 1.0))) (* n (log n))) 1.0))
(FPCore (n) :precision binary64 (+ (log1p n) (/ -0.5 n)))
double code(double n) {
return (((n + 1.0) * log((n + 1.0))) - (n * log(n))) - 1.0;
}
double code(double n) {
return log1p(n) + (-0.5 / n);
}
public static double code(double n) {
return (((n + 1.0) * Math.log((n + 1.0))) - (n * Math.log(n))) - 1.0;
}
public static double code(double n) {
return Math.log1p(n) + (-0.5 / n);
}
def code(n): return (((n + 1.0) * math.log((n + 1.0))) - (n * math.log(n))) - 1.0
def code(n): return math.log1p(n) + (-0.5 / n)
function code(n) return Float64(Float64(Float64(Float64(n + 1.0) * log(Float64(n + 1.0))) - Float64(n * log(n))) - 1.0) end
function code(n) return Float64(log1p(n) + Float64(-0.5 / n)) end
code[n_] := N[(N[(N[(N[(n + 1.0), $MachinePrecision] * N[Log[N[(n + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(n * N[Log[n], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
code[n_] := N[(N[Log[1 + n], $MachinePrecision] + N[(-0.5 / n), $MachinePrecision]), $MachinePrecision]
\left(\left(n + 1\right) \cdot \log \left(n + 1\right) - n \cdot \log n\right) - 1
\mathsf{log1p}\left(n\right) + \frac{-0.5}{n}




Bits error versus n
Results
| Original | 63.0 |
|---|---|
| Target | 0.0 |
| Herbie | 0.0 |
Initial program 63.0
Simplified44.2
Taylor expanded in n around inf 0.0
Final simplification0.0
herbie shell --seed 2022151
(FPCore (n)
:name "logs (example 3.8)"
:precision binary64
:pre (> n 6.8e+15)
:herbie-target
(- (log (+ n 1.0)) (- (/ 1.0 (* 2.0 n)) (- (/ 1.0 (* 3.0 (* n n))) (/ 4.0 (pow n 3.0)))))
(- (- (* (+ n 1.0) (log (+ n 1.0))) (* n (log n))) 1.0))