Re: Need help with prime Test

*To*: mathgroup at smc.vnet.net*Subject*: [mg125046] Re: Need help with prime Test*From*: David Bailey <dave at removedbailey.co.uk>*Date*: Sun, 19 Feb 2012 06:32:31 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <jh6kd9$jsp$1@smc.vnet.net>

On 11/02/2012 20:51, KenR wrote: > I need to generate more "Ramsey" Numbers to further verify that only > prime numbers can meet the criteria. Ramsey numbers are those > generated from a simple criteria that is easy to check. I imported a > CSV list into my Mathematica version 8 to check all 30,759 numbers > that my Excel macro selected and they all turned out to be prime. That > is all that my program selected from all odd numbers from 3 to > 1,048,655, as large as my Excel program could test. I would further > test my program using my Mathematica software but I would like some > help to write the most efficient program to do the job. Right now, I > am trying to write a while loop inside a do loop but don't know how to > exit the loop before the counter becomes 0 in the case that it is > clear that P is not prime. > > The check is to do the following binary recursive sequence mod P and > check to see that the (P-1)/2 term is zero and no term prior to that > is zero. If so then I believe P should be prime based upon the results > so far. > > The test sequence is S(0) = 2, S(1) = 3, S(n) = 6*S(n-1) - S(n-2) - 6. > It appears that S((P-1)/2) is divisible by P then P is very likely > Prime, but I am interested in a test that is valid only for primes. > S((35-1)/2) is divisible by 35 but that is not the first term > divisible by 35. Only about 1/3 of the primes seem to meet the more > restricted criteria, i.e. the sequence has no term divisible by P > prior to S((P-1)/2). > > Using Do and While loops, tends to be frowned upon by some purists, but I think they are a good way to take a first stab at many problems. To exit a Do or While loop on some condition, use If[condition,Break[]]; If you want to exit multiple layers of loops, and/or function calls, use Catch/Throw. These are inefficient if used, but if you are going to execute them at most once, there is no problem. David Bailey http://www.dbaileyconsultancy.co.uk