in reply to Stirling Approx to N! for large Number?

"$n * log ($n) - e* log($n) + 0.5 * (log(2*PI)+log($n));"
Stirling's approx is n^ne^{-n}sqrt{2 pi n), so when you take the log, you get nlog(n) - nlog(e) + .5(log(2pi)+log(n)) so it appears one of your terms is incorrect. (Why not use natural log anyway?)
In addition Stirling's gives an asymptotic approximation (the ratio of Stirling's expression to n! is close to 1 for large n; it is not true that the expresion is close to n! for large n.)
chas

Replies are listed 'Best First'.
Re^2: Stirling Approx to N! for large Number?
by thor (Priest) on Mar 25, 2005 at 13:14 UTC
    Why not use natural log anyway?
    In Perl, the log function does return the natural log. However, it is a property of logarithms that the logarithms of the same number in a different base differ only by a constant multiplicitave constant. That is to say that loga(x) = logb(x)/logb(a). So if one person used their favorite base and you have a different favorite base, you need only scale their answer by a factor of logyours(theirs).

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      Yes, I guess I was thinking the OP meant $n*log(e) rather than e*log($n) (the former is correct), but then log(e) = 1 if log is the natural log (so I wondered if some other log was meant.) You're correct that my comment about using natural log is extraneous...thanks.
      chas