SlideShare a Scribd company logo
The AKS Primality Test
Pranshu Bhatnagar
Chennai Mathematical Institute
Indraprastha Institute of Information Technology
11
th
June 2015
Introduction to Primality Testing
•Goal: given an integer n > 1, determine whether n is prime
•Most people know the smallest primes
•2, 3, 5, 7, 11, 13, 17, 19, 23, …
•What about:
•38,476? No, because it is even
•4,359? No, because the sum of the digits is 21, a multiple of 3
•127? Yes, because it does not have any factors < √127 ≈ 11.27
•257,885,161 − 1?
•This has over 17 million digits. We need better tests…
2
3 Categories
For some arithmetic statement S which is easy to check:
1.n is prime ⇒ S(n)
•pseudoprimes
•strong pseudoprimes
1.S(n) ⇒ n is prime
•n-1 test (Lucas Theorem)
•n+1 test (Lucas-Lehmer)
1.S(n) ⇔ n is prime
•AKS test
3
n is prime ⇒ S(n)
•S(n): n = 2 or n is odd
•S(n): n = 3 or sum of digits of n is not divisible by 3
•¬ S(n) ⇒ n is composite
•S(n) ⇒ ?
5
Pseudoprimes
•n prime ⇒ S(n)
•S-pseudoprime: n is composite but S(n) holds
•S(n): n = 2 or n is odd
•n = 15 is a pseudoprime
7
Intro to Modular Arithmetic
•a ≡ b (mod n)
•Formally n|(a-b)
•a/n leaves remainder b
•Clocks keep time (mod 12)
•16:30 (military time) ≡ 4:30 pm
•8:00 am + 7 hours = 15:00 ≡ 3 pm
•Subtract the modulus until the result is small enough
•11 ≡ 4 (mod 7)
•35 ≡ 0 (mod 5)
•23 = 8 ≡ 2 (mod 3)
11
Fermat Pseudoprimes
•n prime ⇒ S(n)
•S is based on Fermat’s Little Theorem:
If n is prime then an ≡ a (mod n), ∀a∈ℤ
•S(n): an ≡ a (mod n)
•Fermat pseudoprime: n is composite but an ≡ a (mod n)
for some a
13
Examples
n prime ⇒ an ≡ a (mod n)
•Let n = 91
•Composite: 91 = 7 * 13
•391 ≡ 3 (mod 91)
•91 is a Fermat pseudoprime base 3
•291 ≠ 2 (mod 91)
•91 is not a Fermat pseudoprime base 2 (91 is composite)
•Note: Most probably, ∃ infinite Carmichael numbers,
composites with
an ≡ a (mod n) for every a
17
S(n) ⇒ n is prime
•n is composite ⇒ ¬ S(n)
•¬ S(n) ⇒ ?
19
The n-1 Test
•S is based on the Lucas Theorem:
If an-1 ≡ 1 (mod n) but a(n-1)/q ≠ 1 (mod n) ∀ prime q|n-1,
then n is prime (for some a∈ℤ)
•S(n): an-1 ≡ 1 (mod n) but a(n-1)/q ≠ 1 (mod n)
23
Example
[an-1 ≡ 1 (mod n) but a(n-1)/q ≠ 1 (mod n)] ⇒ n
prime
•Let n = 19
•n-1 = 18 = 2 * 32
•Let a = 2
218 ≡ 1 (mod 19)
29 ≡ 18 (mod 19)
26 ≡ 7 (mod 19)
• So 19 is prime
29
Another Example
[an-1 ≡ 1 (mod n) but a(n-1)/q ≠ 1 (mod n)] ⇒ n
prime
•S(n) ⇒ n is prime
•¬ S(n) ⇒ ?
•Let n = 13, a = 5
•n-1 = 12 = 22 * 3
512 ≡ 1 (mod 13)
56 ≡ 12 (mod 13)
But 54 ≡ 1 (mod 13)
•S(n) is false, but n = 13 is prime
31
S(n) ⇔ n is prime
•S(n) ⇒ n is prime
•¬ S(n) ⇒ n is composite
•Theorem:
Given some a with gcd(a,n) = 1:
n is prime iff (x + a)n ≡ xn + a (mod n)
•S(n): (x + a)n ≡ xn + a (mod n)
37
Example
S(n): (x + a)n ≡ xn + a (mod n)
•(x+4)7
= x7 + 28x6 + 336x5 + 2240x4 + 8960x3 + 21504x2 + 28672x + 16384
≡ x7 + 4 (mod 7)
•7 is prime
•(x+3)4
= x4 + 12x3 + 54x2 + 108x + 81
≡ x4 + 2x2 + 1 (mod 4)
≠ x4 + 3
•4 is composite
41
Improvement: The AKS Theorem
•Agrawal-Kayal-Saxena (AKS) Theorem:
n is prime iff
•n is not a power,
•n has no small factors,
•(x + a)n ≡ xn + a (mod n, xr - 1)
for certain r and small values of a
43
The AKS Algorithm
47
Input: n ≥ 1
STEP 1. If ∃a, b > 1 ∈ N such that n = ab , then Output
COMPOSITE;
STEP 2. Find the minimal r ∈ N such that or(n) > log2(n);
STEP 3. For a = 1 to r do
if 1 < (a, n) < n, then Output COMPOSITE;
STEP 4. if r ≥ n, then Output PRIME ;
STEP 5. For a = 1 to do
if (x + a)n ≡ xn + a (mod xr − 1, n), then Output
COMPOSITE;
STEP 6. Output PRIME;
Proof Of Correctness
n is prime ⇒ S(n)
ln is certainly not of the form ab for any a, b > 1, so
lSTEP 1 will not output COMPOSITE.
lSince n is prime, we also know that ∀x ∈ N, (n, x) = 1 or n.
Hence STEP 3 will not output composite either.
lWe have seen that for any prime n, (x+a)n ≡ xn+a (mod n),
so STEP 5 will not output COMPOSITE.
lTherefore the algorithm will output PRIME
S(n) ⇒ n is prime
lIf the algorithm returns PRIME during STEP 4, then we know
that ∀m < n, (m, n) = 1 (this was checked in STEP 3),
meaning n is prime.
lThe remaining case, in which the algorithm returns PRIME
during STEP 6, will take considerably more effort and require
some extra machinery.
Runtime Analysis
Notation
Basic Operations
lLet n, m ∈ N. Then
lComputing m + n takes O(||n|| + ||m||) = O(log(n) + log(m))
bit operations.
lComputing m · n takes O(||n|| · ||m||) = O(log(n) · log(m)) bit
operations.
lComputing the quotient n div m and the remainder n mod m
takes O((||n|| −||m|| + 1) · ||m||) bit operations.
Basic Operations
lLet m, n ∈ N with at most k bits each. Then:
lm and n can be multiplied with O(k(log(k))(loglogk)) = O
~(k)
bit operations.
ln div m and n mod m can be computed using O(k(log(k))(log
logk)) = O
~(k) bit operations.
lMultiplication of two polynomials of degree d with
coefficients at most m bits in size can be done in O
~(d · m)
bit operations.
Euclidean Algorithm
lInput: m, n ∈ Z
l0: a, b integer;
l1: if |n| ≥ |m|
l2: then a ← |n|; b ← |m|;
l3: else b ← |m|; a ← |n|;
l4: while b > 0 repeat
l5: (a, b) ← (b, a mod b); //i.e., ai = bi−1 , bi = ai−1 mod bi−1
l6: return a;
lThis algorithm runs in O(log(n) · log(m)).
Fast Modular Exponentiation
lLet n = 2a
1 + 2a
2 + · · · + 2a
l where a1 > a2 > · · · > al.
lDefine f0 := (x + a),
lfi+1(x) = fi(x)2 (mod xr − 1, n).
lThen faj(x) = (x + a)aj .
lIf we further define g1(x) := fa1(x) and gk(x)≡gk−1(x) fk (x) (mod
xr − 1, n), then we see that
lgl(x) ≡ (x + a)2a
1
+···+2a
l = (x + a) n (mod x r − 1, n).
lWe have therefore computed (x + a)n (mod xr − 1, n) in a1 + l
≤ 2log(n) steps, where a step consists of multiplying two
polynomials of degree less than r with coefficients in Z/nZ.
This leads to a total runtime of O
∼(r·log2 (n)).
Perfect power Test
lInput : n ∈ N
l0: a, b, c, m integer
l1: b ← 2
l2: while (b ≤ log(n)) do
l3: a=1;c=m;
l4: while c − a ≥ 2 do
l5: m ← (a + c) div 2;
l6: p ← min {mb , 1};
l7: if p = n then return "n is a
perfect power";
l8: if p < n then a ← m else c
← m;
l9: b ← b + 1;
l10: return "n is not a perfect
power."
lLoop 1 will run at most log(n)
times. Also, it will take at
most log(n) iterations of loop
2 before |c − a| ≤ 1. During
each iteration of loop 2, we
calculate (a + c) div 2 and mb
, which can be done in
O
~(log(n)) bit operations.
lThe complexity of the entire
algorithm is therefore
O
∼(log3(n)).
Overall
STEP 1 At most O∼(log3(n)) bit operations.
STEP 2 We know that there exists an r< log5(n) such that
or(n) > log2(n) .The easiest way to find such an r is simply to
calculate nk(mod r) for k = 1, 2, ..., log2(n). This involves
O(log2(n)) multiplications modulo r for each r, so STEP 2
takes O∼(log7(n)) bit operations.
STEP 3 While determining whether (a,n)> 1 for some a ≤ r,
computing each gcd takes O∼(log2(n)) bit operations using
the Euclidean Algorithm, resulting in a total of O∼(log7(n)) bit
operations
Overall
STEP 5 Given a ≤ , calculating (x + a)n in the
ring Z/nZ as reducing modulo xr − 1 is trivial (simply replace
xs by x(s−r)). In order to calculate (x+a)n, we must perform
O(log(n)) multiplications of polynomials of degree<r with
coefficients of size O(log(n)) (as the coefficients are written
modulo n; recall that all polynomials are reduced modulo xr −1
during Fast Modular Exponentiation).Each congruence
therefore takes O∼(log7(n)) bit operations to verify.
This step therefore takes O∼( log(n) log7(n)) =
O∼( log8(n)) = O∼(log21/2(n)) bit operations. The
complexity of STEP 5 clearly dominates the complexity of
the other steps, so the overall complexity of the algorithm is
O∼(log10.5(n)), which is indeed polynomial.
Example
•Is n = 1993 prime?
1.1993 is not a power ✓
53
Example Continued
(Is n = 1993 prime?)
1.(i) Find “certain r:”
Really finding the least integer r > log2n with order of n in ℤr
*
We find r = 5.
(ii) Check that n has no “small factors”
Really checking no factors in [2, log n * √φ(r)] = [2, log(1993)*√4]
= [2, 21.92])
2, 3, 4, 5, …, 21 are not factors ✓
Note: √1993 ≈ 44.643 – AKS checks less than half as many
numbers as possible factors
59
Example Continued
(Is n = 1993 prime?)
1.Check (x + a)n ≡ xn + a (mod n, xr - 1)
for a up to the same value (log n* √φ(r))
So for 1 ≤ a ≤ 21 check
(x + a)1993 ≡ x1993 + a (mod 1993, x5 - 1) ✓
Result: n = 1993 passed all 3 tests. So 1993 is prime.
61
Significance
•Determines whether n is prime or composite in
polynomial time
•AKS Test is an iff statement
•If pass the test then n is definitely prime
•If fail the test then n is definitely composite
67
Work Cited
•Linowitz, Benjamin. An Exposition of the AKS Polynomial
Time Primality Testing
•Stay, Michael, Primes is in P, slowly.
•Crandall, Richard, and Carl Pomerance. Prime Numbers:
A Computational Perspective. New York: Springer,
2005.
•Agrawal, Manindra; Kayal, Neeraj; Saxena, Nitin (2004).
"PRIMES is in P"
71

