drab wrote:Answering your question of Mon Oct 20, 2014 5:35 pm ...

This is my defined function to quickly build a sequence of N primes:

z←ps n;p

z←0⍴p←1

go:→(n≤⍴z)/0

z←z,p←1πp

→go

It works the same as ¯2π:

ps 9

2 3 5 7 11 13 17 19 23

¯2π⍳9

2 3 5 7 11 13 17 19 23

Defined operators t1 and t2 just run their functions, and return how long it took.

The time for function ps is fairly linear wrt the size of N:

ps t1 99

0.001125065901

ps t1 999

0.01211279636

ps t1 9999

0.2419504361

But the time for ¯2π is not linear at all:

¯2π t2 ⍳99

0.001940112212

¯2π t2 ⍳999

0.3270593882

¯2π t2 ⍳9999

47.22952671

Thanks for the heads up. When I originally implemented this function, I borrowed an idea from Roger Hui of Dyalog which is to rely upon a table of results for every

N values where

N is

1E5. The top end of the table is such that

N is the largest number such that it is a multiple of

1E5 and that

¯2πN returns a number just below

2*32; that

N is

203200000. To find an answer, first do a binary search of the table finding the multiples of

1E5 which are the upper and lower limits of a range of

1E5 values, then compare

N with the midpoint of the upper and lower values and either search forwards from the lower value or backwards from the upper value using

1π (Next Prime) or

¯1π (Previous Prime), respectively.

Because the increment (

1E5) is so large, this means that the table is designed for large arguments, not small ones, so it's no surprise that it performs poorly for numbers

< 1E5. On the other hand, it works quite well for numbers as large as

2E8.

In any case, I've introduced two new tables for the range of

N in

[0, 1E2] by

1s, and

[0, 1E5] by

100s. This should allow

¯2πN to produce results on small arguments quite quickly.

This enhancement is available in the latest beta version.

http://www.nars2000.org/download/binaries/beta/