       Re: "Substract one and add one" algorithm

• To: mathgroup at smc.vnet.net
• Subject: [mg59098] Re: "Substract one and add one" algorithm
• Date: Thu, 28 Jul 2005 02:28:20 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 7/27/05 at 1:25 AM, gilmar.rodriguez at nwfwmd.state.fl.us (Gilmar)
wrote:

>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=n/2 -1 and q=n/2+1.

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

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

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

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

Here is a simple function which does what you described above

h[k_Integer] :=
Module[{p, q, f},
f[p_Integer, q_Integer] :=
If[PrimeQ[p] && PrimeQ[q], {p, q}, f[p - 1, q + 1]];
f[k/2, k/2]] /; k > 3 && EvenQ[k]
--
To reply via email subtract one hundred and four

```

• Prev by Date: Re: Simplification question
• Next by Date: Re: Freeware Mathematica packages(don't know the exact term)