21
189 Obi et al., Comparing AKS AlgorithmFuto Journal Series (FUTOJNLS) e-ISSN : 2476-8456 p-ISSN : 2467-8325 Volume-5, Issue-1, pp- 189 - 209 www.futojnls.org Research Paper July 2019 Comparing AKS Algorithm for Deterministic Primality Testing Using Matlab Updated With Mapple and C++ 1 Chidozie, K. K, 1* Obi, M. C. and 2 Nwamba, I. 1 Department of Mathematics, Federal University of Technology, Owerri, Imo State, Nigeria 2 ICT Department, Imo State University, Owerri, Imo State, Nigeria *Corresponding Author’s Email: [email protected]; [email protected] Abstract This work compared the use of MATLAB updated with MAPPLE and C++ to implement AKS algorithm which is the first deterministic primality testing algorithm in polynomial time. To test if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm. This is inefficient especially in cryptography where large numbers are often tested for primality. Thus implementing AKS algorithm in MATLAB updated with MAPPLE is faster and efficient than using C++. 1. Introduction The study of prime numbers dates back to 300BC. An ancient Greek Mathematician called Euclid used the method of contradiction to prove that there were infinitely many prime numbers. He also proved the fundamental theorem of arithmetic. In 200BC, another Greek Mathematician called Eratosthenes introduced an algorithm for primality testing called the Sieve of Eratosthenes when given integer numbers from 2 to , mark all the even numbers except 2. Then start with the next unmarked number, which in our case is 3, mark all the numbers which are multiplies of three except 3. Continue in this way until there are no new unmarked numbers. All the numbers remaining unmarked are prime numbers. The test, however, is efficient. It takes steps to determine if n is prime. Afterwards, little happened with the study of prime numbers until the 17 th century, during which Pierre Fermat put a great effort into it. One of his greatest achievements is the Fermat‟s Little Theorem that, for any given prime number p any number such that a , then Although the above test could be efficiently computed, it could not be used as such since there were numbers called the Carmichael numbers which satisfied the Fermat‟s property for all a‟s Though the direct application of the Fermat‟s Little Theorem was discarded, it lays the foundation for many different algorithms which were primarily based on this theorem.

Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

189 Obi et al., Comparing AKS Algorithm…

Futo Journal Series (FUTOJNLS)

e-ISSN : 2476-8456 p-ISSN : 2467-8325

Volume-5, Issue-1, pp- 189 - 209 www.futojnls.org

Research Paper July 2019

Comparing AKS Algorithm for Deterministic Primality Testing

Using Matlab Updated With Mapple and C++

1Chidozie, K. K, 1*Obi, M. C. and 2Nwamba, I. 1Department of Mathematics, Federal University of Technology, Owerri, Imo State, Nigeria

2ICT Department, Imo State University, Owerri, Imo State, Nigeria

*Corresponding Author’s Email: [email protected]; [email protected]

Abstract

This work compared the use of MATLAB updated with MAPPLE and C++ to implement AKS algorithm which is the first deterministic primality testing algorithm in polynomial time. To test if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm. This is inefficient especially in cryptography where large numbers are often tested for primality. Thus implementing AKS algorithm in MATLAB updated with MAPPLE is faster

and efficient than using C++.

1. Introduction

The study of prime numbers dates back to 300BC. An ancient Greek Mathematician called

Euclid used the method of contradiction to prove that there were infinitely many prime

numbers. He also proved the fundamental theorem of arithmetic.

In 200BC, another Greek Mathematician called Eratosthenes introduced an algorithm for

primality testing called the Sieve of Eratosthenes when given integer numbers from 2 to ,

mark all the even numbers except 2. Then start with the next unmarked number, which in

our case is 3, mark all the numbers which are multiplies of three except 3. Continue in this

way until there are no new unmarked numbers. All the numbers remaining unmarked are

prime numbers. The test, however, is efficient. It takes √ steps to determine if n is

prime.

Afterwards, little happened with the study of prime numbers until the 17th

century, during

which Pierre Fermat put a great effort into it. One of his greatest achievements is the

Fermat‟s Little Theorem that, for any given prime number p any number such that a

, then Although the above test could be efficiently computed, it could not

be used as such since there were numbers called the Carmichael numbers which satisfied

the Fermat‟s property for all a‟s

Though the direct application of the Fermat‟s Little Theorem was discarded, it lays the

foundation for many different algorithms which were primarily based on this theorem.