More Related Content

What's hot

Chomsky Hierarchy.ppt
Chomsky Hierarchy.pptChomsky Hierarchy.ppt
Chomsky Hierarchy.ppt
AayushSingh233965
 
TOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite AutomataTOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite Automata
Mohammad Imam Hossain
 
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...
Vaibhav Khanna
 
Non regular languages
Non regular languagesNon regular languages
Non regular languageslavishka_anuj
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
University of Science and Technology Chitttagong
 
Digital Signature.ppt
Digital Signature.pptDigital Signature.ppt
Digital Signature.ppt
SABITHARASSISTANTPRO
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
sanchi29
 
ChaCha20-Poly1305 Cipher Summary - AdaLabs SPARKAda OpenSSH Ciphers
ChaCha20-Poly1305 Cipher Summary - AdaLabs SPARKAda OpenSSH CiphersChaCha20-Poly1305 Cipher Summary - AdaLabs SPARKAda OpenSSH Ciphers
ChaCha20-Poly1305 Cipher Summary - AdaLabs SPARKAda OpenSSH Ciphers
AdaLabs
 
Message Authentication Code & HMAC
Message Authentication Code & HMACMessage Authentication Code & HMAC
Message Authentication Code & HMAC
Krishna Gehlot
 
Automata theory -- NFA and DFA construction
Automata theory -- NFA and DFA  constructionAutomata theory -- NFA and DFA  construction
Automata theory -- NFA and DFA construction
Akila Krishnamoorthy
 
