Average Error: 63.0 → 0
Time: 2.9s
Precision: 64
\[n \gt 6.8 \cdot 10^{15}\]
\[\left(\left(n + 1\right) \cdot \log \left(n + 1\right) - n \cdot \log n\right) - 1\]
\[\mathsf{fma}\left(\frac{1}{n}, 0.5 - \frac{0.16666666666666669}{n}, \log n \cdot 1\right)\]
\left(\left(n + 1\right) \cdot \log \left(n + 1\right) - n \cdot \log n\right) - 1
\mathsf{fma}\left(\frac{1}{n}, 0.5 - \frac{0.16666666666666669}{n}, \log n \cdot 1\right)
double code(double n) {
	return ((((n + 1.0) * log((n + 1.0))) - (n * log(n))) - 1.0);
}
double code(double n) {
	return fma((1.0 / n), (0.5 - (0.16666666666666669 / n)), (log(n) * 1.0));
}

Error

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original63.0
Target0
Herbie0
\[\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. Simplified61.9

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

    \[\leadsto \color{blue}{0.5 \cdot \frac{1}{n} - \left(1 \cdot \log \left(\frac{1}{n}\right) + 0.16666666666666669 \cdot \frac{1}{{n}^{2}}\right)}\]
  4. Simplified0

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{n}, 0.5 - \frac{0.16666666666666669}{n}, \log n \cdot 1\right)}\]
  5. Final simplification0

    \[\leadsto \mathsf{fma}\left(\frac{1}{n}, 0.5 - \frac{0.16666666666666669}{n}, \log n \cdot 1\right)\]

Reproduce

herbie shell --seed 2020057 +o rules:numerics
(FPCore (n)
  :name "logs (example 3.8)"
  :precision binary64
  :pre (> n 6.8e+15)

  :herbie-target
  (- (log (+ n 1)) (- (/ 1 (* 2 n)) (- (/ 1 (* 3 (* n n))) (/ 4 (pow n 3)))))

  (- (- (* (+ n 1) (log (+ n 1))) (* n (log n))) 1))