[Date Index]
[Thread Index]
[Author Index]
Looking for a "smart" index for a Do-loop (Revised!)
*To*: mathgroup at smc.vnet.net
*Subject*: [mg50331] Looking for a "smart" index for a Do-loop (Revised!)
*From*: gilmar.rodriguez at nwfwmd.state.fl.us (Gilmar Rodr?guez Pierluissi)
*Date*: Fri, 27 Aug 2004 02:57:54 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
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!
Prev by Date:
**Re: Is a For loop always a no-no?**
Next by Date:
**Re: Re: Publicon problems converting sample document to LaTeX**
Previous by thread:
**Re: An entropy measure of rational number fractal dimension: d=0.3732201657487591656832916543359**
Next by thread:
**Re: Looking for a "smart" index for a Do-loop (Revised!)**
| |