Devon McCormick wrote:
> 
> You're correct in terms of matching the pseudo-code but the original, less
> accurate version gives better results.  As shown below, the correct
> version
> gives a very skinny, hard to visualize, result whereas the original,
> mistaken, version gives a squarer result.
> 
To see better what's going up and to generalize these visualizations,
let's consider:

   distr=: i...@[ +/@:="0 1 (| p:@i.)

which gives us distribution of remainders modulo x of first y
primes:

   11 distr 1e6
1 99925 100000 100051 99994 100007 100082 99983 99905 100024 100028

   [d=:11 distr 1e7
1 999889 999978 999851 999836 1000114 1000025 1000170 1000216 1000065 999855

The key observation is that the distribution is nearly uniform, except for
the first 
number which is always 1 for y>10, because the only prime equal 0 mod 11 is
11 
(if there were another such number, it would have been divisible by 11).

Now we can assign displacements to each of the remaining 10 remainders.  
Since the distribution is about uniform, it is sufficient to choose an equal
number 
of displacements along + and - direction of each axis in d-dimensional space 
in which we'd like to move point, in order to get total displacement (drift) 
near zero.   That, with counting how many times each point was visited, 
should be sufficient to get various similarly nebulous pictures of prime
numbers.
For example, in d=2, choosing

    dr=: 0 0,0 _1,0 0,1 0,0 0,0 0,0 1,0 0,_1 0,0 0,:0 0

gives us total drift:
   +/ dr *"1 0 d
_365 136

and thus about "square" picture.   The choice from the pseudo-code gives:

   DR=: 0 0, 0 1, 0 _1, 1 0, _1 0, 0 1, 0 0, 0 0, 0 0, 0 0,: 0 0
   +/ DR *"1 0 d
15 1000025

So there is an upward drift and more of a "rectangular" picture.  
Similarly, your choice has a drift of 15 _89, etc.

Another class of pictures we get if we choose displacements of
larger numbers of remainders to be nonzero, for instance:

    Dr=: 0 0,0 _1,0 1,1 0,_1 0,_1 0,0 1,0 0,_1 0,0 0,:0 _1
    +/ Dr *"1 0 d
117 259

Although the drift is small, we should get a more diffuse picture because 
there is a greater likelihood of motion along one of the four directions.

We can also choose 2n nonzero displacements along one axis and 
2m>2n nonzero displacements along another, again with small drift, 
and should expect nonisotropic (i.e more diffuse along the latter axis) 
pictures.

Finally, why choose unit displacements along axes at all instead of
more general displacements with approx. zero drift?

Generalizations to other primes and/or larger numbers of dimensions
are straightforward, i.e:

   13 distr 1e7
1 833304 833092 833218 833285 833651 833725 833387 833360 833312 833221
833372 833072



> This makes me even more wary of pseudo-code.
> 
> NB. With spec matching pseudo-code:
>    DR=: 0 0, 0 1, 0 _1, 1 0, _1 0, 0 1, 0 0, 0 0, 0 0, 0 0,: 0 0
>    primenebulaP 1e6
> 247 x 99935
> 
> NB. Original, not matching pseudo-code:
>    DR=: 0 0, 0 1, 0 _1, 1 0, _1 0, 0 0, 0 0, 0 0, 0 0, 0 0,: 0 0
>    primenebulaP 1e6
> 247 x 224
> 
> NB. Where
> 
> primenebulaP=: 3 : 0
>  d=. ({.,#)/.~+/\ {&DR 11|p: i.y       NB. scan left +/ on movement steps
> NB. normalize coordinates to upper right quadrant and calculate size
>  'gx gy '=. >: >./ XY=.(2{."1 d) -"1 {.~&2 <./ d
>  smoutput (": gx),' x ', ": gy         NB. show picture size
>  viewmat (2{"1 d) (<"1 XY) } 0$~ gx, gy
> )
> 
> 
> On Thu, Jan 7, 2010 at 4:31 PM, Viktor Cerovski
> <[email protected]>wrote:
> 
>> ...
>> For x=5, it should go up, ie:
>>
>> dr=: 0 0, 0 1, 0 _1, 1 0, _1 0, 0 1, 0 0, 0 0, 0 0, 0 0,: 0 0
>> ...
>>
> 
> 
> 
> -- 
> Devon McCormick, CFA
> ^me^ at acm.
> org is my
> preferred e-mail
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Prime-number-nebula-tp27062900s24193p27069420.html
Sent from the J Chat mailing list archive at Nabble.com.

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

Reply via email to