Type classes for efficient exact real arithmetic in Coq

Floating point operations are fast, but require continuous effort on the part of the user in order to ensure that the results are correct. This burden can be shifted away from the user by providing a library of exact analysis in which the computer handles the error estimates. Previously, we [Krebbers/Spitters 2011] provided a fast implementation of the exact real numbers in the Coq proof assistant. Our implementation improved on an earlier implementation by O'Connor by using type classes to describe an abstract specification of the underlying dense set from which the real numbers are built. In particular, we used dyadic rationals built from Coq's machine integers to obtain a 100 times speed up of the basic operations already. This article is a substantially expanded version of [Krebbers/Spitters 2011] in which the implementation is extended in the various ways. First, we implement and verify the sine and cosine function. Secondly, we create an additional implementation of the dense set based on Coq's fast rational numbers. Thirdly, we extend the hierarchy to capture order on undecidable structures, while it was limited to decidable structures before. This hierarchy, based on type classes, allows us to share theory on the naturals, integers, rationals, dyadics, and reals in a convenient way. Finally, we obtain another dramatic speed-up by avoiding evaluation of termination proofs at runtime.

[1]  Guillaume Melquiond,et al.  Flocq: A Unified Library for Proving Floating-Point Algorithms in Coq , 2011, 2011 IEEE 20th Symposium on Computer Arithmetic.

[2]  Martin Hofmann,et al.  Extensional Constructs in Intensional Type Theory , 1997, CPHC/BCS Distinguished Dissertations.

[3]  Henry Cheng Constructive mathematics and computer science , 1972, ACM '72.

[4]  Christine Paulin-Mohring,et al.  The coq proof assistant reference manual , 2000 .

[5]  Russell O'Connor,et al.  Certified Exact Transcendental Real Number Computation in Coq , 2008, TPHOLs.

[6]  A. Troelstra,et al.  Constructivism in Mathematics: An Introduction , 1988 .

[7]  Assia Mahboubi,et al.  Packaging Mathematical Structures , 2009, TPHOLs.

[8]  Warwick Tucker,et al.  Foundations of Computational Mathematics a Rigorous Ode Solver and Smale's 14th Problem , 2022 .

[9]  Pierre Letouzey Extraction in Coq: An Overview , 2008, CiE.

[10]  Thierry Coquand,et al.  Inductively defined types , 1988, Conference on Computer Logic.

[11]  Davorin Le,et al.  Synthetic Topology and Constructive Metric Spaces , 2021, 2104.10399.

[12]  Yves Bertot,et al.  Affine functions and series with co-inductive real numbers , 2006, Mathematical Structures in Computer Science.

[13]  Bas Spitters,et al.  Type classes for mathematics in type theory† , 2011, Mathematical Structures in Computer Science.

[14]  Thomas C. Hales A computer verification of the Kepler conjecture , 2003 .

[15]  Andrej Bauer,et al.  Implementing Real Numbers With RZ , 2008, CCA.

[16]  Nicolas Julien Certified Exact Real Arithmetic Using Co-induction in Arbitrary Integer Base , 2008, FLOPS.

[17]  Luís Cruz-Filipe,et al.  A Large-Scale Experiment in Executing Extracted Programs , 2006, Calculemus.

[18]  E. Bishop Foundations of Constructive Analysis , 2012 .

[19]  Eugenio Moggi,et al.  Computational lambda-calculus and monads , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[20]  Andrej Bauer,et al.  The Dedekind reals in abstract Stone duality , 2009, Mathematical Structures in Computer Science.

[21]  Enrico Tassi,et al.  Interactive theorem provers: issues faced as a user and tackled as a developer , 2008 .

[22]  Matthieu Sozeau A New Look at Generalized Rewriting in Type Theory , 2009, J. Formaliz. Reason..

[23]  Assia Mahboubi,et al.  Formal proofs in real algebraic geometry: from ordered fields to quantifier elimination , 2012, Log. Methods Comput. Sci..

