3 and 7 are primes, and (3+7)%2 is 5 which is a prime too. But 3 and 7 are not 
consecutive primes, because there is a prime between 3 and 7, namely 5. So if  
p  <  q  and  p  is prime and  q  is prime and r= (p+q)%2 is prime too, then p 
< r and r < q, and so p and q are not consecutive primes. QED.  There is no 
need for induction. 





>________________________________
> Fra: Roger Hui <rogerhui.can...@gmail.com>
>Til: Programming forum <programm...@jsoftware.com> 
>Sendt: 4:01 mandag den 13. maj 2013
>Emne: Re: [Jprogramming] Testing consecutive pairs of primes
> 
>
>Henry has already argued that if p and q are consecutive primes then
>(p+q)%2 can not be prime.  I just want to say that reasoning of the sort:
>
>While it might be possible for the larger primes, I'm thinking not - just
>by induction.
>
>
>On Sun, May 12, 2013 at 3:07 AM, Alan Stebbens <a...@stebbens.org> wrote:
>
>> ProgrammingPraxis (at http://programmingpraxis.com/2013/05/10/mindcipher)
>> offered a problem asking, given p, q as two consecutive pairs of primes, if
>> (p+2)%2 could be prime.
>>
>> Since both p & q (> 2) are prime, their sum is an even number and not
>> prime, but could the half of their sum be a prime?
>>
>> I'm not much of a mathematician, but I figured I could brute-force an
>> approximation with J.
>>
>> The gist below is my experiment showing that the answer is no, for the
>> consecutive pairs of primes in the set of the first million primes.  While
>> it might be possible for the larger primes, I'm thinking not - just by
>> induction.
>>
>> Probably some of you could show a proof, but it was more fun for me to
>> cobble up this in J, and also demonstrate J to the non-J audience at
>> Programming Praxis (which has been mostly scheme, Haskell, python, ruby).
>>
>> https://gist.github.com/aks/5563008
>>
>> Here's my experiment:
>>
>>    i. 20
>> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
>>
>>    NB. generate the first 20 primes
>>    p: i. 20
>> 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
>>
>>    NB. box up consecutive pairs of those primes
>>    (2 <\ ]) p: i. 20
>>
>> ┌───┬───┬───┬────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
>> │2 3│3 5│5 7│7 11│11 13│13 17│17 19│19 23│23 29│29 31│31 37│37 41│41 43│43
>> 47│47 53│53 59│59 61│61 67│67 71│
>>
>> └───┴───┴───┴────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
>>
>>    NB. sum up each pair of primes
>>    +/ each (2 <\ ])p: i. 20
>> ┌─┬─┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┐
>> │5│8│12│18│24│30│36│42│52│60│68│78│84│90│100│112│120│128│138│
>> └─┴─┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┘
>>
>>    NB. divide each sum by 2
>>    2 %~ each +/ each (2 <\ ])p: i.
>> 20
>>
>> ┌───┬─┬─┬─┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
>> │2.5│4│6│9│12│15│18│21│26│30│34│39│42│45│50│56│60│64│69│
>> └───┴─┴─┴─┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘
>>
>>    NB. now, test each of those results for being prime.  1 p: y -- tests y
>> for being prime
>>
>>    1&p: each 2 %~ each +/ each (2 <\ ])p: i.
>> 20
>>
>> ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
>> │0│0│0│0│0│0│0│0│0│0│0│0│0│0│0│0│0│0│0│
>> └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
>>
>>    NB. open the boxed results, so we can add them up
>>    >1&p: each 2 %~ each +/ each (2 <\ ])p: i. 20
>> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>>
>>    NB. sum/reduce the vector of booleans.  If there's a prime, the sum will
>> be > 0
>>    +/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 20
>> 0
>>
>>    NB. ok. No primes.  Let's keep checking for larger groups
>>
>>    +/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 1000
>> 0
>>    +/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 10000
>> 0
>>    +/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 100000
>> 0
>>
>>    NB. the previous output took a few seconds.  The next will take a few
>> minutes
>>
>>    +/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 1000000
>> 0
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>----------------------------------------------------------------------
>For information about J forums see http://www.jsoftware.com/forums.htm
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to