Closed tthsqe12 closed 2 years ago
Nice! Want me to figure out the cutoffs for using it?
Sure, but unfortunately its complexity has completely different characteristcs from the Euclidean algorithm. If Euclid does just a few iterations, it will be hard to beat that.
So for huge numbers, you'd want a version of the Euclidean algorithm that quits after a few iterations?
After some quick testing, your algorithm seems to win pretty consistently for balanced GCDs above 64 bits. (So perhaps a 2-limb Euclidean (or binary) GCD would be useful.)
However, your algorithm seems to perform much worse than the Euclidean one for highly unbalanced operands. For example, it is slower for gcd(10^6 bits, 10^5 bits).
I think instead of changing your algorithm, the main fmpzi_gcd function could just check if the operands are unbalanced, then do a single divrem or divrem_approx before dispatching to the right algorithm. Does that make sense?
For the first question, probably "no" because the second question is probably "yes": do some divisions until the operands are balanced.
Ideally you would want a quasi-linear algorithm that deals directly with the quotient sequence, but that is a lot of work, so this is a compromise.
Sure.
This is the nemo version