Page 2: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

190 Obi et al., Comparing AKS Algorithm…

The theory of primarily testing for restricted families of numbers had an earlier start. The first

and most famous “modern” algorithm is the Lucas-Lehmer Test (1876). It is an algorithm that

runs in ̃ time to determine whether a Mersenne number (a number of the

form , prime) is prime or composite. Proth (1878) enlarged the family of numbers for

which a primarily test that runs in ̃ exists. The Proth Test applied to all numbers n

such that ( ⁄ ) (by we always mean log to the base ) provided an

integer is given for which the Jacobi Symbol (

) Usually such an integer can

easily be found using the quadratic reciprocity law; thus, the Proth test become deterministic

for a large proportion of, though not all the numbers n satisfying ( ⁄ ) ( is

the Lucas-Lehmer Test). Later, the Lucas-Lehmer Test was also extended to all

numbers , such that ( ⁄ ) for which an integer α is given

such that (

) (

) Hugh Williams (1970) extended these tests to numbers

satisfying ( ⁄ ) where is a prime, provided there is a prime ,

such that n is not a power modulo , and gave many concrete

implementations and tables of primes.

Most of the mathematicians who are interested in prime numbers have two challenges:

To find the next largest prime number relative to current one.

To provide a fast method or improve a current available one which determines

whether a given number is prime or composite.

This is due to the natural properties of prime numbers and the need of their widespread

applications. The second problem is particularly important because the given number could

be any magnitude. Currently the largest known prime number is which was

found by Findley (2004). Therefore methods such as Sieve of Eratosthenes are not efficient

for large numbers since their complexity of time is exponential in terms of the length of a

large number. It is not feasible to determine an integer number of large magnitude via these

methods even based on the latest mainframe computers. Naturally, a more efficient primality

testing algorithm is urgently needed because of the important role prime numbers play in

modern cryptosystems. As a result, there has been a dramatic increase in developing

efficient primality testing algorithms since 1970s. Most of them are based on the Fermat‟s

Little Theorem.

Pratt (1975) showed that a short certificate of primality always exists and hence that primes

are in non deterministic polynomial time, but while his method is constructive, it requires

factorisation of large integers and thus does not run in polynomial time.

Miller (1976) used the property of Fermat‟s Little Theorem polynomial time algorithm for

primarily testing assuming Extended Riemann Hypothesis (ERH).

Independently, Solovay and Strassen (1977) obtained different randomized polynomial-time

algorithm using the property that for a prime , (

) for every a. Their

algorithm can also be made deterministic under Extended Riemann Hypothesis. Since then

a number of randomized polynomial-time algorithms have been proposed for primarily-

testing based on many different properties.

Page 3: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

191 Obi et al., Comparing AKS Algorithm…

Solovay and Strassen (1977) used Euler‟s theorem in order to develop a primality test. Their

idea was to randomly choose integers less than and ensure that each satisfied the

above equality.

Rabin (1980) modified Miller‟s test to provide an unconditional but randomized polynomial

time algorithm.

The Miller-Rabin algorithm relies on an equality or set of equalities that hold true for prime

values, and then see whether or not they hold for a number that we want to test for primality.

The algorithm was able to correctly identify the composite numbers but had a probability

which is less than of error in identifying primes.

Adlemann, Pomerance, and Rumely achieved (1983) a major breakthrough by giving a

deterministic algorithm for primality testing that runs in time (all the

previous deterministic algorithm required exponential time). Their algorithm was (in a sense)

a generalization of Miller‟s idea and used higher reciprocity laws. It was simplified by Cohen

and Lenstra (1984), and implemented by Cohen and Lenstra (1987).

Goldwasser and Kilian (1986) proposed a randomized algorithm based on Elliptic Curves

running in expected polynomial time on almost all inputs (all inputs under a widely believed

hypothesis) that produces a certified for primality (until then, all randomized algorithms

produced a certificates for compositeness only). Based on their idea a similar algorithm was

developed by Atkin (1986).

Later, Atkin and Morain (1990, 1993) devised a method called Elliptic Curves Primality

Proving (ECPP). It stated that given any prime n of length k, the algorithm outputs a

certificate of correctness of size which can be verified correct in deterministic

time. The running time of this algorithm is for some and subsequently

optimized by Bosma and van der Hulst (1990).

A major breakthrough was achieved by Agrawal, Kayal and Saxena (2002) who together

