Download Title of the Paper (18pt Times New Roman, Bold)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Addition wikipedia , lookup

Fractal wikipedia , lookup

Elementary mathematics wikipedia , lookup

Algorithm wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Factorization of polynomials over finite fields wikipedia , lookup

Quadratic reciprocity wikipedia , lookup

List of prime numbers wikipedia , lookup

Transcript
Some Computation Remarks on Prime Number Fractals
SABIN TABIRCA
TATIANA TABIRCA1 JOHN MORRISON
Department of Computer Science, BCRI
National University of Ireland, Cork
College Road, Cork
IRELAND
KIERAN REYNOLDS
Abstract: - This paper presents some recent development on Prime Number Fractals. Firstly, it is proved that
the number of up, down, left or right moves is asymptotically equal to li (n) / 4 . This result explains the central
area of intense brightness and some less detailed areas around the borders. A new PNF algorithm is introduced
so that more border pixels contain colour details. Finally, we will present how parallel computation can be
used to generate more prime numbers.
Key-Words: - Prime numbers, fractals, parallel computation.
1 Introduction
Prime numbers have represented a very interesting
challenge for the last few centuries and all the
important results concerning them have had a huge
impact in Mathematics. In particular Number
Theory has come a long way from the Euclid proof
of the infinity of the prime numbers to the proof of
P-completeness of primality testing. The quest of
finding curious patterns or representations on prime
numbers has always fascinated both mathematicians
and computer scientists. Perhaps, graphical
representations have represented the most attractive
way to highlight curious facts on prime numbers.
The Ulam spiral is perhaps the first graphical
representation of primes [6],[7]. The numbers
1, 2,..., n 2 are written within a square in a spiral
order with 1 in the centre and the primes are
highlighted then diagonal patters appear in the
representation. Of course, there have not been any
proofs of these patterns but the bigger the square is
the more visible they are. The simplicity of this
construction has given less space for new
interpretations or generalizations for more than 4
decades.
Only recently, a new graphical representation has
been proposed and that is called “Prime Number
Fractals”. As with any simple fact there has been
much mathematics folklore around it since there was
not a formal article to propose the construction.
Most mathematicians have recognized that Adrian
Leatherland from Monash University in Australia
has constructed the first prime number fractal [3].
We should also acknowledge the work of A. Turpel
in The Aesthetics of Prime Sequence [9].
1
In this article we introduce a generalization of the
algorithm to generate Prime Number Fractals. We
also present some efficient methods to generate the
prime numbers needed in the algorithm.
procedure fractal(n, w, h, colour)
begin
generate_primes(n, m, p);
x=w/2;y=h/2;
for i=0 to m-1 do begin
dir=p[i] mod 5;
if dir=1 then y=y-1 mod h;
if dir=2 then y=y+1 mod h;
if dir=3 then x=x-1 mod w;
if dir=1 then x=x+1 mod w;
colour[x][y]++;
end;
end;
Figure 1. The Algorithm to Generate PNF.
2
PNF Algorithm
The algorithm to generate Prime Number Fractals is
one of the simplest methods in Number Theory.
Suppose that the fractal sizes are w and h for the
width and height, respectively so that the fractal is
given by w h pixels. At any time when a pixel is
visited the pixel colour increments. If we have a
prime number p then p mod 5  {1,2,3,4} so that we
can match the result p mod 5 with the four
directions up, down, left and right as follows:
1. p mod 5 1  (x,y) goes to (x,y-1)
2. p mod 5  2  (x,y) goes to (x,y+1)
Supported by Boole Centre for Research in Informatics.
3.
4.
p mod 5  3  (x,y) goes to (x-1,y)
p mod 5  4  (x,y) goes to (x+1,y)
If we start from all the prime numbers
p0  2, p1  3,..., pm 1 less than a number n we will
obtain a sequence of moves up, down, left and right
to visit the fractal pixels. In this way the pixel
colours change. A description of this method is
shown in Figure 1.
The procedure generate_primes(n, m, p) generates
all the prime numbers p0  2, p1  3,..., pm 1 less
than n. The Prime Number theorem gives that
n
m  O(
) . The Erathostenes’ sieve provides an
log n
O(n  log log n) computation and that is recognized
to be the most efficient algorithm to generate these
primes [2]. The method stores all the numbers less
than n into an array and removes successively all the
multiples of 3, 5, 7, etc. The numbers left in the
array represent all the primes we want to find. The
major drawback of this method is the internal
memory might not be enough to store all the
numbers we want to work with. Note that some
programming languages e.g. C or C++ can allocate
sufficient space to generate up to hundreds of
millions primes.
images are similar to the whole image so that they
satisfy fractal self-similarity.
 5,1 ( x)
 5,2 ( x)
 5,3 ( x)
 5,4 ( x)