John the ripper & hydra password cracking tool
John the ripper & hydra password cracking toolJohn the ripper & hydra password cracking tool
John the ripper & hydra password cracking tool
Md. Raquibul Hoque
 
String matching, naive,
String matching, naive,String matching, naive,
String matching, naive,
Amit Kumar Rathi
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
baran19901990
 
Automata theory -RE to NFA-ε
Automata theory -RE to  NFA-εAutomata theory -RE to  NFA-ε
Automata theory -RE to NFA-ε
Akila Krishnamoorthy
 
RSA algorithm
RSA algorithmRSA algorithm
RSA algorithm
Arpana shree
 
Recurrence relation
Recurrence relationRecurrence relation
Recurrence relation
Ajay Chimmani
 
Time complexity
Time complexityTime complexity
Time complexity
Katang Isip
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
Mohammed Hussein
 
Information and data security digital signatures
Information and data security digital signaturesInformation and data security digital signatures
Information and data security digital signatures
Mazin Alwaaly
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
Deepmala Sharma
 

What's hot (20)

Chomsky Hierarchy.ppt
Chomsky Hierarchy.pptChomsky Hierarchy.ppt
Chomsky Hierarchy.ppt
 
TOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite AutomataTOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite Automata
 
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...
 
Non regular languages
Non regular languagesNon regular languages
Non regular languages
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
 
