Average Error: 63.0 → 0.0
Time: 3.6s
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{fma}\left(n, \frac{1}{n}, \mathsf{log1p}\left(n\right)\right) + -1 \]
\left(\left(n + 1\right) \cdot \log \left(n + 1\right) - n \cdot \log n\right) - 1
\mathsf{fma}\left(n, \frac{1}{n}, \mathsf{log1p}\left(n\right)\right) + -1
(FPCore (n)
 :precision binary64
 (- (- (* (+ n 1.0) (log (+ n 1.0))) (* n (log n))) 1.0))
(FPCore (n) :precision binary64 (+ (fma n (/ 1.0 n) (log1p n)) -1.0))
double code(double n) {
	return (((n + 1.0) * log(n + 1.0)) - (n * log(n))) - 1.0;
}
double code(double n) {
	return fma(n, (1.0 / n), log1p(n)) + -1.0;
}

Error

Bits error versus n

Target

Original63.0
Target0
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{fma}\left(n, \mathsf{log1p}\left(n\right) - \log n, \mathsf{log1p}\left(n\right)\right) + -1} \]
  3. Taylor expanded in n around inf 0.0

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

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

Reproduce

herbie shell --seed 2021329 
(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))