If you are looking for a way around the overflow / deficiency problem you have, you can use the logs (to maintain acceptable values ββfor intermediate calculations) and then increase them at the end:
options(digits=20) for(k in 0:r){ sum = sum + (1 - exp(lchoose(2^k, n) + log(factorial(n)) - k*n*log(2))) print(paste0(k,": ",sum)) } [1] "0: 1" [1] "1: 2" [1] "2: 3" ... [1] "19: 11.7217600143979" [1] "20: 11.7230238079842" [1] "21: 11.7236558993777"
To make sure this is correct, I performed the initial summation (excluding journals) in Mathematica and got the same results up to 12 decimal places.
Although you can make the problem in R if you want to go with a computer algebra system (which allows you to do symbolic mathematical calculations and exact calculations), Sage is free and open source.
source share