Fast Factorial Algorithms
27 points
3 days ago
| 5 comments
| luschny.de
| HN
ipeev
2 hours ago
[-]
A cached map will do best if you actualy need a fast factorial. There are very little entries before the numbers become pointlessly big.
reply
smokel
4 hours ago
[-]
I hoped this would help me solve some more Project Euler [1] problems. Unfortunately, the algorithms given are not explained in detail, so the learning experience is somewhat mediocre. Then again, I have ChatGPT to elucidate them for me.

This article [2] has some interesting details on the swinging factorial function n≀, but I can't seem to find the essay that it references: "Swing, divide and conquer the factorial", 2008.

[1] https://projecteuler.net/

[2] https://oeis.org/A000142/a000142.pdf

reply
mjevans
32 minutes ago
[-]
My approach to the first 100 Euler eventually involved a bitmap of possible primes (only odd numbers, there's only one even prime) which was initially seeded by a 'magic number' set representing the lowest primes and would grow up to a target number of cached small / really fast primes.

Then the algorithms I understand less kick in. Most of those involve some form of modo math to wrap the number space based on one or more origami like folds and use well known and test algorithms which were previously exhaustively proven to cover the entire 32 bit number-space when utilized in a composite fashion.

reply
zamadatix
3 hours ago
[-]
To all commenting about the Sitrling formula, there is a separate page linked at the end for approximations http://www.luschny.de/math/factorial/approx/SimpleCases.html which contains many advanced options to compare for that.
reply
imglorp
7 minutes ago
[-]
I've always wondered if Stirling(n) can be used to arrive quickly in the vicinity of n!, and then use a search of some kind to get to the exact target.
reply
looneysquash
1 hour ago
[-]
I wonder if any compiler can rewrite that last one into one of the others.
reply
dvh
4 hours ago
[-]
No Stirling formula?
reply
Aardwolf
2 hours ago
[-]
That one is an approximation rather than returning all millions of exact big integer digits though (the approximation is more useful for real life statistics etc..., but doesn't look like what this article is targeting)
reply