proposed an algorithm (popularly known as the AKS algorithm) in their paper “PRIMES is in

”. The AKS algorithm can determine the input number n is prime number or not in the runs

time ̃ . The algorithm which is based on a slight modification of the Fermat‟s Little

Theorem was the first deterministic polynomial time algorithm for primality testing.

Soon after the publication of AKS paper, Lenstra Jr (2003) modified the AKS algorithm with

the observation made by Pomerance who observed that need not to be the largest prime

divisor of . The major difference is the construction of the useful prime .

Also, Berrizbeitia (2003) presented a deterministic primality tests with running time of

. For integers such that for a given integer (

) and for

integers such that (

) (

) .

Cheng in his paper (2003), states that the reduction in time complexity is achieved by first

generalizing Berrizbeitia‟s algorithm to one which has higher density of easily-proved primes.

For a general prime, one round of ECPP is deployed to reduce its primality proof to the proof

of a random easily proved prime. The algorithm has a running time of

Page 4: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

192 Obi et al., Comparing AKS Algorithm…

Also in the same year, Bernstein (2003) generalize Berrizbeitia improvements and presents

an algorithm that, for a given integer n, finds and verifies the primality of n in random time

.

In the later version of AKS (2004), the original algorithm has been improved based on

various modifications by other people. This version of algorithm which is presented in this

paper eliminates the while-loop and uses the idea of Lenstra for constructing r. Hence the

complexity time is reduced to . And Lenstra (2005), proposed a variant of AKS

which runs in ̃ time. However, both of these improvements are only of theoretical

interest.

Lenstra Jr (2011) improved the running time once again. He and Pomerance were able to

improve the running time to ̃ by generating rings using Gaussian periods, instead

of roots of unity. Their proof relies on recently developed results in both analytic and additive

number theory.

This paper presented AKS algorithm under the basic principles involved and provide its

implementation in updated MATLAB with MAPPLE and C++ and also compare the run time.

Since MAPPLE functions assisted for the exponentiation and modular reduction in MATLAB,

there was no need to carry on our test on MAPPLE.

2. Some basic definitions

2.1. Congruence

If two numbers and have the property that their difference – is integrally divisible by a

number (i.e. is an integer) then and are said to be “congruence modulo ”.

The number is called the modulus and the statement “ is congruence to ” is

written mathematically as .

If – is not integrally divisible by , then, it is said that “ is not congruence to

”.

2.2. Residue Classes

The congruence relation on the set of integers 1 separates the integers into n

equivalence classes, called residue classes modulo n. Each

equivalence class consist of all integers congruent to , where the integer is

the class representative.

2.3. Euler’s Totient Function

The totient function , also called Euler‟s totient function or Euler‟s phi function is the

number of positive integers that are relatively prime with .

Generally, if

, where distinct prime divisors of and , then,

(

) (

)

In particular, if a prime, then and if , where , then

Page 5: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

193 Obi et al., Comparing AKS Algorithm…

2.4. Polynomial Ring

The polynomial ring, , in over a field is express in the form

where , the coefficients of , are elements of . So,

is a ring under basic polynomial addition and multiplication.

3. The AKS Algorithm

3.1. The AKS Test

Here, we develop the core ideas of a recent primality test. The test was derived in 2002 and

is based on a generalization of Fermat‟s Little Theorem to polynomial rings. To begin, we

discuss binomial coefficients modulo a prime.

The objective here is to describe the Primality Testing Algorithm which, when given an input

outputs whether the given input is prime or composite. Since the aim is to find a

polynomial-time algorithm, the final algorithm should output a result (of which is prime or

composite) in ̃ where refers to .

Theorem 3.1: Let be a prime. If , then ( )

Proof: For , each term in the denominator of the binomial coefficient

(

)

Is strictly less than and since is prime, this means that the factor in the numerator

cannot cancel. Hence, divides ( ) and the theorem is proved.

This theorem is the key to proving the generalization of Fermat‟s Little Theorem to the

polynomial case.

N.B: We write if and . That is, is the largest power of dividing

Thus, if Then since but .

Theorem 3.2 (Fermat’s Little Theorem): Let be an integer and any integer with

Then is prime if and only if

(3.2)

Proof: First note that,

– (

) (

) (

) (

)

∑ ( )

.

Suppose is prime. Then each binomial coefficient in the sum is zero, so this case reduces

to Fermat‟s Little Theorem.

