Alan

>when i first read your note i reinterpreted it as the prime ness of half of 
>the midpoint of prime pairs (ie off by two from each other)... i suppose this 
>is a made up question which i am guilty of providing exploratory functions for:

ps=: p:@i.  NB. primes
pp=: ((2&+) = (1&|.))   NB. prime pair?
pq=:1&p:    NB. prime?
   ek=: </.    NB. enclose key
   dl=: >@{:   NB. disclose last
pip=:(>@{:) @(pp </. ])@ps
   hi=: -:@>:  NB. halve inc
hpp=: >@}:@(pq ek ]) @ (-:@>:@pip)  NB. half primes of pairs

NB. this works responsively on my machine for up to
   hpp 1e7
2 3

NB. hpp 1e8 gives the same slowly ,and hpp 1e9 gives out of memory
NB. Except for the first two pairs, it appears that none work...

greg
~krsnadas.org

--

from: R.E. Boss <[email protected]>
to: [email protected]
date: 12 May 2013 08:56
subject: Re: [Jprogramming] Testing consecutive pairs of primes

All the boxing is unnecessary.
Here is  the performance you win (j801):

     ts'+/>1&p: each 2 %~ each +/ each (2 <\ ])p: i. 1000000'
6.4344903 1.8283457e9

   ts' +/1 p:2%~ 2 +/\ p: i. 1000000'
0.38894168 1.9701402e8

Rule of thumb: don't box items of same shape.

R.E. Boss
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to