Average Error: 63.0 → 0.0
Time: 4.3s
Precision: binary64
\[n > 6.8 \cdot 10^{+15}\]
\[\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} \]
(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}

Error

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original63.0
Target0.0
Herbie0.0
\[\log \left(n + 1\right) - \left(\frac{1}{2 \cdot n} - \left(\frac{1}{3 \cdot \left(n \cdot n\right)} - \frac{4}{{n}^{3}}\right)\right) \]

Derivation

  1. Initial program 63.0

    \[\left(\left(n + 1\right) \cdot \log \left(n + 1\right) - n \cdot \log n\right) - 1 \]
  2. Simplified44.2

    \[\leadsto \color{blue}{\mathsf{log1p}\left(n\right) - \mathsf{fma}\left(n, \log n - \mathsf{log1p}\left(n\right), 1\right)} \]
  3. Taylor expanded in n around inf 0.0

    \[\leadsto \mathsf{log1p}\left(n\right) - \color{blue}{\frac{0.5}{n}} \]
  4. Final simplification0.0

    \[\leadsto \mathsf{log1p}\left(n\right) + \frac{-0.5}{n} \]

Reproduce

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))