Conversely, suppose is composite. Then has a prime divisor , so let . We show

that the coefficient ( ) of in is not divisible by and therefore, doing a

Page 6: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

194 Obi et al., Comparing AKS Algorithm…

term-by-term comparison, the congruence (3.2) cannot hold. Since , then

and consequently

( ) (3.3)

Now suppose ( ). Then there is an integer such that

.

Rearranging and pulling a factor of from into yields

(3.4)

and since the left-hand side is an integer, so is the right-hand side. Now we show that no

factor of in the numerator can cancel. Suppose a factor of can cancel, then some term in

the denominator must be divisible by . Since is prime,

and must divide one of the terms in the product, that is, for some .

Then and since , we must also have ,

which contradicts the fact that . Thus and no factor of can cancel.

Then (3.4) implies that , a contradiction. Hence, ( ).

Finally, suppose ( ) . Then there is an integer such that (

) . It follows

that

( )

(3.5)

Since , the left-hand side is an integer and then so is the right-hand side. We have

shown that ( ), so we must have , contradicting (3.3). Therefore (

)

and hence the congruence (3.2) cannot hold.

This theorem provides us with a deterministic primality test. Given an integer , we can

choose an with and check if the polynomial congruence (3.2) is satisfied. Note

that we can always choose since for any integer .

Thus, we use the previous theorem to verify that is prime. We expand and reduce

modulo 7 to find that

(

) (

) (

) (

) (

) (

)

Then since the congruence (3.2) is satisfied, is prime.

We can also verify that is composite. We expand and reduce modulo :

Page 7: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

195 Obi et al., Comparing AKS Algorithm…

(

) (

) (

) (

) (

) (

) (

)

Since the congruence (3.2) is not satisfied, 8 is composite.

Unfortunately, testing numbers in this way is impractical. There are too many coefficients to

compute when expanding . We can eliminate some of the coefficients if we choose

to reduce the polynomial modulo a convenient polynomial.

3.2. Algorithm (The AKS Test)

The main idea of the AKS test is that if is composite, then the reduced polynomial

congruence cannot hold for too many . In order to implement the AKS algorithm, we

require a quick method to detect perfect powers in step (1). Such a method is given below.

First, notice that we only need to check for prime exponents: If , where is prime,

then

.

The largest possible exponent we need to check for is the one for which the base is . So

we only need to check if for prime exponents not exceeding . Note that such a

list can be obtained using the Sieve of Eratosthenes. Now for to be a perfect power, the

base

⁄ must be an integer. Otherwise, is not a perfect power.

Thus, we can determine whether is a perfect power using the method

described above. If , then the largest possible exponent is . Since we

only need to check for prime exponents not exceeding , the only exponents we need to

check are , and . Now we compute the necessary roots:

Page 8: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

196 Obi et al., Comparing AKS Algorithm…

⁄ ,

⁄ ,

Since the fifth root of is the integer , we conclude that is a perfect power.

With a method for detecting perfect powers in hand, we can begin to implement the AKS

algorithm. The algorithm is easy to implement on a computer. On paper, however, there are

many computations to do. For this reason, we only test very small values of in this work.

For instance, if , we first determine whether is a perfect power. The only prime less

than or equal to is , and computing

⁄ ,

We find that is not a perfect power. Now we find the in step (2). One can verify the

following computations.

, ,

,

So the smallest for which is . Then computing the necessary

greatest common divisors in step (3), we find the following.

None of these values are strictly between and , so we continue to step (4). Since

, we conclude that is prime.

Thus, if , we first check whether is a perfect power. The only primes less than or

equal to are 2 and 3. Computing the roots

⁄ and

⁄ ,

We find that is not a perfect power. Now we compute the following orders to complete

step (2):

, .

The smallest for which is . Then we compute the greatest

common divisors in step (3) and find that

.

Since , we conclude that is composite.

Here for our final example, we test the integer . To see that is not a perfect power,

we note that and that neither of the necessary roots,

⁄ and

⁄ ,

Page 9: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

197 Obi et al., Comparing AKS Algorithm…

are integers. To find the in step 2, we compute for increasing values of ,

beginning with . The first for which is . Since

for all , we cannot conclude that is composite in step (3), and

since , we cannot conclude in step (4) that is prime.

Finally, we enter step (5) of the AKS algorithm. We find that either by inspection

or by using the Euclidean algorithm to compute for to . Now we must check

