Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there any chance to write a faster GCD than the built-in one in Mathematica?

@Mr.Wizard has written one in this question (although it's not for this purpose) which is 6 times slower on a 100k digits:

In[1]:= whileGCD=Module[{a=#,b=#2},While[b!=0,{a,b}={b,Mod[a,b]}];a]&;
In[2]:= Primo[n_]:=Product[i,{i,Prime[Range[n]]}]

In[10]:= prod=Primo[500000];
In[17]:= m=22Primo[20500] +1;

In[16]:= Timing[GCD[m,prod]]
Out[16]= {0.25,1}

In[12]:= Timing[whileGCD[m,prod]]
Out[12]= {1.609,1}
share|improve this question
5  
The short answer is no. The longer answer is maybe, if you are a GMP developer with access to some fairly low level NTT (number theory transform) code. Even then it will be difficult. –  Daniel Lichtblau Jan 6 '13 at 20:49
1  
I don't have it installed at the moment so I cannot compare them but you may wish to try PARI/GP. I have found that to be much faster than Mathematica's built-in functions in at least one instance. –  Mr.Wizard Jan 12 '13 at 10:52
    
@Mr.Wizard I've tried it for Timing[GCD[100000! + 1, 1000000!]] and it is 9 times slower than Mathematica –  Mohsen Afshin Jan 12 '13 at 13:17
    
I'm actually happy to hear that, though of course that isn't any help to you. –  Mr.Wizard Jan 12 '13 at 13:26

1 Answer 1

Daniel Lichtblau answered this question in the comments

The short answer is no. The longer answer is maybe, if you are a GMP developer with access to some fairly low level NTT (number theory transform) code. Even then it will be difficult.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.