Digital Signature.ppt
Digital Signature.pptDigital Signature.ppt
Digital Signature.ppt
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
ChaCha20-Poly1305 Cipher Summary - AdaLabs SPARKAda OpenSSH Ciphers
ChaCha20-Poly1305 Cipher Summary - AdaLabs SPARKAda OpenSSH CiphersChaCha20-Poly1305 Cipher Summary - AdaLabs SPARKAda OpenSSH Ciphers
ChaCha20-Poly1305 Cipher Summary - AdaLabs SPARKAda OpenSSH Ciphers
 
Message Authentication Code & HMAC
Message Authentication Code & HMACMessage Authentication Code & HMAC
Message Authentication Code & HMAC
 
Automata theory -- NFA and DFA construction
Automata theory -- NFA and DFA  constructionAutomata theory -- NFA and DFA  construction
Automata theory -- NFA and DFA construction
 
John the ripper & hydra password cracking tool
John the ripper & hydra password cracking toolJohn the ripper & hydra password cracking tool
John the ripper & hydra password cracking tool
 
String matching, naive,
String matching, naive,String matching, naive,
String matching, naive,
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
Automata theory -RE to NFA-ε
Automata theory -RE to  NFA-εAutomata theory -RE to  NFA-ε
Automata theory -RE to NFA-ε
 
RSA algorithm
RSA algorithmRSA algorithm
RSA algorithm
 
Recurrence relation
Recurrence relationRecurrence relation
Recurrence relation
 
Time complexity
Time complexityTime complexity
Time complexity
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Information and data security digital signatures
Information and data security digital signaturesInformation and data security digital signatures
Information and data security digital signatures
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 

Viewers also liked

UNIUYO Admission List for 2015/2016 Pre-degree Students www.alluniversitynews...
UNIUYO Admission List for 2015/2016 Pre-degree Students www.alluniversitynews...UNIUYO Admission List for 2015/2016 Pre-degree Students www.alluniversitynews...
UNIUYO Admission List for 2015/2016 Pre-degree Students www.alluniversitynews...
Mbadinuju Chiemeka Valentine B.Sc
 
Christian castillo el aula virtual en apoyo a clases presenciales
Christian castillo el aula virtual en apoyo a clases presencialesChristian castillo el aula virtual en apoyo a clases presenciales
Christian castillo el aula virtual en apoyo a clases presenciales
Conectarnos Soluciones de Internet
 
Método de Loci - Roberto Funck
Método de Loci - Roberto FunckMétodo de Loci - Roberto Funck
Método de Loci - Roberto Funck
Conectarnos Soluciones de Internet
 
La importancia de estar bien posicionado - Tips SEO y posicionamiento en busc...
La importancia de estar bien posicionado - Tips SEO y posicionamiento en busc...La importancia de estar bien posicionado - Tips SEO y posicionamiento en busc...
La importancia de estar bien posicionado - Tips SEO y posicionamiento en busc...
Conectarnos Soluciones de Internet
 
Alethea Robyn Wicht CV 2017
Alethea Robyn Wicht CV 2017Alethea Robyn Wicht CV 2017
Alethea Robyn Wicht CV 2017Alethea Wicht
 
12 Steps to Dominate Your Marketing With Video
12 Steps to  Dominate Your Marketing  With Video12 Steps to  Dominate Your Marketing  With Video
12 Steps to Dominate Your Marketing With Video
Christina Hawkins
 
La valoración didáctica de experiencias universitarias en b learning
La valoración didáctica de experiencias universitarias en b learningLa valoración didáctica de experiencias universitarias en b learning
La valoración didáctica de experiencias universitarias en b learning
Conectarnos Soluciones de Internet
 
