Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Primality

Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Primality Testing:
Rabin-Miller vs AKS
Author: Bruno Neto
Instructor: Dr. George Steele
PMAT 427 - Number Theory
Winter 2014
University of Calgary
April 9
th
, 2014
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Table of Contents
1 Primality Test
Probabilistic vs Deterministic
History of Primality Testing
2 Rabin-Miller Primality Test
Fermats Primality Test
Rabin-Miller
3 AKS Primality Test
Facts
Algorithm
4 References
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Primality Test
Goal
The goal of a primality test algorithm is to verify whether a
given positive integer is prime or not.
Gauss, disquisitiones arithmeticae, 1801
"The problem of distinguishing prime numbers from composite
numbers and of resolving the latter into their prime factors is
know to be one of the most important and useful in
arithmetic(...) Nevertheless, we must confess that all methods
that have been proposed thus far are either restricted to very
special cases or are so laborious and prolix that (...) theses
methods do not apply at all to large numbers. "
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Probabilistic vs Deterministic
Probabilistic (or Randonmized) Test
Give a positive integer
Check for a random a if it works
Repeat k times
Result: Maybe prime
Ex: Fermat, Rabin-Miller, RSA, Solovay-Strassen
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Probabilistic vs Deterministic
Deterministic Test
Give a positive integer
Test the algorithm
Result: Guaranteed whether prime or composite
Ex: Trial Division, AKS, Elliptic Curve, "Rabin-Miller"
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
History of Primality Testing
In 17th Century, Fermats Little Theorem says for any
prime integer n and any integer a coprime to n,
a
n1
1(mod n)
1976 - Miller used the alternative property to obtain a
deterministic polynomial time
1980 - Rabin modied Milles test to a randomized
polynomial time algorithm
1984 - Adleman, Pomerance, and Rumely created a
deterministic for primality test that runs in
(log(n))
O(log log log(n))
time
1986 - Goldwasser and Kilian proposed a randomized
algorithm based on Elliptic Curves running in expected
polynomial time
2002 - Agrawal, Kayal, and Saxena proved a deterministic
algorithm in polynomial time
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Fermats Primality Test
Fermats Little Theorem
If n is prime and (a, n) = 1, then a
n1
1(mod n).
Alternative Statement 1
If a
n1
1(mod n) and (a, n) = 1, then n is denitely
composite.
Alternative Statement 2
If a
n1
1(mod n) and (a, n) = 1, then n is probably prime.
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Examples
base 2, 3 < n < 1000
2
340
1(mod 341), however 341 = 11 x 31
2
560
1(mod 561), however 561 = 3 x 11 x 17
2
645
1(mod 645), however 645 = 3 x 5 x 43
base 5, 3 < n < 1000
5
3
1(mod 4), however 4 is composite
5
123
1(mod 124), however 124 = 4 x 31
5
560
1(mod 561), however 561 is composite
5
780
1(mod 781), however 781 = 11 x 71
Fermats Pseudoprimes
341, 561 in base 2 and 4, 124, 561, 781 in base 5
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Carmichael Numbers
Carmichael Numbers less then 10,000
561, 1105, 1729, 2465, 2821, 6601, 8911
Theorem(Erdos)
Theorem: Let C(X) be the number of Carmichael numbers
less then X, then
C(X) < Xexp

k
2
log(x)logloglog(X)
loglog(X)

C(10
3
) = 1
C(10
10
) = 1547
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
History of Rabin-Miller Primality Test
Gary G. Miller is a professor at Carnegie Mellon University and
created the algorithm deterministically assuming the
Generalized Riemann Hypothesis in 1976. While Michael O.
Rabin, based his method to test the algorithm probabilistically
using Millers work in 1980.
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Algorithm
Rabin-Miller Algorithm
1 Input: n odd, k repetitions
2 make n 1 = 2
s
m, m odd and s biggest power of 2
3 for i in range(1,k)
4 a = random [2, n-1]
5 while s > 0
6 If a
2
s
m
1(mod n), then n is composite
7 If a
2
s
m
1(mod n), then n is probably a prime
8 s = s 1
9 Output: n denitely composite or n probably prime
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Example
Test, after one interation
Enter an odd integer to be tested:
4547337172376300111955330758342147474062293202868155909393
Enter the number of times you want to test: 1
The number is probably a prime
Test, after two interations
Enter an odd integer to be tested:
4547337172376300111955330758342147474062293202868155909393
Enter the number of times you want to test: 2
The number is denitely a composite integer.
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Lemma 1
Lemma: Let a Z, n N, n 2, and (a, n) = 1. Then n is
prime if and only if (X + a)
n
(X
n
+ a) 0 (mod n)
Proof of Lemma 1
Proof: For 0 < i < n, the coecient of x
i
in
(X + a)
n
(X
n
+ a) 0 (mod n) is

n
i

a
n1
.
n prime

n
i

0 (mod n) all the coecients are zero.


If n is composite. Consider a prime q that is a factor of n and
let q
k
|n. Then q
k
does not divide

n
q

and is coprime to a
nq
and hence the coecient of X
q
is not zero (modn). Thus,
((X + a)
n
(X
n
+ a)) is not identically zero over Z
n
.
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Algorithm
AKS psedocode Algorithm
Input: integer n > 1
1 If (n = a
b
) for a N and b > 1, output COMPOSITE
2 Find the smallest r such that o
r
(n) > log
2
n.
3 If 1 < (a, n) < n for some a r , output COMPOSITE
4 If n r , output PRIME
5 For a = 1 to

(r )log(n) do
6 if((X + a)
n
X
n
+ a (mod X
r
1, n)), output
COMPOSITE
7 output PRIME
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
References
1 Agrawal, M., Kayal, N., and Saxena, N., PRIMES is in P,
Kanpur-208016, India, 2002
2 Perrenoud, M., Randomized and Deterministic Primality
Test, Ecole Polytechnique Federale de Lausanne, 2009
3 Jin, T., Research and Implementation on AKS Algorithm,
University of Bath, 2005
4 Mcintosh, C., Finding Prime Numbers: Miller Rabin and
Beyond, Furman University, Eletronic Journal of
Undergraduate Mathematics, Vol. 12, 1-4, 2007
Primality
Testing:
Rabin-Miller
vs AKS
Bruno Neto
Primality
Test
Probabilistic
vs
Deterministic
History of
Primality
Testing
Rabin-Miller
Primality
Test
Fermats
Primality Test
Rabin-Miller
AKS
Primality
Test
Facts
Algorithm
References
Thank you!

You might also like