[24]  Ulrich Berger,et al.  From Coinductive Proofs to Exact Real Arithmetic , 2009, CSL.

[25]  Stephen Wolfram,et al.  A New Kind of Science , 2003, Artificial Life.

[26]  Enrico Tassi,et al.  A Small Scale Reflection Extension for the Coq system , 2008 .

[27]  Derek Dreyer,et al.  How to make ad hoc proof automation less ad hoc , 2011, ICFP '11.

[28]  Fred Richman,et al.  Real numbers and other completions , 2008, Math. Log. Q..

[29]  Bas Spitters,et al.  Program Extraction from Large Proof Developments , 2003, TPHOLs.

[30]  Herman Geuvers,et al.  A Constructive Algebraic Hierarchy in Coq , 2002, J. Symb. Comput..

[31]  Herman Geuvers,et al.  C-CoRN, the Constructive Coq Repository at Nijmegen , 2004, MKM.

[32]  Cyril Cohen,et al.  Construction of Real Algebraic Numbers in Coq , 2012, ITP.

[33]  Claudio Sacerdoti Coen,et al.  Nonuniform Coercions via Unification Hints , 2009, TYPES.

[34]  Yves Bertot,et al.  Interactive Theorem Proving and Program Development: Coq'Art The Calculus of Inductive Constructions , 2010 .

[35]  Benjamin Grégoire,et al.  Extending Coq with Imperative Features and Its Application to SAT Verification , 2010, ITP.

[36]  Benjamin Grégoire,et al.  Full Reduction at Full Throttle , 2011, CPP.

[37]  R.S.S. O'Connor,et al.  Incompleteness & completeness : formalizing logic and analysis in type theory , 2005 .

[38]  Per Martin-Löf,et al.  An intuitionistic theory of types , 1972 .

[39]  Assia Mahboubi,et al.  Implementing the cylindrical algebraic decomposition within the Coq system , 2007, Mathematical Structures in Computer Science.

[40]  Andrej Bauer,et al.  A constructive theory of continuous domains suitable for implementation , 2009, Ann. Pure Appl. Log..

[41]  Benjamin Grégoire,et al.  A compiled implementation of strong reduction , 2002, ICFP '02.

[42]  Erik Palmgren,et al.  Constructivist and structuralist foundations: Bishop's and Lawvere's theories of sets , 2012, Ann. Pure Appl. Log..

[43]  Bas Spitters,et al.  Computer Certified Efficient Exact Reals in Coq , 2011, Calculemus/MKM.

[44]  Andrea Asperti,et al.  User Interaction with the Matita Proof Assistant , 2007, Journal of Automated Reasoning.

[45]  Andrea Asperti,et al.  Hints in Unification , 2009, TPHOLs.

[46]  Matthieu Sozeau,et al.  A Gentle Introduction to Type Classes and Relations in Coq , 2012 .

[47]  Pierre Castéran,et al.  Interactive Theorem Proving and Program Development , 2004, Texts in Theoretical Computer Science An EATCS Series.

[48]  Thierry Coquand,et al.  The Calculus of Constructions , 1988, Inf. Comput..

[49]  Robert Pollack Dependently Typed Records in Type Theory , 2002, Formal Aspects of Computing.

[50]  Ioana Pasca,et al.  Formal Verification of Exact Computations Using Newton's Method , 2009, TPHOLs.

[51]  Matthieu Sozeau,et al.  First-Class Type Classes , 2008, TPHOLs.

[52]  Philip Wadler,et al.  Monads for functional programming , 1995, NATO ASI PDC.

[53]  Russell O'Connor A monadic, functional implementation of real numbers , 2007, Math. Struct. Comput. Sci..

[54]  Bas Spitters,et al.  A computer-verified monadic functional implementation of the integral , 2008, Theor. Comput. Sci..