A Purely Functional Library for Modular Arithmetic and Its Application to Certifying Large Prime Numbers

  • Benjamin Grégoire
  • Laurent Théry
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4130)


Computing efficiently with numbers can be crucial for some theorem proving applications. In this paper, we present a library of modular arithmetic that has been developed within the Coq proof assistant. The library proposes the usual operations that have all been proved correct. The library is purely functional but can also be used on top of some native modular arithmetic. With this library, we have been capable of certifying the primality of numbers with more than 13000 digits.


Recursive Call Base Word Complete Binary Tree Modular Arithmetic Large Prime Number 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    GNU Multiple Precision Arithmetic Library,
  2. 2.
    Barendregt, H., Barendsen, E.: Autarkic computations in formal proofs. J. Autom. Reasoning 28(3), 321–336 (2002)MATHCrossRefMathSciNetGoogle Scholar
  3. 3.
    Bertot, Y., Magaud, N., Zimmermann, P.: A proof of GMP square root. Journal of Automated Reasoning 29(3-4), 225–252 (2002)MATHCrossRefMathSciNetGoogle Scholar
  4. 4.
    Boutin, S.: Using Reflection to Build Efficient and Certified Decision Procedures. In: Ito, T., Abadi, M. (eds.) TACS 1997. LNCS, vol. 1281, pp. 515–529. Springer, Heidelberg (1997)CrossRefGoogle Scholar
  5. 5.
    Brillhart, J., Lehmer, D.H., Selfridge, J.L.: New primality criteria and factorizations of 2m ±1. Mathematics of Computation 29, 620–647 (1975)MATHMathSciNetGoogle Scholar
  6. 6.
    Burnikel, C., Ziegler, J.: Fast recursive division. Technical Report MPI-I-98-1-022, Max-Planck-Institut (1998)Google Scholar
  7. 7.
    Caprotti, O., Oostdijk, M.: Formal and efficient primality proofs by use of computer algebra oracles. Journal of Symbolic Computation 32(1/2), 55–70 (2001)MATHCrossRefMathSciNetGoogle Scholar
  8. 8.
    Crandall, R., Fagin, B.: Discrete weighted transforms and large-integer arithmetic.  62(205), 305–324 (1994)Google Scholar
  9. 9.
    Gonthier, G.: A computer-checked proof of the Four Colour Theorem. Technical report, available at
  10. 10.
    Grégoire, B., Leroy, X.: A compiled implementation of strong reduction. In: International Conference on Functional Programming 2002, pp. 235–246. ACM Press, New York (2002)Google Scholar
  11. 11.
    Grégoire, B., Mahboubi, A.: Proving ring equalities done right in Coq. In: Hurd, J., Melham, T. (eds.) TPHOLs 2005. LNCS, vol. 3603, pp. 98–113. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  12. 12.
    Grégoire, B., Théry, L., Werner, B.: A computational approach to Pocklington certificates in type theory. In: Hagiya, M., Wadler, P. (eds.) FLOPS 2006. LNCS, vol. 3945, pp. 97–113. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  13. 13.
    Harrison, J., Théry, L.: A skeptic’s approach to combining HOL and Maple. J. Autom. Reasoning 21(3), 279–294 (1998)MATHCrossRefGoogle Scholar
  14. 14.
    Karatsuba, A.A., Ofman, Y.: Multiplication of Many-Digital Numbers by Automatic Computers. Soviet Physics-Doklad 7, 595–596 (1963)Google Scholar
  15. 15.
    Leroy, X.: Objective Caml (1997), available at
  16. 16.
    Ménissier-Morain, V.: The CAML Numbers Reference Manual. Technical Report 141, INRIA (1992)Google Scholar
  17. 17.
    Nipkow, T., Bauer, G., Schultz, P.: Flyspeck I: Tame Graphs. Technical report, available at
  18. 18.
    The Coq development team. The Coq Proof Assistant Reference Manual v7.2. Technical Report 255, INRIA (2002), available at
  19. 19.
    Zimmermann, P.: Karatsuba square root. Research Report 3805, INRIA (1999)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Benjamin Grégoire
    • 1
  • Laurent Théry
    • 1
  1. 1.INRIA Sophia-AntipolisFrance

Personalised recommendations