Skip to content
Prev 246766 / 398506 Next

how to calculate this natural logarithm

On Sat, Jan 08, 2011 at 12:20:59AM +0800, zhaoxing731 wrote:
The natural logarithm of choose() is lchoose(), so the
natural logarithms of the products above are

  i <- 482:600
  logx <- lchoose(2000000,i) + lchoose(1000000,600-i)
  maxlog <- max(logx)
  # [1] 5675.315

The sum of numbers, which have very different magnitudes, may
be approximated by their maximum, so max(logx) is an
approximation of the required logarithm. A more accurate
calculation can be done, for example, as follows

  maxlog + log(sum(exp(logx - maxlog)))
  # [1] 5675.977

Petr Savicky.