whether the polynomial congruence

is satisfied for ⌊√ ⌋ . After computing all necessary congruences,

we find that each congruence is satisfied. Therefore, is prime.

3.3. Algorithm for testing perfect-power

This part of the algorithm is used to check if the given number is a perfect power i.e. here

we check if the number can be written in the form . Now, if then we know that the

maximum value of is where here refers to the base (as has been the case

throughout). Therefore the problem here reduces to probing whether an exists such that

for The algorithm is given below:

i. for to

ii.

iii. performs

iv. if

output TRUE

v. Output FALSE

3.4. Is ‘r’ Prime?

In step 4 of AKS algorithm requires checking whether r is a prime number. Therefore r is

smaller enough so that we can apply an unconditional deterministic primality test algorithm in

non-polynomial time.

Input: Integer

1.

2.

3. while

4. if

5. then return is composite.

6. else

7.

8. }

9. return is prime.

Page 10: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

198 Obi et al., Comparing AKS Algorithm…

3.5. MATLAB Code

We use MATLAB to implement the algorithm and Maple to do the symbolic computation

found in the loop. The maple command used to calculate the identity in maple was given by

Gilbert G. T. (2003). This led to an implementation which was far faster than anything C++

could do. Appendix I show the MATLAB script used and Appendix II show the C++ script

used.

Application I: The Correctness of Perfect Power Check

First for perfect power checking, we present below the tests for certain values. The values

are selected so that, it is tested for numbers with different number of digits. In the result

column, 0 implies that the entered number is not a perfect power while otherwise, it displays

the perfect power of the given number such that using algorithm for testing Perfect

Power in (3.3) and (3.5) whose code appears in appendix I, we obtain;

Bits Number Result

1 4 22

1 7 0

5 42875 353

5 72355 0

10 1564031349 695

10 8812214355 0

15 582622237229761 241375692

15 987687645327744 0

20 26663523546439124560 64363433

20 43454657619840381796 0

24 333446267951815307088493 693439573

24 543565790912343654309875 0

28 1956410986640441413344189841 79217

28 1331410986640441413344189841 0

31 1271991467017507741703714391419 5917

43 1166316484553604833910724976125484023676928 667211

58 2478773645164848478975418774582564813617861031462649237

504

0

60 4010070685431578037276803435363509006705535080419539779

5649

91267310

80 5015772548390522734176174889014169418007610109084

0037071925071763978352502147041

49303914

132 1915028638109830236694870661712657837656061763680673178

0114577653169832206102664839162775687537780

7727062582859038489434170143851401

20157

Figure 4.1: Algorithm to determine if is prime or composite.

Page 11: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

199 Obi et al., Comparing AKS Algorithm…

Number Result

5 PRIME

33 COMPOSITE

861 COMPOSITE

4861 PRIME

55697 PRIME

7741043 PRIME

1771561 COMPOSITE

90552556447 COMPOSITE

435465768763 PRIME

9965468763136528274628451 PRIME

43546576876313652827462842409420126531423 COMPOSITE

Application II: Comparing Run Time

Detailed below are amortized times to determine the primality of different prime numbers

using the Matlab updated with MAPPLE and C++ implementation. These programs were run

on a laptop with a Pentium 2.13 GHz processor and 4GB of ram. It was also run in Windows,

which is known to be noticeably slower in Matlab than Linux distributions. However,

MATLAB updated with MAPPLE varies by approximately one tenth a second for each time

the same number is computed. The iteration time is specified by the user: the user inputs the

number of digits; the program then tests numbers from 2 to the number with input digits. It is

obvious that for primality testing algorithms, the time of giving an answer for composite and

prime input will be different. Thus we just record the run time for numbers which are returned

as primes, and write the data into a file.

Prime Number Time (seconds)

MATLAB C++

2 ≈ 0.01 ≈ 0.03

3 ≈ 0.08 ≈ 0.10

13 ≈ 0.11 ≈ 0.13

61 ≈ 0.19 ≈ 0.21

97 ≈ 0.29 ≈ 0.31

199 ≈ 0.46 ≈ 0.48

293 ≈ 0.61 ≈ 0.63

397 ≈ 0.81 ≈ 0.81

499 ≈ 0.99 ≈ 1.01

587 ≈ 1.13 ≈ 1.15

599 ≈ 1.15 ≈ 1.17

691 ≈ 1.27 ≈ 1.29