1,000,000
19,618
5,000,000
87,063
10,000,000
166,105
19,622
87,179
166,212
19,665
87,216
166,230
10,593
87,055
166,032
Table 1. Distribution of up, down, left, right moves.
PNF images as presented in [3] or [9] are all very
similar. They have a central area of intense
brightness and little details on the borders. This has
a simple explanation. The first few prime numbers
do not have a uniform distribution of p mod 5 .
After that the distribution becomes uniform but
random so that the walk through the image always
hits central pixels (see Table 1 and Figure 3). This
has a very sensitive mathematical explanation
shown by Theorem 1.
180,000
160,000
140,000
120,000
up
100,000
down
80,000
left
60,000
right
40,000
20,000
0
1,000,000
5,000,000
10,000,000
Figure 3. Distribution of up, down, left, right moves.
Theorem 1. The numbers of up, down, left and right
moves in the PNF algorithm are asymptotically
equal.
Figure 2. PNF Fractal Using 500,000,000 primes.
The result of this algorithm is an image of coloured
pixels. This image, shown in Figure 2 can describe a
distant astronomical object like a nebula or galaxy
of stars. It can also suggest a fireball from an
explosion. Marek Wolf, who has also detected some
connections between prime number distribution and
fractality has pointed out the PNF images are fractal
[11], [12]. A simple explanation can be that the
generation algorithm gives a kind of random walk
through the pixels. It is observable that parts of PNF
Proof. Diriclet’s theorem assures if (a, b)  1 then
there are an infinity of primes in the set
{a  k  b, k  0} . This means that the random walk
has an infinity of up, down, left, right moves. If
 a,b ( x) denotes the number of primes of the form
a  k  b less than x then we know from a very
recent result of Weisstein that
 a ,b ( x )
1
,
(1)

li ( x)
 (a)
x 
lim
where li (x) is the logarithmic integral function and
 (a) the Euler totien function [13]. This gives that
 5,1 ( x)
 5, 2 ( x )


li ( x)
x   li ( x)
x 
 5, 3 ( x )
 5, 4 ( x )
1
1
(2)




li ( x)
li ( x)
 (5) 4
x 
x 
which means that
lim
lim
lim
lim
li( x)
 5,1 ( x)   5,2 ( x)   5,3 ( x)   5,4 ( x) 
