Skip to main content
Log in

Mechanisation of the AKS Algorithm

  • Published:
Journal of Automated Reasoning Aims and scope Submit manuscript

Abstract

The AKS algorithm (by Agrawal, Kayal and Saxena) is a significant theoretical result, establishing “PRIMES in P” by a brilliant application of ideas from finite fields. This paper describes an implementation of the AKS algorithm in our theorem prover HOL4, together with a proof of its correctness and its computational complexity. The complexity analysis is based on a conservative computation model using a writer monad. The method is elementary, but enough to show that our implementation of the AKS algorithm takes a number of execution steps bounded by a polynomial function of the input size. This establishes formally that the AKS algorithm indeed shows “PRIMES is in P”.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Aaronson, S.: The prime facts: From Euclid to AKS (2003). http://www.scottaaronson.com/writings/prime.pdf. Accessed 13 June 2020

  2. Agrawal, M.: A short history of “PRIMES is in P”. In: 33rd International Colloquium on Automata, Languages and Programming, ICALP 2006, Venice, Italy (2006)

  3. Agrawal, M.: Primality tests based on Fermat’s Little theorem. In: Chaudhuri, S., Das, S.R., Paul, H.S., Tirthapura, S. (eds.) Distributed Computing and Networking. Number 4308 in Theoretical Computer Science and General Issues, pp. 288–293. Springer, Berlin (2006)

    Google Scholar 

  4. Agrawal, M., Kayal, N., Saxena, N.: PRIMES is in P (2002). Original paper by the AKS team. http://www.cse.iitk.ac.in/users/manindra/algebra/primality_original.pdf. Accessed 13 June 2020

  5. Agrawal, M., Kayal, N., Saxena, N.: PRIMES is in P. Ann. Math. 160(2), 781–793 (2004)

    Article  MathSciNet  Google Scholar 

  6. Avanzini, M., Dal Lago, U., Moser, G.: Analysing the complexity of functional programs: higher-order meets first-order. In: Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming, ICFP 2015, pp. 152–164, New York, NY, USA. Association for Computing Machinery (2015)

  7. Avigad, J., Donnelly, K., Formalizing, O.: Notation in Isabelle, HOL. In: Basin, D., Rusinowitch, M. (eds.) Automated Reasoning. Lecture Notes in Computer Science, vol. 3097, pp. 357–371. Springer, Berlin. IJCAR (2004)

  8. Bagnara, R., Pescetti, A., Zaccagnini, A., Zaffanella, E.: PURRS: towards computer algebra support for fully automatic worst-case complexity analysis. CoRR (2005). arXiv:cs/0512056

  9. Benzinger, R.: Automated higher-order complexity analysis. Theor. Comput. Sci. 318, 79–103 (2004)

    Article  MathSciNet  Google Scholar 

  10. Bernstein, D.J.: An Exposition of the Agrawal–Kayal–Saxena Primality Proving Theorem (2002). https://wstein.org/edu/Fall2002/124/refs/aks.pdf. Accessed 13 June 2020

  11. Bornemann, F.: PRIMES Is in P: a breakthrough for everyman. Not. AMS 50(5), 545–552 (2003)

    MathSciNet  MATH  Google Scholar 

  12. Brent, R.P.: Primality testing. Technical report, Mathematical Sciences Institute, ANU (2010). https://maths-people.anu.edu.au/~brent/pd/comp4600_primality.pdf. Accessed 13 June 2020

  13. Campos, C., Modave, F., Roach, S.: Towards the verification of the AKS primality test in ACL2. In: 5th International Conference on Intelligent Technologies (2004)

  14. Chan, H.L.: Primality testing is polynomial-time: a mechanised verification of the AKS algorithm. Ph.D., Australian National University, Canberra, Australia (2019). https://openresearch-repository.anu.edu.au/handle/1885/177195. Accessed 13 June 2020

  15. Chan, H.L., Norrish, M.: A string of pearls: proofs of Fermat’s Little theorem. J. Formaliz. Reason. 6(1), 63–87 (2013)

    MathSciNet  MATH  Google Scholar 

  16. Chan, H.L., Norrish, M.: Mechanisation of AKS algorithm: part 1—the main theorem. In: Urban, C., Zhang, X. (eds.) Interactive Theorem Proving, ITP 2015, Number 9236 in LNCS, pp. 117–136. Springer, Berlin (2015)

    Google Scholar 

  17. Chan, H.L., Norrish, M.: Classification of finite fields with applications. J. Autom. Reason. 63(3), 667–693 (2019)

    Article  MathSciNet  Google Scholar 

  18. Chan, H.L., Norrish, M.: Proof pearl: bounding least common multiples with triangles. J. Autom. Reason. 62(2), 171–192 (2019)

    Article  MathSciNet  Google Scholar 

  19. Crandall, R., Pomerance, C.: Prime Numbers: A Computational Perspective. Springer, Berlin (2005)

    MATH  Google Scholar 

  20. Daleson, G.: Deterministic primality testing in polynomial time. Master’s thesis, Portland State University (2006)

  21. de Moura, F.L.C., Tadeu, R.: The Correctness of the AKS Primality Test in Coq (2008). http://www.cic.unb.br/~flavio/AKS.pdf. Accessed 13 June 2020

  22. Dietzfelbinger, M.: Primality Testing in Polynomial Time: From Randomized Algorithms to ‘PRIMES is in P’. Lecture Notes in Computer Science. Springer (2004)

  23. EATCS: Gödel Prize by European Association for Theoretical Computer Science. In: 33rd International Colloquium on Automata, Languages and Programming, ICALP (2006)

  24. Eberl, M.: Proving divide and conquer complexities in Isabelle/HOL. J. Autom. Reason. 58(4), 483–508 (2017)

    Article  MathSciNet  Google Scholar 

  25. Haslbeck, M.P.L., Nipkow, T.: Hoare logics for time bounds: a study in meta theory. In: Beyer, D., Huisman, M. (eds.) Tools and Algorithms for the Construction and Analysis of Systems, pp. 155–171. Springer International Publishing, Cham (2018)

    Chapter  Google Scholar 

  26. Hurd, J.: Verification of the Miller–Rabin Probabilistic Primality Test. Elsevier Science Inc., Amsterdam (2003). https://doi.org/10.1016/S1567-8326(02)00065-6

    Book  MATH  Google Scholar 

  27. Jouannaud, J.-P., Weiwen, X.: Automatic complexity analysis for programs extracted from Coq proof. Electron. Not. Theor. Comput. Sci. 153(1), 35–53 (2006)

    Article  Google Scholar 

  28. Knuth, D.E.: The Art of Computer Programming: Seminumerical Algorithms, vol. 2, 3rd edn. Addison-Wesley Longman Publishing Co. Inc, Boston (1998)

    MATH  Google Scholar 

  29. Le Métayer, D.: ACE: an automatic complexity evaluator. ACM Trans. Program. Lang. Syst. 10(2), 248–266 (1988)

    Article  Google Scholar 

  30. Lenstra, H.W.: Primality testing with Gaussian periods. In: Agrawal, M., Seth, A. (eds.) FST TCS 2002: Foundations of Software Technology and Theoretical Computer Science. Lecture Notes in Computer Science, vol. 2556, pages 1–1. Springer, Berlin (2002)

  31. Nair, M.: On Chebyshev-type inequalities for primes. Am. Math. Mon. 89(2), 126–129 (1982)

    Article  MathSciNet  Google Scholar 

  32. Rempe-Gillen, L., Waldecker, R.: Primality testing for beginners, Student Mathematical Library, vol. 70. American Mathematical Society (2014)

  33. Robinson, S.: New method said to solve key problem in math (2002). https://www.nytimes.com/2002/08/08/us/new-method-said-to-solve-key-problem-in-math.html. Accessed 13 June 2020

  34. Rosendahl, M.: Automatic complexity analysis. In: Proceedings of the 4th International Conference on Functional Programming Languages and Computer Architecture, FPCA’89, pp. 144–156, New York, NY, USA. Association for Computing Machinery (1989)

  35. Schoof, R.: Four primality testing algorithms. Algorithmic Number Theory, MSRI Publications, vol. 44, pp. 101–126 (2008). http://www.mat.uniroma2.it/~schoof/05rene.pdf. Accessed 13 June 2020

  36. Shoup, V.: A Computational Introduction to Number Theory and Algebra, 1st edn. Cambridge University Press, Cambridge (2008)

    Book  Google Scholar 

  37. Tao, T.: The AKS primality test. In his blog (2009). http://terrytao.wordpress.com/2009/08/11/the-aks-primality-test/. Accessed 13 June 2020

  38. Théry, L.: Proving pearl: Knuth’s algorithm for prime numbers. In: Basin, D., Wolff, B. (eds.) Theorem Proving in Higher Order Logics, pp. 304–318. Springer, Berlin (2003)

    Chapter  Google Scholar 

  39. Laurent Théry: The Correctness of the AKS algorithm, a direct transcription. In: Coq (2019). https://github.com/thery/mathcomp-extra/blob/master/aks.v

  40. von zur Gathen, J., Gerhard, J.: Modern Computer Algebra, 3rd edn. Cambridge University Press, Cambridge (2013)

    Book  Google Scholar 

  41. Wiedijk, F., Harrison’s, J.: Formalization of the Agrawal–Kayal–Saxena primality test. Intercity Number Theory Seminar, Nijmegen (2003). http://www.cs.ru.nl/~freek/talks/intercity.dvi. Accessed 13 June 2020

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Hing Lun Chan.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Chan, H.L., Norrish, M. Mechanisation of the AKS Algorithm. J Autom Reasoning 65, 205–256 (2021). https://doi.org/10.1007/s10817-020-09563-y

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10817-020-09563-y

Keywords

Navigation