Thread: Ramsey Primes
View Single Post
ramsey2879
ramsey2879 is offline
#4
Feb15-12, 09:20 AM
P: 891

Ramsey Primes


Quote Quote by ramsey2879 View Post
My code for Mathematical is short so I will include it below for reference. There are some flaws. For instance the Reap/Sow function generates a list of the form {Null,{{prime3,prime5,prime6,prime8,...}}}. I want to generate a simple list {prime3,prime5,prime6,prime8...}. Also, the code took about an hour to pick out 31 primes between 1049000 and 1050000. Overall, about 2/3 of the prime numbers are not picked out, but that is what I am looking for code that will generate only primes, not code that will generate all primes but also include some composites. So far some 30,000 prime numbers between 5 and 1050000 were generated with no false hits. Any help improving my code will be appreciated.
Caa = 5
Reap[While[Caa < 1050001,
Co = 1;
S0 = 2;
S1 = 3;

While[Co < ((Caa-1)/2),Temp = Mod[6 S1 - S0 - 6,Caa];If[Temp <= 1,Break[]];
S0=S1;S1=Temp;Co++];
n = ((Caa-1)/2) - Co; If[n<2,If[n>0, Sow[Caa]]];
Caa++;Caa++]]
The code was used to find 31083 primes between 3 and 1061001, no composites were picked. one problem with the code is that it requires a recursive formula to determine S((P-1)/2) Mod P so I did some manipulation to find a equivalent test that doesn't require recursion to find S((p-1)/2):

2,3,10,51 is of the Form S(n) = 6S(n-1)- S(n-2) - K K = 6 and Test is S((P-1)/2) = 0, Mod P etc
1,2,9,50 is of the Form S(n) = 6S(n-1) - S(n-2) - K K = 2 and Test is S((P-1)/2) = -1, Mod P etc

Subtracting 1 from each term reduced K by 4
Doubling each term multiplies K by 2, i.e.:
2,4,18,100 is of the Form 6S(n-1) - S(n-2) - K K = 4 and Test is S((p-1)/2 = -2, Mod P, etc
Subtracting 1 from each term again reduces K by 4 i.e. to 0,:
1,3,17,99 is of the Form 6S(n-1) - S(n-2) K = 0 Test is S((P-1)/2) = -3, Mod P, etc.
Thus a direct formula exists for S((P-1)/2)