.
4
(3)
Equation (3) shows that the algorithm has
asymptotically the same number of up, down, left,
right moves.
▄
If the starting point of the random walk is the pixel
from the image centre. The PNF algorithm executes
the same number of up, down, left, right moves but
in a random fashion. Therefore, the central pixels
are more likely to be reached than the border pixels.
3 Generalised PNF Algorithm
We have seen that PNF images have less-details
around the borders and the brightness is
accumulated in the central area. The idea of this
algorithm is to keep the directions up, down, left,
right for a move but to jump more than one pixel. In
this way, jumping more than one pixel, more border
pixels might be reached.
2k  1  p mod q  3k  jump left over
p mod q  2k pixels.
4. 3k  1  p mod q  4k  jump right over
p mod q  3k pixels.
Figure 5 presents the detailed description of this new
algorithm.
3.
Equation (2) assures us that all these q  1  4  k
moves occur in a similar number. Moreover, the
border pixels are reached more often since the
moves jump more than one pixels. Figure 4
illustrates the generalized PNF fractal using modulo
q  13 . In this case we can jump 1, 2 or 3 pixels for
each direction. It can be seen that brightness on the
pixels has been spread towards the borders.
procedure fractal(q, n, w, h, colour)
begin
generate_primes(n, m, p);
x=w/2; y=h/2; k=(q-1)/4;
for i=0 to m-1 do begin
dir=p[i] mod q;
if 1≤dir≤k then y=y-dir;
if k+1≤dir≤2k then y=y+dir-k;
if 2k+1≤dir≤3k then x=x-dir+2k;
if 3k+1≤dir≤4k then x=x+dir-3k;
colour[x][y]++;
end;
end;
Figure 5. Generalised Algorithm for PNF.
4 A Parallel Approach
It is clear that the more prime numbers used in this
computation the more details PNF images contain.
The PNF algorithms rely on the Eratosthene sieve to
generate all the prime numbers up to a threshold.
The question we address in this chapter is how to
extend this computation above the threshold using
parallel computation.
Figure 4. PNF Fractal Using 500,000,000 primes.
Let q  4  k  1 be a prime number. For another
prime number p there are q-1 possible modulo
results. Depending on the value p mod q we have
the following moves:
1. 1  p mod q  k
 jump up over
p mod q pixels.
2. k  1  p mod q  2k  jump down over
p mod q  k pixels.
Suppose that the prime numbers up to n1 are
generate by using the Eratosthene sieve in
generate_primes(n1, m, p). The array or collection p
contains initially n1 elements and finally only
n
m  1 . Hence we can use the available
log n1
n
n1  1 memory locations to store some other
log n1
primes bigger than n1 . The odd numbers x between
n1 and n2 are tested to find whether they are prime
by using a primality test is_prime(x). Since they are
big odd numbers the computation is_prime(x) is
very expensive so that parallel processing is needed
to speed up the process. Figure 6 illustrates the
generic parallel algorithm for this computation.
procedure generate_prime(n1, n2, m, p)
begin
generate_primes(n, m, p);
forall x=n1 to n2 step 2 do
if is_prime(x) then p[++m]=x;
end;
Figure 6. Extending the computation of primes.
Suppose that a parallel machine with s  size
processors P1 , P2 , ..., Ps is used in computation. The
parallel loop forall is scheduled onto processors in a
block fashion so that the processor Pj receives all
the iterations {l j , l j  2,..., h j } . The scheduling is
therefore given by the bounds
l , h , j  1,2,..., p
j
j
so that
l1  n1 , hp  n2 and l j  h j 1  2, j  2,3,..., p .
(4)
Each processor Pj tests all the odd numbers
{l j , l j  2,..., h j } and stores the prime numbers found
in a local array local_p. Finally, all the local arrays
are gathered back in the array p. In this way the
prime numbers that are found by the processors will
be appended to the array p in a consecutive fashion.
The efficiency of this parallel computation depends
on how well the bounds l j , h j , j  1,2,..., p are



chosen. The simplest solution is to use an uniform
scheduling where each processor receives the same
n  n1
number of iterations 2
. In this case the
2s
processor P1 gets the smallest numbers to test while
the last processor Ps tests the largest numbers. In
this way the computation will have an important
load imbalance overhead.
4.1 Primality Tests
Testing primality for large numbers has been a
challenging problem for which several deterministic
and probabilistic methods have been developed. For
century the trial divisor method is known to be
efficient for small numbers. For a number x all the
odd number up to x should be tested to find a
divisor. Certainly, the complexity of this solution is
O x is excessive for very large numbers.
 
