7
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ $\log a+\log b=\log (a\cdot b)$ $\endgroup$ – lab bhattacharjee May 8 '13 at 14:57
7
$\begingroup$

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

$\endgroup$
5
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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!$

$\endgroup$
  • $\begingroup$ I am trying to do this with a computer, so for large $N$, calculating N! may not be possible $\endgroup$ – user74255 May 8 '13 at 14:58
  • $\begingroup$ @Inceptio, it's better to show the means than end $\endgroup$ – lab bhattacharjee May 8 '13 at 14:59
  • $\begingroup$ @labbhattacharjee: Considered it. Edited.:) $\endgroup$ – Inceptio May 8 '13 at 15:03
  • $\begingroup$ Will the approximation of N! interfere with the log calculation? I am not sure what O(ln(n)) is $\endgroup$ – user74255 May 8 '13 at 15:04
  • $\begingroup$ @user74255: No. You can calculate the approximate value of it, and then take $\log$ of it. $\endgroup$ – Inceptio May 8 '13 at 15:07
1
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.