Summation of logs

$\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$ 1

4 Answers

$\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$ 1 $\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$ 10 $\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$ $\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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like