UNIUYO Basic Studies Placement: Direct Entry Admission List for 2015/2016 Bas...
UNIUYO Basic Studies Placement: Direct Entry Admission List for 2015/2016 Bas...UNIUYO Basic Studies Placement: Direct Entry Admission List for 2015/2016 Bas...
UNIUYO Basic Studies Placement: Direct Entry Admission List for 2015/2016 Bas...
Mbadinuju Chiemeka Valentine B.Sc
 
Joining the Conversation: Fundamentals of Social Media
Joining the Conversation: Fundamentals of Social MediaJoining the Conversation: Fundamentals of Social Media
Joining the Conversation: Fundamentals of Social Media
Andrea Karpala
 
UNIUYO 2016/17 3rd SCE Supplementary Admission List www.alluniversitynews.com
UNIUYO 2016/17 3rd SCE Supplementary Admission List www.alluniversitynews.comUNIUYO 2016/17 3rd SCE Supplementary Admission List www.alluniversitynews.com
UNIUYO 2016/17 3rd SCE Supplementary Admission List www.alluniversitynews.com
Mbadinuju Chiemeka Valentine B.Sc
 
Uniuyo sce admission list 2015 www.alluniversitynews.com
Uniuyo sce admission list 2015 www.alluniversitynews.comUniuyo sce admission list 2015 www.alluniversitynews.com
Uniuyo sce admission list 2015 www.alluniversitynews.com
Mbadinuju Chiemeka
 
Premalignant Skin Conditions
Premalignant Skin ConditionsPremalignant Skin Conditions
Premalignant Skin Conditions
Ibrahim Farag
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-Presented
SlideShare
 

Viewers also liked (14)

UNIUYO Admission List for 2015/2016 Pre-degree Students www.alluniversitynews...
UNIUYO Admission List for 2015/2016 Pre-degree Students www.alluniversitynews...UNIUYO Admission List for 2015/2016 Pre-degree Students www.alluniversitynews...
UNIUYO Admission List for 2015/2016 Pre-degree Students www.alluniversitynews...
 
Christian castillo el aula virtual en apoyo a clases presenciales
Christian castillo el aula virtual en apoyo a clases presencialesChristian castillo el aula virtual en apoyo a clases presenciales
Christian castillo el aula virtual en apoyo a clases presenciales
 
Método de Loci - Roberto Funck
Método de Loci - Roberto FunckMétodo de Loci - Roberto Funck
Método de Loci - Roberto Funck
 
La importancia de estar bien posicionado - Tips SEO y posicionamiento en busc...
La importancia de estar bien posicionado - Tips SEO y posicionamiento en busc...La importancia de estar bien posicionado - Tips SEO y posicionamiento en busc...
La importancia de estar bien posicionado - Tips SEO y posicionamiento en busc...
 
Alethea Robyn Wicht CV 2017
Alethea Robyn Wicht CV 2017Alethea Robyn Wicht CV 2017
Alethea Robyn Wicht CV 2017
 
12 Steps to Dominate Your Marketing With Video
12 Steps to  Dominate Your Marketing  With Video12 Steps to  Dominate Your Marketing  With Video
12 Steps to Dominate Your Marketing With Video
 
La valoración didáctica de experiencias universitarias en b learning
La valoración didáctica de experiencias universitarias en b learningLa valoración didáctica de experiencias universitarias en b learning
La valoración didáctica de experiencias universitarias en b learning
 
UNIUYO Basic Studies Placement: Direct Entry Admission List for 2015/2016 Bas...
UNIUYO Basic Studies Placement: Direct Entry Admission List for 2015/2016 Bas...UNIUYO Basic Studies Placement: Direct Entry Admission List for 2015/2016 Bas...
UNIUYO Basic Studies Placement: Direct Entry Admission List for 2015/2016 Bas...
 
Joining the Conversation: Fundamentals of Social Media
Joining the Conversation: Fundamentals of Social MediaJoining the Conversation: Fundamentals of Social Media
Joining the Conversation: Fundamentals of Social Media
 
UNIUYO 2016/17 3rd SCE Supplementary Admission List www.alluniversitynews.com
UNIUYO 2016/17 3rd SCE Supplementary Admission List www.alluniversitynews.comUNIUYO 2016/17 3rd SCE Supplementary Admission List www.alluniversitynews.com
UNIUYO 2016/17 3rd SCE Supplementary Admission List www.alluniversitynews.com
 
Uniuyo sce admission list 2015 www.alluniversitynews.com
Uniuyo sce admission list 2015 www.alluniversitynews.comUniuyo sce admission list 2015 www.alluniversitynews.com
Uniuyo sce admission list 2015 www.alluniversitynews.com
 
Premalignant Skin Conditions
Premalignant Skin ConditionsPremalignant Skin Conditions
Premalignant Skin Conditions
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-Presented
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similar to Introduction to the AKS Primality Test

