Re: Looking for a "smart" index for a Do-loop (Revised!)

*To*: mathgroup at smc.vnet.net*Subject*: [mg50343] Re: [mg50331] Looking for a "smart" index for a Do-loop (Revised!)*From*: DrBob <drbob at bigfoot.com>*Date*: Sat, 28 Aug 2004 04:37:55 -0400 (EDT)*References*: <200408270657.CAA00744@smc.vnet.net>*Reply-to*: drbob at bigfoot.com*Sender*: owner-wri-mathgroup at wolfram.com

Try: Clear@MGPPP MGPPP[n_?EvenQ]/;n>8:=Block[{p,q},Do[If[PrimeQ[ q=(n-(p=Prime[i]))],Return[{ p,q}]],{i,PrimePi[n/2],PrimePi[Ceiling[Sqrt[n]]],-1}] ] MGPPP[n_?EvenQ]:=Block[{p,q},Do[If[PrimeQ[q=(n-(p=Prime[i]))],Return[{p, q}]],{i,PrimePi[n/2],1,-1}] ] MGPPP/@Range[4,60,2] {{2,2},{3,3},{3,5},{5,5},{5,7},{7,7},{5,11},{7,11},{7,13},{11, 11},{11,13},{13,13},{11,17},{13,17},{13, 19},{17,17},{17,19},{19,19},{17,23},{19,23},{13,31},{23,23},{19,29},{ 19,31},{23,29},{23,31},{19,37},{29,29},{29,31}} or Clear@MGPPP MGPPP[n_?EvenQ]/;n>8:=Block[{p,q},Do[If[PrimeQ[ q=(n-(p=Prime[i]))],Return[{ p,q}]],{i,PrimePi[n/2],PrimePi[Ceiling[Sqrt[n]]],-1}] ] MGPPP[4]={2,2}; MGPPP[6]={3,3}; MGPPP[8]={3,5}; MGPPP/@Range[4,60,2] {{2,2},{3,3},{3,5},{5,5},{5,7},{7,7},{5,11},{7,11},{7,13},{11, 11},{11,13},{13,13},{11,17},{13,17},{13, 19},{17,17},{17,19},{19,19},{17,23},{19,23},{13,31},{23,23},{19,29},{ 19,31},{23,29},{23,31},{19,37},{29,29},{29,31}} Bobby On Fri, 27 Aug 2004 02:57:54 -0400 (EDT), Gilmar Rodr?guez Pierluissi <gilmar.rodriguez at nwfwmd.state.fl.us> wrote: > Dear Mathematica Group: > > The following program is used to calculate the Minimal Goldbach > Prime Partition Points corresponding to an even number n >= 4: > > MGPPP[n_] := Block[{p, q}, > Do[If[PrimeQ[q = (n - (p = > Prime[i]))], Return[{p, q}]], {i, PrimePi[n/2], 1, -1}]] > > To visualize these points try: > > ListPlot[Table[MGPPP[n], {n, 4, 100, 2}], PlotJoined -> True] > > Notice that the index i starts at the value PrimePi[n/2]. Next, 1 is > sustracted from PrimePi[n/2] (as long as q = n- Prime[i] is not > prime), > with i (possibly) reaching the value 1. > > Now, I'm attempting to reduce the number of iterations of my index i, > to make my program faster. > Let K = PrimePi[n/2], and L = PrimePi[Ceiling[Sqrt[n]]]. > Rather than {i, K, 1, -1}, I want to use {i, K, L, -1} in the above > "Do-loop". > The value PrimePi[Ceiling[Sqrt[n]]] takes advantage of the so called > "Knjzek p lower bound". > > To visualize the geometry involved, please visit: > > http://gilmarlily.netfirms.com/goldbach/knjzekbands.htm > > The program takes the primes between Prime[PrimePi[n/2]] and > Prime[PrimePi[Ceiling[Sqrt[n]]]] and looks for the first instance in > which > (n - Prime[i]) is prime for i = K, K-1, K-2, ..., perhaps up to L. > When the program finds (n - Prime[i]) prime, it stops and returns > MGPPP[n]. > > The problem with attempting: > > MGPPP[n_] := Block[{p, q}, > Do[If[PrimeQ[q = (n - (p = > Prime[i]))], Return[{p, q}]], {i, K, L, -1}]]] > > is that the do-loop will not work for 4 <=n <= 8. Keep in mind that i > assumes values K, K-1, ...., until reaching L. > The program works for n > 8 though, since for these n's, K is large > enough to loop its way to L. To see this try: > > Table[{n,PrimePi[Ceiling[Sqrt[n]]],PrimePi[n/2]},{n, > 4,300,2}]//TableForm > > and: > > Table[{n,Prime[PrimePi[Ceiling[Sqrt[n]]]],Prime[PrimePi[n/2]]},{n, > 4,300,2}]//TableForm > > I would like to modify the above program to do something like this: > > MGPPP[n_] := Module[{p, q}, > {m = n/2; If[Element[m, > Primes], {p = m, q = m}, {K = > PrimePi[m], If[Element[n], {4, 6, 8}], L = 1, L = > PrimePi[Ceiling[Sqrt[ > n]]]; Do[If[Element[n - Prime[ > i], Primes], hit = i; Break[]], {i, K, L, -1}], p = Prime[ > hit], q = n - p}]}; {p, q}] > > In other words; if 4 <=n <= 8 the lower index L becomes 1, if not > (i.e. n > 8) > L = PrimePi[Ceiling[Sqrt[n]]]. I'm looking for a "smart" index for > my Do-loop, but > any other approach to make this program work (using L) is definitely > welcomed! > > Thank you for your help! > > > -- DrBob at bigfoot.com www.eclecticdreams.net

**References**:**Looking for a "smart" index for a Do-loop (Revised!)***From:*gilmar.rodriguez@nwfwmd.state.fl.us (Gilmar Rodr?guez Pierluissi)