797 ≈ 1.34 ≈ 1.36

887 ≈ 1.45 ≈ 1.47

911 ≈ 1.46 ≈ 1.48

997 ≈ 1.59 ≈ 1.61

1487 ≈ 3.08 ≈ 3.10

Page 12: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

200 Obi et al., Comparing AKS Algorithm…

1499 ≈ 3.13 ≈ 3.15

1999 ≈ 11.97 ≈ 11.99

2999 ≈ 36.40 ≈ 36.42

3989 ≈ 55.20 ≈ 55.22

4999 ≈ 64.50 ≈ 64.52

It is of interest to note that 587, 887, and 1487 are co-Sophie Germain primes. This suggests

that these numbers should be faster to calculate than the ones around them which are not

co-Sophie Germain primes. This should actually speed up the amount of time it takes to find

a suitable , however, for numbers this small value is actually the same for two close

primes such as 587 and 599. It also found that the numbers 797, 887, and 911 all share the

same value and have very similar run times. Further, the for loop takes the most time to

calculate and this is the major limiting factor in this implementation. It was programmed so

that Matlab would display the “suitable” , this was interesting since a number as large as

4999, an was found nearly instantly, but the time it took to compute the identity in the for

loop took over a minute.

The formulation of a Deterministic Polynomial Time Primality Testing Algorithm has certainly

been a huge leap considering the fact that there were none until the AKS algorithm threw

thrown some light on one of the oldest problems in mathematics. However the AKS

algorithm though a remarkable theoretical result, is still nowhere near to being practical since

we have better performing probabilistic algorithms (with very less margin for error). To check

for whether the number 9965468763136528274628451 is prime took as much as around

210 minutes. Implementing AKS algorithm in MATLAB updated with MAPPLE is faster and

efficient using the result C++.

4. Conclusion

The formation of a deterministic Primality Testing algorithm has certainly been a big

problem until the AKS algorithm threw some light on this one of the oldest problems in

cryptography in particular and number theory in general. Implementing AKS algorithm in

MATLAB updated with MAPPLE is faster and efficient than implementing in C++. Changing

the base of the logarithm from 2 to e in steps 2 and 6 of the modified AKS algorithm should

be reduce computation by 50%. Maple functions „modp‟ and „pownd‟ for performing

polynomial exponentiation and modular reduction improved computational complexity of the

AKS algorithm. Such improvements focus on determining smaller values for r in the

polynomial of the form .

4.1. Limitations

Since most function in MATLAB do not accept inputs greater than 264, to text the primality of

large numbers were not done in this work. Also for large numbers AKS algorithm require

more time in the polynomial text since as the value of increases the value of does not

increase exponentially.

References

Adleman, L. M., Pomerance, C. & Rumely, R. S. (1983). On distinguishing prime numbers

from composite numbers. Ann. Math. 117, 173-206.

Page 13: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

201 Obi et al., Comparing AKS Algorithm…

Agrawal, M., Kayal, N. & Saxena, N. (2002). PRIMES is in P. Preprint, Posted in

http://www.cse.iitk.ac.in/news/primality.html

Amos T., Travis S. & Rohan, H. (2017). WXML Final Report: AKS Primality Test

Andrew Granville, It is Easy to Determine Whether a Given Integer is PRIME

http://www.dms.umontreal.ca/~andrew/PDF/Bulletin04.pdf.

Anon (2004). The Biggest Number. [online] Available from: http://www.7880.com/

Info/Article-3d278480.html [Accessed Nov 2006].

Atkin, O. L. (1986). Lecture notes of a conference, boulder (Colorado). Manuscript.

Atkin, O. L. & Morain, F. (1993). Elliptic Curves and Primality Proving (ECPP). Mathematics

of Computation, 61, 29-67.

Bernstein, D. J. (2008). Fast multiplication and its applications, in J. P. Buhler, P.

Stevenhagen (eds), Algorithmic number theory, 325-384, MSRI Publications 44,

Cambridge U. Press, New York.

Bernstein D. (2003). Proving Primality in Essentially Quartic Random Time, [online].

Available from http://cr.yp.to/primetests/quartic-20060914-ams. pdf [Accessed

December 2006].

Berrizbeitia, P. (2003). Sharpening “PRIMES is in P” for a large family of numbers. Journal.

Math. Comp. 74, 2043-2059.

Bobby, K. (2010). The miller-rabin randomized primality test. http://www.cs.