Probabilistic methods, like Lucas’ or Rabin-Miller’s
tests have been around for the last few decades. If a
number passes such test is likely to be prime and is
called pseudo-prime. For a number x let
x  1  2 y  z with z odd. Rabin-Miller’s test uses a
random number 1  a  x  1 to check if
a z  1 mod x  or a 2 z  1 mod x  for some j (5)
in which x passes the test [5]. If the test is repeated
for several values 1  a  x  1 then the certainty of
the test becomes close to 1. Moreover, when
Equation (5) is satisfied for all the values
1  a  x  1 then x is prime. The complexity of this
Rabin-Miller test is O(log x) which makes it one of
the most efficient method. However, if a number x
passes the test then we can only say that x is likely
prime.
j
The most effective deterministic test over the last
decade was based on elliptic curves. By defining an
addition of points on an elliptic curve modulus a
prime a group of rational points can be constructed.
Goldwasser and Kilian proposed a theorem for a
pseudocurve E (  n ) that provided the impetus fpr a
primality proof called ECPP [2]. This algorithm
yielded a certificate of primality that could easily be
provided. ECPP has a complexity of O((log n)5 )
and is proven to be polynomial time for almost all
choices of inputs.
The quest of an efficient deterministic test has
recently got a positive answer although this was
predicted several years ago [10]. In August 2002,
the scientific community was shocked by Agrawal
et.al. who announced that primality testing is
polynomial . Their method, which is known as
cyclotomic AKS test has the complexity O log 12 x .
Recently, this complexity has been reduced
dramatically to O log 6 x or even to O log 4 x for
some classes of integers [4].






All these methods have been successfully
implemented in various libraries to work with large
numbers. The Java BigInteger class provides the
method isProbablePrime() that uses the Rabin-Miller
test. In C/C++ there are several packages for large
number computation. lip (long integer processing)
contains several probabilistic and deterministic
methods for both primality and factorization.
4.2 Balanced Workload Scheduling - BWBS
Balanced Workload Block Scheduling (BWBS) is a
static scheduling method that was proposed recently
by Tabirca et.al [8]. The method attempts to find the
bounds
l
j ,hj
, j  1,2,..., s of a block scheduling
that balances the workload of the processors. The
assumption is that the workload of each parallel
iteration is known. Suppose that the workload of the
method
is_prime(x)
is
given
by
w( x), x  n1 , n1  2, , n1  4,...,n2 . In this case the
 w( x)
total workload is
so that the
x  n1 , n1  2, , n1  4,..., n 2
average workload per processors becomes
1
W 
w( x) .
s x  n1 , n1  2, n1  4,..., n2

BWBS find the bounds l
j ,hj
, j  1,2,..., s so that
the workload of each processor is equal to W
1
w( x)  W  
w( x) .
s x n1 ,n1  2,n1  4,..., n2
x l j ,l j  2,..., h j

(6)

(7)
Tabirca et.al. proposed a method to find equations
for the upper bounds h j , j  1,2,..., s when the


workload w(x) has simple formula [8]. This method
can be applied for the trial divisor testing when the
workload is w( x)  x , x [n1 , n2 ] . In this case the
upper bounds are
2/3
s j
j
3/ 2
3/ 2 
h j    n2 
 n1  , j  1,2,..., s . (8)
s
s

P1
P2
P3
P4
479.5 540.4 635.5 767.8
610.5 608.4 609.1 611.3
620.7 610.9 611.1 609.6
US
BWBS1
BWBS2
Table 2. Processor Execution Times for s=4.
900
800
Seconds
700
600
US
500
processing step is required to compute the bounds of
Equation (7) using
(9)
hj  h 
 w( x)  W   w( x) .
