Open trizen opened 2 years ago
Good idea. I'm thinking for internal use I'll make a trial factor iterator. We're using pre-computed gcds up to 32k to do quick tests, but it's kind of a mess actually doing the trial division efficiently. Factor trees are used later.
I'll have to look at the different use cases and see what I can do. Nice algorithm, should be more efficient to use once past the small gcds.
Ah, I was thinking of the ECPP code which used gcds. That idea got put into the main factoring code only a few weeks ago (in response to another issue you pointed out).
Current code:
$ time perl -Iblib/lib -Iblib/arch ~/tmp/g27-1.pl
Length of n = 16875
bigomega(n) = 4175
Factorization took 0.405609 seconds.
Your code:
$ time perl -Iblib/lib -Iblib/arch ~/tmp/g27-2.pl
Length of n = 16875
remainder = 1
bigomega(n) = 4175
Factorization took 0.037066 seconds.
A big improvement over what it was before, but it ends trial factoring quickly. Simply expanding it to 64k gives:
$ make >/dev/null && time perl -Iblib/lib -Iblib/arch ~/tmp/g27-1.pl
Length of n = 16875
bigomega(n) = 4175
Factorization took 0.033636 seconds.
But I'm sure I could construct examples that would want better factoring after that. I also think there is some micro-improvements to be made in the trial factoring using the gcd result. I'll have to do more testing.
Hi Dana.
I noticed that the prime factorization of large integers that have many small prime factors seems to be quite slow, but I think we can do better.
Example:
Output:
The same factorization in PARI/GP takes only ~40ms:
As a solution, I propose the following adaptive trial-division algorithm, which efficiently finds small prime factors of
n
, and it also stops early whenn
no longer has small prime factors:Output: