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.
-
$\log a+\log b=\log (a\cdot b)$ – lab bhattacharjee May 08 '13 at 14:57
4 Answers
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).$$

- 374,180
-
-
It’s interesting to note that $\frac{1}{2}\log(2\pi)$ is the divergent sum of the logarithms of all natural numbers – Sidharth Ghoshal Jul 19 '23 at 02:23
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!$

- 7,881
-
I am trying to do this with a computer, so for large $N$, calculating N! may not be possible – user74255 May 08 '13 at 14:58
-
-
-
Will the approximation of N! interfere with the log calculation? I am not sure what O(ln(n)) is – user74255 May 08 '13 at 15:04
-
@user74255: No. You can calculate the approximate value of it, and then take $\log$ of it. – Inceptio May 08 '13 at 15:07
-
Perhaps instead of calculating $N!$ and then taking the $log$, you could in one step calculate the log-gamma function, i.e., $ln Γ (N+1)$. You didn't mention what language you are coding in; this would be very easy in, say, Mathematica. – Ray May 08 '13 at 15:10
-
-
-
-
I'm not talking about computational complexity--you can read about numerical stability here: http://en.wikipedia.org/wiki/Numerical_stability – Ray May 08 '13 at 15:55
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.
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).

- 32,122