cornell.edu/courses/cs4820/2010sp/handouts/MillerRabin.pdf.

Bosma, W. & van der Hulst, M.-P (1990). Faster Primality Testing. In Advances in

Cryptology, Proc. Eurocrypt '89, Houthalen, April 10-13, 1989 (Ed. J.-J. Quisquater).

New York: Springer-Verlag, 652-656.

Carmichael, R. D., (1910). Note on a number theory function. Bull. Amer. Math. Soc., 16,

232-238.

Cheng Q. (2003). Primality Proving via one round of ECPP and one iteration in AKS, Crypto

Santa Barbara [online] Available from:

http://www.cs.ou.edu/%7Eqcheng/paper/askimp.pdf [Accessed December, 2006].

Cohen, H. & Lenstra, A. K. (1984). Primality Testing and Jacobi Sums. Math. Comput. 42,

297-330.

Cohen, H. & Lenstra, A. K. (1987). Implementation of a New Primality Test. Math.

Comput. 48, 103-121.

Goldwasser S. & Kilian J. (1986). Almost all primes can be quickly certified. In proceedings

of Annual ACM Symposium on the Theory of Computing, 316-329.

Granville A. (2005). It is easy to determine whether a given integer is prime. Bull. Amer.

Math. Soc. (N.S.), 42(1), 3-38.

Hardy G. H. & Wrightan E. M. Introduction to the theory of numbers, 63 – 72

Jameson G. J. (2008). The Prime Number Theorem. Cambridge University Press.

Joachim von zur Gathen & J¨urgen Gerhard (1999). Modern Computer Algebra. Cambridge

University Press.

Laubenbacher R. & Pengelley D. (2010). Voici ce que j‟ai trouve‟. Sophie Germain‟s grand

plan to solve Fermat‟s Last Theorem. Historia, 37(4), 641-692.

Lenstra H. W. Jr (2002). Primality Testing with Cyclotomic Rings. Preprint.

Lenstra H. W. Jr. & Carl Pomerance (2011). Primality testing with Gaussian Period Preprint

(http://www.math.dartmouth.edu/~carlp/aks041411.pdf).

Lucas E. (1876). On the search for large prime, numbers, Assoc. French P. I‟Avanc. Of

Science, accounts Rendus, 5, 61-68.

Page 14: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

202 Obi et al., Comparing AKS Algorithm…

Manindra Agrawal, Neeraj Kayal & Nitin Saxena. PRIMES is in P (2004). Ann. Of Math.

160(2): 781-793.

Muller G. L., (1976). Riemann‟s hypothesis and tests for primality. J. Comput. Sys. Sci.

13:317.

Prath V., (1975). Every prime has a succinct certificate. SIAM Journal on computing, 4:214-

220.

Proth F. (1878). On prime numbers, Rendus accounts, Acad. Sciences, Paris, 87:926.

Rabin M.O., (1980). Probabilistic algorithm for testing primality. J. Number Theory, 12:128-

138.

Rempe-Gillen L. & Waldecker (2014). Primality testing for beginners, volume 70 of Student

Mathematical Library. American Mathematical Society, Providence, RI.

Shoup V., A Computation introduction to Number Theory and Algebra (Beta version 5).

Copyright ©2004.

Silverman J. H., (2010). Squares modulo p. http://www.math.brown.edu/˜jhs/

MA0042/FRINTNewCh2324.pdf.

Solovay R. & Strassen V. (1977). A fast Monte-Carlo test for primality. SIAM Journal on

Computing, 6:84-86.

William Rundell (2015). Primality testing. http://calclab.math.tamu.edu/

r̃undell/m470/notes/primality.pdf.

APPENDIX 1

Page 15: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

203 Obi et al., Comparing AKS Algorithm…

Page 16: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

204 Obi et al., Comparing AKS Algorithm…

Page 17: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

205 Obi et al., Comparing AKS Algorithm…

Page 18: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

206 Obi et al., Comparing AKS Algorithm…

Page 19: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

207 Obi et al., Comparing AKS Algorithm…

Page 20: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

208 Obi et al., Comparing AKS Algorithm…

APPENDIX 2

Page 21: Comparing AKS Algorithm for Deterministic Primality ... Volume-5, Issue-1, pp- 189 - 209 ... if the number 9965468763136528274628451 is prime took about 210 minutes in AKS algorithm

209 Obi et al., Comparing AKS Algorithm…