how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
YekoyeTigabuYeko
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
mustafa sarac
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
Soujanya V
 
AsymptoticAnalysis.ppt
AsymptoticAnalysis.pptAsymptoticAnalysis.ppt
AsymptoticAnalysis.ppt
SiddheshUpadhyay3
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
pallavidhade2
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
sohelranasweet
 
factoring
factoringfactoring
factoring
Harish Sahu
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexityAbbas Ali
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
KarthikeyaLanka1
 
Quantum factorization.pdf
Quantum factorization.pdfQuantum factorization.pdf
Quantum factorization.pdf
ssuser8b461f
 
introduction to algorithm for beginneer1
introduction to algorithm for beginneer1introduction to algorithm for beginneer1
introduction to algorithm for beginneer1
ranjankumarbehera14
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
KokilaK25
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabist
Gatewayggg Testeru
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
smruti sarangi
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
A Szemeredi-type theorem for subsets of the unit cube
A Szemeredi-type theorem for subsets of the unit cubeA Szemeredi-type theorem for subsets of the unit cube
A Szemeredi-type theorem for subsets of the unit cube
VjekoslavKovac1
 
04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx
arslanzaheer14
 

Similar to Introduction to the AKS Primality Test (20)

how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
AsymptoticAnalysis.ppt
AsymptoticAnalysis.pptAsymptoticAnalysis.ppt
AsymptoticAnalysis.ppt
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
factoring
factoringfactoring
factoring
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
 
Quantum factorization.pdf
Quantum factorization.pdfQuantum factorization.pdf
Quantum factorization.pdf
 
introduction to algorithm for beginneer1
introduction to algorithm for beginneer1introduction to algorithm for beginneer1
introduction to algorithm for beginneer1
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabist
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
A Szemeredi-type theorem for subsets of the unit cube
A Szemeredi-type theorem for subsets of the unit cubeA Szemeredi-type theorem for subsets of the unit cube
A Szemeredi-type theorem for subsets of the unit cube
 
04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx
 

Recently uploaded

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 

Recently uploaded (20)

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 

