MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

"Substract one and add one" algorithm

  • To: mathgroup at
  • Subject: [mg59041] "Substract one and add one" algorithm
  • From: "Gilmar" <gilmar.rodriguez at>
  • Date: Wed, 27 Jul 2005 01:25:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Dear Mathematica Users Forum Friends:

I want to build a function h[n] that does the following:

For n even greater and equal than 4:

Case 1: If m=n/2 is prime then h[n]={n/2,n/2}. Done.

Case 2: If m =n/2 is not prime; let p[1]=n/2 -1 and q[1]=n/2+1.

                    If both p[1], and q[1] are prime then,
                    h[n]={p[1],q[1]}. Done.

                    If either one or both p[1] and q[1] are not prime;
                    let p[2] =p[1]-1, and q[2]=q[1]+1.

                    If both p[2], and q[2] are prime then
                    h[n]={p[2],q[2]}. Done.

                    If either one or both p[2] and q[3] are not prime;
                    let p[3] =p[2]-1, and q[3]=q[2]+1.


I want to test empirically that a value h[n] = {p[k],q[k]}
(for an appropriate integer k) exists.

A few examples:

n/2=2 is prime; so h[4]={2,2}.

n/2=3 is prime; so h[6]={3,3}.

n=8 is not prime; so p[1]=n/2 -1 =3 is prime and q[1]=n/2+1=5 is prime;
                  so h[8]={3,5}.

n/2=5 is prime; so h[10]={5,5}.

n/2=6 is not prime; so p[1]=n/2-1=5 is prime and q[1]=n/2+1=7 is prime;
      so h[12]={5,7}.

n/2=7 is prime; so h[14]={7,7}.

n/2=8 is not prime;
      so p[1]=n/2-1=7 is prime but, q[1]=n/2+1=9 is not prime,
      so p[2]=7-1=6 is not prime, and q[2]=9+1=10 is not prime,
      so p[3]=6-1=5 is prime, and q[3]=10+1=11 is prime,
      so h[16]={5,11}.

Thank you for your help!

  • Prev by Date: Re: LatticeReduce problem
  • Next by Date: Re: LatticeReduce problem
  • Previous by thread: Re: Why won't Hornerwork?
  • Next by thread: Re: "Substract one and add one" algorithm