Author rhettinger
Recipients PedanticHacker, Stefan Pochmann, mark.dickinson, mcognetta, pablogsal, rhettinger, serhiy.storchaka, tim.peters
Date 2021-12-18.20:40:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1639860055.45.0.097167485904.issue37295@roundup.psfhosted.org>
In-reply-to
Content
For the small cases (say n < 50), we can get faster code by using a small (3Kb) table of factorial logarithms:

   double lf[50] = [log2(factorial(n)) for n in range(50)];

Then comb() and perm() function can be computed quickly and in constant time using the C99 math functions:

   result = PyLong_FromDouble(round(exp2(lf[n] - (lf[r] + lf[n-r]))));
History
Date User Action Args
2021-12-18 20:40:55rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, serhiy.storchaka, PedanticHacker, mcognetta, Stefan Pochmann, pablogsal
2021-12-18 20:40:55rhettingersetmessageid: <1639860055.45.0.097167485904.issue37295@roundup.psfhosted.org>
2021-12-18 20:40:55rhettingerlinkissue37295 messages
2021-12-18 20:40:55rhettingercreate