10

Are there any useful identities for quickly calculating the sum of consecutive logs? For example $\sum_{k=1}^{N} log(k)$ or something to this effect. I should add that I am writing code to do this (as opposed to doing this on a calculator) so N can be very large.

user74255
  • 145

4 Answers4

10

For large $N$, we have $N!\approx N^Ne^{-N}\sqrt {2\pi N}$ (Stirling formula) and hence $$\sum_{k=1}^N\ln k\approx\left( N+\frac12\right)\ln N-N+\frac12\ln(2\pi).$$

7

Hint:

Use the fact that $\log(a)+\log(b)=\log(ab)$

Your expression simply becomes $\sum_1^N \log k=\log(N!)$, and now you can have Stirling Approximation to approximate $N!$

Inceptio
  • 7,881
7

The Euler-Maclaurin Sum Formula, can also be used to get an asymptotic expansion. It gives $$ \sum_{k=1}^n\log(k)=\overbrace{\vphantom{\frac12}C}^{\frac12\log(2\pi)}+\overbrace{\vphantom{\frac12}n\log(n)-n}^{\int f(n)\,\mathrm{d}n}+\overbrace{\frac12\log(n)}^{\frac12f(n)}+\overbrace{\frac1{12n}}^{\frac1{12}f'(n)}-\overbrace{\frac1{360n^3}}^{\frac1{720}f'''(n)}+\dots $$ The constant $\frac12\log(2\pi)$ is derived as in the proof of Stirling's Formula.

robjohn
  • 345,667
3

In the particular case of $$ \sum_{k=1}^N\log k=\log N!=\log\Gamma(N+1) $$ this is just the loggama function, which is implemented in many software systems. This is fast and accurate.

For example, it is lngamma in GP, lgamma in C (math.h), LogGamma in Mathematica, lnGAMMA in Maple, LogGamma in Magma, gammaln in MatLab, lnGamma in Mathcad, log_gamma in Sage, math.lgamma in Python, and gammaln in Perl (Math::SpecFun::Gamma).

Charles
  • 32,122