Presentation on theme: "AKS Implementation of a Deterministic Primality Algorithm"— Presentation transcript:
1AKS Implementation of a Deterministic Primality Algorithm R. Salembier & P. Southerington
2AKS Primality Test Deterministic primality-proving algorithm Manindra Agrawal, Neeraj Kaval, Nitin Saxena“PRIMES is in P,” 6 August 2002Determines whether a number is prime or composite.There is no probability associated as with Miller-Rabin Test
3Original AKS Algorithm August 6, 2002 version: 1. If (n = ab for a N and b > 1), output COMPOSITE.2. Find the smallest r such that Or(n) > 4 log2n3. If 1 < GCD(a, n) < n for all a ≤ r, output COMPOSITE.4. If n ≤ r, output PRIME.5. For a = 1 toif (( x + a)n xn + a (mod xr – 1, n))output COMPOSITE.6. Output PRIME.
4Lenstra/Pomerance Variant Revised version we are using: 1. If (n = ab for a N and b > 1), output COMPOSITE.2. Find the smallest r such that Or(n) > log2n3. If gcd(a, n) ≠ 1 for all a ≤ r, output COMPOSITE.4. For a = 1 toif (( x + a)n ≡ xn + a (mod xr-1, n)), output PRIME.
5Complexity Big-O Notation AKS runs in polynomial time Read as ‘order of’Indicates the dominant termAKS runs in polynomial timeOriginal: Õ (log12 (n))Lenstra/Pomerance: Õ (log7.5 (n))
6LiDIA Implementation Perfect Power Test GCD Test Exponentiation used native is_power() functionGCD TestInitially used gcd()Traditional method of GCD calculationChanged to bgcd()Eliminates divisionUses shifts and addsExponentiationLeft-to-Right ExpansionModular reduction at each step
7Division Optimization Split polynomial into three coefficient vectorsTerms with exponents > r-1Term with exponent r-1Terms with exponents < r-1Subtracted r from each exponent in first setAdded first and third vectors together
9Squaring “Optimization” Constructed squaring routineDealt with first and last terms individuallyLooped through all terms pairing together91% of test in squaring functionOperation times actually increasedConfirmed problem using GMP
10NTL Implementation Efficient polynomial multiplication LiDIA used only classical multiplicationNTL Automatically chooses from:Classical algorithmKaratsuba methodTwo Fast Fourier Transform (FFT) methodsDramatic performance increase50% of time spent in FFTMay be able to adjust selection boundaries
12NTL Potential Implement native Perfect Power test Currently falling back to GMPPossible Alternate ImplementationsManually reduce coefficientsRepresent polynomial directly as a ringLet NTL handle polynomial reduction
13Performance Comparison Crandall & Papadopoulis Apple / UMD
14Conjecture Improvement Improves time to Õ (log3 (n))Conjecture:If n mod r ≠ 0 mod r andIf (X – 1)n Ξ (Xn – 1) mod (Xr -1, n)And n2 mod r ≠ -1 mod rn is PRIMEFrom tests this appears to be trueIf tests holds for a =1 then it holds for all aConjecture is still not proven
16Future Work Native GMP Implementation Allow total control over polynomial operationsVery difficult to do more efficiently than NTLBernstein Exponentiation OptimizationMap polynomial ring onto integer ringQi Cheng MethodOne round of Elliptic Curve Primality TestOne iteration of AKS
17Conclusions Our implementation comparable to others’ NTL better suited to AKS than LiDIAAKS still too slow for practical useConjectureBernstein / Qi ChengFocus should be on algorithmic improvements