x l j ,l j  2,..., h
x l j ,l j  2,..., h  2
It is clear that the pre-processing step induces a
n  n1
small scheduling overhead of O( 2
)
2
operations.
5 Experimental Results
Some experimental tests have been carried out in
order to illustrate the parallel method. They have
been done using a Dell Cluster machine with 100
PIII processors. The algorithm fractal was translated
into a C MPI program in which a simple divisor trial
test has been used. Three scheduling methods have
been used to schedule the parallel loop forall. The
first one is uniform scheduling(US) where each
block set has the same number of iterations. The
second one is a balanced workload scheduling
(BWBS1) that uses the upper bounds from Equation
(8). Finally, balanced workload scheduling (BWBS2)
with a pre-processing step is employed.
The MPI program has used n1  10,000,000 to
generate the primes using the Erathostene’s sieve.
After that the computation of primes has been
extended up to n2  500,000,000 . Table 2
illustrates the processor execution times when s=4.
Firstly, we can observe that the uniform scheduling
gives an important load imbalance while the BWBS
methods achieve a good load balance. We can also
remark that the pre-processing step of BWBS2
makes the execution time of P1 a bit bigger.
s=1
US
3101.54
BWBS1 2628.59
BWBS2 2669.01
s=4
767.8
611.3
620.7
s=8
403.7
293.7
305.2
s=16
225.1
146.5
152.6
s=32
149.2
75.1
83.3
BWBS1
400
BWBS2
300
Table 3. Execution Times for s=1, 4, 8, 16, 32.
200
100
0
P1
P2
P3
P4
Figure 7. Processor Execution Times for s=4.
Unfortunately, the method cannot be applied for the
other primality methods whose complexity has the
form of w( x)  log k x, x [n1 , n2 ] . For them a pre-
The second test evaluates the overall execution
times over s=1, 4, 8, 16 and 32 processors (see
Table 3). Figure 8 shows that the difference between
the BWBS methods is marginal with a small
advantage for BWBS1. It also illustrates the
importance of parallel computing to solve this
problem. Using one processor the PNF image has
been generated in around 43 minutes. But when 32
processors have been employed the execution time
has reduces to less than 2 minutes.
3500
(Seconds)
3000
2500
US
2000
BWBS1
1500
BWBS2
1000
500
0
s=1
s=4
s=8
s=16 s=32
(Number of Processors)
Figure 8. Execution Times for s=1, 4, 8, 16, 32.
6 Conclusion
This article has presented some new developments
on Prime Number Fractals. The first contribution of
the article has proved that the number of up, down,
left or right moves is the same which is a
mathematical explanation of the central area of
brightness. A generalized PNF algorithm has been
proposed to make areas around the borders brighter.
Since the PNF algorithms depend on the number of
primes used in computation, we have presented a
parallel method to generate more numbers than the
Erathostene sieve gives.
References:
[1] M. Agrawal, N. Kayal, and N. Saxena, Primes in
P, Indian Institute of Technology, Preprint,
Aug. 6, 2002,
www.cse.iitk.ac.in/primality.pdf.
[2] E. Bach and J.Shallit, Algorithmic Number
Theory, MIT Press, Cambridge, Massachusetts,
USA, 1996.
[3] A. Leatherland, Pulchritudinous primes;
Visualizing the distribution of prime numbers,
http://yoyo.cc.monash.edu.au/~bunyip/primes
[4] Lenstra H. W. Jr. and Pomerance C. "Primality
Testing with Gaussian Periods." Manuscript.
March 2003.
[5] M.O.Rabin, Probabilistic Algorithm for Testing
Primality, J. Number Th,. Vol 12, 1980, pp. 128138.
[6] M. Stein and S. Ulam, An Observation on the
Distribution of Primes, Amer. Math. Monthly,
Vol 74, 1967, pp. 43-44.
[7] M. Stein, S. Ulam, and B. Wells, A Visual
Display of Some Properties of the Distribution of
Primes, Amer. Math. Monthly, Vol 71, 1964, pp.
516-520.
[8] T.Tabirca, L.Freeman, S.Tabirca and T.L.Yang,
A Static Workload Balance Scheduling
Algorithm, Proceedings of the 2nd Workshop on
Parallel and Distributed Scientific and
Engineering Computing with Applications
(PDSECA 2001), April 2001, San Francisco,
USA.
[9] A. Turpel, The Aesthetics of Prime Sequence,
http://www.2357.a-tu.net/
[10] S. Wagon, Primality Testing, Math. Intell. Vol.
8, No. 3, 1986, pp. 58-61.
[11] M. Wolf, Multifractality of prime numbers,
Physica A 160, 1989, pp. 24-42.
[12] M. Wolf, Random walk on the prime numbers"
Physica A 250, 1998, pp. 335-344.
[13] E. E. Weisstein, Arbitrarily Long Progressions
of Primes, MathWorld headline news, April 12,
2004.
http://mathworld.wolfram.com/news/2004-0412/primeprogressions/.
.