Factoring stalls on certain inputs
See original GitHub issueAs discovered in #185, factoring 2^256 - 1
stalls out which prevents testing if degree-256 polynomials over GF(2)
are primitive. This would likely (?) be fixed once the quadratic sieve (#146) is added.
In [1]: import galois
# Takes forever... and may never return?
In [2]: galois.factors(2**256 - 1)
^C---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-3-6806de99fcaa> in <module>
----> 1 galois.factors(2**256 - 1)
~/repos/galois/galois/_polymorphic.py in factors(value)
514 """
515 if isinstance(value, (int, np.integer)):
--> 516 return integer_factor.factors(value)
517 elif isinstance(value, Poly):
518 return poly_factor.factors(value)
~/repos/galois/galois/_factor.py in factors(n)
250 # Step 4
251 while n > 1 and not is_prime(n):
--> 252 f = pollard_rho(n) # A non-trivial factor
253 while f is None:
254 # Try again with a different random function f(x)
~/repos/galois/galois/_factor.py in pollard_rho(n, c)
571 a = f(a)
572 b = f(f(b))
--> 573 d = math.gcd(a - b, n)
574
575 if d == n:
KeyboardInterrupt:
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
factoring - If there is an algorithm A can calculate the modular ...
Suppose you are given an algorithm A which takes y∈{0,1,…,N−1} as input, and outputs x∈{0,1,…,N−1} such that x2≡y(modN). Design an ...
Read more >Issues · mhostetter/galois - GitHub
A performant NumPy extension for Galois fields and their applications - Issues · mhostetter/galois.
Read more >Do Freight Brokers Use Factoring Companies? - Customodal
Do freight brokers use factoring companies? Yes. Freight brokers who use factoring companies are able to pay their carriers right away.
Read more >Torque Converter Fluid Coupling: Tell Me Something I Don't ...
To define this general equation, let's say your engine creates 500 ft-lb of torque at your converter stall of 4,000 RPM. The square...
Read more >c# - Input an Integer and get its prime factors and duplicates
The basic algorithm for integer factorization using trial division tries ... The loop stops when f is greater than the square root of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Apologies if all of this is obvious to you or already known/considered. I got here specifically because I really liked this project and was playing with larger
GF(2**n)
fields.It looks like
2**256-1
factorization as implemented currently gets to the point where it needs to factorize340282366920938463463374607431768211457==2**128+1
which is59649589127497217 * 5704689200685129054721
. Unfortunately, it looks like Pollard’s rho algorithm is getting much more than usual time for this number for offsetc=1
(not sure why - square root of the smallest factor is ~24M but it seems that it takes around 455M steps for Pollard’s rho to find the factor). That said runningpollard_rho
withc=3
finds the factor after 19M iterations which is close to regular working times of Pollard’s rho.I only see 2 things can be done:
p**n-1
factorizations hardcoded (or in a sqlite db similar toconway_polys.db
). A reasonable trick would be to introduce a hardcoded list of primes to check as factors where the list specifically contains large-ish primes that are known factors of2**n-1
withn
up to some value (maybep**n-1
for otherp
too).For the 1st approach there seems to be some very interesting public materials regarding mersenne numbers factorizations such as Factorization tables from Cunningham book.
I got a bit confused at first with the book only containing
2**n-1
factorization for odd values ofn
, but that turned out to be just because otherwise2**(2k)-1 = (2**k-1) * (2**k +1)
and there is a separate section of the book for the2**n+1
factorization wheren=4k
. E.g. you can find 59649589127497217 there in factorization of2**128+1
.So if just prime factors from
2**n-1
and2**n+1
factorizations (tables called2-
and2+
) are taken from the book and saved aside to be checked e.g. after all factors under 10M and before running more advanced algorithms this should be enough to factorize2**n-1
for some highern
numbers.More about the notations they are using and such here. There are some things that are not very convenient (e.g. P40 meaning 40-digit prime number without specifying it, and C200 for not-factored number). The primes hidden under
P40
notation are present in separate tables it seems, but they would not be necessarily needed here.I’m closing this. This will now be tracked in the consolidated #456.