Introduction to the AKS Primality Test

  • 1. The AKS Primality Test Pranshu Bhatnagar Chennai Mathematical Institute Indraprastha Institute of Information Technology 11 th June 2015
  • 2. Introduction to Primality Testing •Goal: given an integer n > 1, determine whether n is prime •Most people know the smallest primes •2, 3, 5, 7, 11, 13, 17, 19, 23, … •What about: •38,476? No, because it is even •4,359? No, because the sum of the digits is 21, a multiple of 3 •127? Yes, because it does not have any factors < √127 ≈ 11.27 •257,885,161 − 1? •This has over 17 million digits. We need better tests… 2
  • 3. 3 Categories For some arithmetic statement S which is easy to check: 1.n is prime ⇒ S(n) •pseudoprimes •strong pseudoprimes 1.S(n) ⇒ n is prime •n-1 test (Lucas Theorem) •n+1 test (Lucas-Lehmer) 1.S(n) ⇔ n is prime •AKS test 3
  • 4. n is prime ⇒ S(n) •S(n): n = 2 or n is odd •S(n): n = 3 or sum of digits of n is not divisible by 3 •¬ S(n) ⇒ n is composite •S(n) ⇒ ? 5
  • 5. Pseudoprimes •n prime ⇒ S(n) •S-pseudoprime: n is composite but S(n) holds •S(n): n = 2 or n is odd •n = 15 is a pseudoprime 7
  • 6. Intro to Modular Arithmetic •a ≡ b (mod n) •Formally n|(a-b) •a/n leaves remainder b •Clocks keep time (mod 12) •16:30 (military time) ≡ 4:30 pm •8:00 am + 7 hours = 15:00 ≡ 3 pm •Subtract the modulus until the result is small enough •11 ≡ 4 (mod 7) •35 ≡ 0 (mod 5) •23 = 8 ≡ 2 (mod 3) 11
  • 7. Fermat Pseudoprimes •n prime ⇒ S(n) •S is based on Fermat’s Little Theorem: If n is prime then an ≡ a (mod n), ∀a∈ℤ •S(n): an ≡ a (mod n) •Fermat pseudoprime: n is composite but an ≡ a (mod n) for some a 13
  • 8. Examples n prime ⇒ an ≡ a (mod n) •Let n = 91 •Composite: 91 = 7 * 13 •391 ≡ 3 (mod 91) •91 is a Fermat pseudoprime base 3 •291 ≠ 2 (mod 91) •91 is not a Fermat pseudoprime base 2 (91 is composite) •Note: Most probably, ∃ infinite Carmichael numbers, composites with an ≡ a (mod n) for every a 17
  • 9. S(n) ⇒ n is prime •n is composite ⇒ ¬ S(n) •¬ S(n) ⇒ ? 19
  • 10. The n-1 Test •S is based on the Lucas Theorem: If an-1 ≡ 1 (mod n) but a(n-1)/q ≠ 1 (mod n) ∀ prime q|n-1, then n is prime (for some a∈ℤ) •S(n): an-1 ≡ 1 (mod n) but a(n-1)/q ≠ 1 (mod n) 23
  • 11. Example [an-1 ≡ 1 (mod n) but a(n-1)/q ≠ 1 (mod n)] ⇒ n prime •Let n = 19 •n-1 = 18 = 2 * 32 •Let a = 2 218 ≡ 1 (mod 19) 29 ≡ 18 (mod 19) 26 ≡ 7 (mod 19) • So 19 is prime 29
  • 12. Another Example [an-1 ≡ 1 (mod n) but a(n-1)/q ≠ 1 (mod n)] ⇒ n prime •S(n) ⇒ n is prime •¬ S(n) ⇒ ? •Let n = 13, a = 5 •n-1 = 12 = 22 * 3 512 ≡ 1 (mod 13) 56 ≡ 12 (mod 13) But 54 ≡ 1 (mod 13) •S(n) is false, but n = 13 is prime 31
  • 13. S(n) ⇔ n is prime •S(n) ⇒ n is prime •¬ S(n) ⇒ n is composite •Theorem: Given some a with gcd(a,n) = 1: n is prime iff (x + a)n ≡ xn + a (mod n) •S(n): (x + a)n ≡ xn + a (mod n) 37
  • 14. Example S(n): (x + a)n ≡ xn + a (mod n) •(x+4)7 = x7 + 28x6 + 336x5 + 2240x4 + 8960x3 + 21504x2 + 28672x + 16384 ≡ x7 + 4 (mod 7) •7 is prime •(x+3)4 = x4 + 12x3 + 54x2 + 108x + 81 ≡ x4 + 2x2 + 1 (mod 4) ≠ x4 + 3 •4 is composite 41
  • 15. Improvement: The AKS Theorem •Agrawal-Kayal-Saxena (AKS) Theorem: n is prime iff •n is not a power, •n has no small factors, •(x + a)n ≡ xn + a (mod n, xr - 1) for certain r and small values of a 43
  • 16. The AKS Algorithm 47 Input: n ≥ 1 STEP 1. If ∃a, b > 1 ∈ N such that n = ab , then Output COMPOSITE; STEP 2. Find the minimal r ∈ N such that or(n) > log2(n); STEP 3. For a = 1 to r do if 1 < (a, n) < n, then Output COMPOSITE; STEP 4. if r ≥ n, then Output PRIME ; STEP 5. For a = 1 to do if (x + a)n ≡ xn + a (mod xr − 1, n), then Output COMPOSITE; STEP 6. Output PRIME;
  • 18. n is prime ⇒ S(n) ln is certainly not of the form ab for any a, b > 1, so lSTEP 1 will not output COMPOSITE. lSince n is prime, we also know that ∀x ∈ N, (n, x) = 1 or n. Hence STEP 3 will not output composite either. lWe have seen that for any prime n, (x+a)n ≡ xn+a (mod n), so STEP 5 will not output COMPOSITE. lTherefore the algorithm will output PRIME
  • 19. S(n) ⇒ n is prime lIf the algorithm returns PRIME during STEP 4, then we know that ∀m < n, (m, n) = 1 (this was checked in STEP 3), meaning n is prime. lThe remaining case, in which the algorithm returns PRIME during STEP 6, will take considerably more effort and require some extra machinery.
  • 22. Basic Operations lLet n, m ∈ N. Then lComputing m + n takes O(||n|| + ||m||) = O(log(n) + log(m)) bit operations. lComputing m · n takes O(||n|| · ||m||) = O(log(n) · log(m)) bit operations. lComputing the quotient n div m and the remainder n mod m takes O((||n|| −||m|| + 1) · ||m||) bit operations.
  • 23. Basic Operations lLet m, n ∈ N with at most k bits each. Then: lm and n can be multiplied with O(k(log(k))(loglogk)) = O ~(k) bit operations. ln div m and n mod m can be computed using O(k(log(k))(log logk)) = O ~(k) bit operations. lMultiplication of two polynomials of degree d with coefficients at most m bits in size can be done in O ~(d · m) bit operations.
  • 24. Euclidean Algorithm lInput: m, n ∈ Z l0: a, b integer; l1: if |n| ≥ |m| l2: then a ← |n|; b ← |m|; l3: else b ← |m|; a ← |n|; l4: while b > 0 repeat l5: (a, b) ← (b, a mod b); //i.e., ai = bi−1 , bi = ai−1 mod bi−1 l6: return a; lThis algorithm runs in O(log(n) · log(m)).
  • 25. Fast Modular Exponentiation lLet n = 2a 1 + 2a 2 + · · · + 2a l where a1 > a2 > · · · > al. lDefine f0 := (x + a), lfi+1(x) = fi(x)2 (mod xr − 1, n). lThen faj(x) = (x + a)aj . lIf we further define g1(x) := fa1(x) and gk(x)≡gk−1(x) fk (x) (mod xr − 1, n), then we see that lgl(x) ≡ (x + a)2a 1 +···+2a l = (x + a) n (mod x r − 1, n). lWe have therefore computed (x + a)n (mod xr − 1, n) in a1 + l ≤ 2log(n) steps, where a step consists of multiplying two polynomials of degree less than r with coefficients in Z/nZ. This leads to a total runtime of O ∼(r·log2 (n)).
  • 26. Perfect power Test lInput : n ∈ N l0: a, b, c, m integer l1: b ← 2 l2: while (b ≤ log(n)) do l3: a=1;c=m; l4: while c − a ≥ 2 do l5: m ← (a + c) div 2; l6: p ← min {mb , 1}; l7: if p = n then return "n is a perfect power"; l8: if p < n then a ← m else c ← m; l9: b ← b + 1; l10: return "n is not a perfect power." lLoop 1 will run at most log(n) times. Also, it will take at most log(n) iterations of loop 2 before |c − a| ≤ 1. During each iteration of loop 2, we calculate (a + c) div 2 and mb , which can be done in O ~(log(n)) bit operations. lThe complexity of the entire algorithm is therefore O ∼(log3(n)).
  • 27. Overall STEP 1 At most O∼(log3(n)) bit operations. STEP 2 We know that there exists an r< log5(n) such that or(n) > log2(n) .The easiest way to find such an r is simply to calculate nk(mod r) for k = 1, 2, ..., log2(n). This involves O(log2(n)) multiplications modulo r for each r, so STEP 2 takes O∼(log7(n)) bit operations. STEP 3 While determining whether (a,n)> 1 for some a ≤ r, computing each gcd takes O∼(log2(n)) bit operations using the Euclidean Algorithm, resulting in a total of O∼(log7(n)) bit operations
  • 28. Overall STEP 5 Given a ≤ , calculating (x + a)n in the ring Z/nZ as reducing modulo xr − 1 is trivial (simply replace xs by x(s−r)). In order to calculate (x+a)n, we must perform O(log(n)) multiplications of polynomials of degree<r with coefficients of size O(log(n)) (as the coefficients are written modulo n; recall that all polynomials are reduced modulo xr −1 during Fast Modular Exponentiation).Each congruence therefore takes O∼(log7(n)) bit operations to verify. This step therefore takes O∼( log(n) log7(n)) = O∼( log8(n)) = O∼(log21/2(n)) bit operations. The complexity of STEP 5 clearly dominates the complexity of the other steps, so the overall complexity of the algorithm is O∼(log10.5(n)), which is indeed polynomial.
  • 29. Example •Is n = 1993 prime? 1.1993 is not a power ✓ 53
  • 30. Example Continued (Is n = 1993 prime?) 1.(i) Find “certain r:” Really finding the least integer r > log2n with order of n in ℤr * We find r = 5. (ii) Check that n has no “small factors” Really checking no factors in [2, log n * √φ(r)] = [2, log(1993)*√4] = [2, 21.92]) 2, 3, 4, 5, …, 21 are not factors ✓ Note: √1993 ≈ 44.643 – AKS checks less than half as many numbers as possible factors 59
  • 31. Example Continued (Is n = 1993 prime?) 1.Check (x + a)n ≡ xn + a (mod n, xr - 1) for a up to the same value (log n* √φ(r)) So for 1 ≤ a ≤ 21 check (x + a)1993 ≡ x1993 + a (mod 1993, x5 - 1) ✓ Result: n = 1993 passed all 3 tests. So 1993 is prime. 61
  • 32. Significance •Determines whether n is prime or composite in polynomial time •AKS Test is an iff statement •If pass the test then n is definitely prime •If fail the test then n is definitely composite 67
  • 33. Work Cited •Linowitz, Benjamin. An Exposition of the AKS Polynomial Time Primality Testing •Stay, Michael, Primes is in P, slowly. •Crandall, Richard, and Carl Pomerance. Prime Numbers: A Computational Perspective. New York: Springer, 2005. •Agrawal, Manindra; Kayal, Neeraj; Saxena, Nitin (2004). "PRIMES is in P" 71

Editor's Notes

  1. 1