Formalizing Refinements and Constructive Algebra in Type
Total Page:16
File Type:pdf, Size:1020Kb
Thesis for the Degree of Doctor of Philosophy Formalizing Refinements and Constructive Algebra in Type Theory Anders Mortberg¨ Department of Computer Science and Engineering Chalmers University of Technology and University of Gothenburg SE-412 96 Gothenburg, Sweden Gothenburg, 2014 Formalizing Refinements and Constructive Algebra in Type Theory Anders Mortberg¨ ISBN 978-91-982237-0-5 © Anders Mortberg,¨ 2014 Technical Report no. 115D96 Department of Computer Science and Engineering Programming Logic Research Group Department of Computer Science and Engineering Chalmers University of Technology and University of Gothenburg SE-412 96 Gothenburg, Sweden Printed at Chalmers Reproservice Gothenburg, Sweden 2014 Abstract The extensive use of computers in mathematics and engineering has led to an increased demand for reliability in the implementation of algorithms in com- puter algebra systems. One way to increase the reliability is to formally verify that the implementations satisfy the mathematical theorems stating their spec- ification. By implementing and specifying algorithms from computer algebra inside a proof assistant both the reliability of the implementation and the com- putational capabilities of the proof assistant can be increased. This first part of the thesis presents a framework, developed in the interac- tive theorem prover Coq, for conveniently implementing and reasoning about program and data refinements. In this framework programs defined on rich dependent types suitable for proofs are linked to optimized implementations on simple types suitable for computation. The correctness of the optimized algorithms is established on the proof-oriented types and then automatically transported to the computation-oriented types. This method has been applied to develop a library containing multiple algorithms from computational alge- bra, including: Karatsuba’s polynomial multiplication, Strassen’s matrix mul- tiplication and the Sasaki-Murao algorithm for computing the characteristic polynomial of matrices over commutative rings. The second part of the thesis presents the formalization of notions from constructive algebra. Focus is on the theory of coherent and strongly discrete rings, which provides a general setting for developing linear algebra over rings instead of fields. Examples of such rings include Bezout´ domains, Prufer¨ domains and elementary divisor rings. Finitely presented modules over these rings are implemented using an abstraction layer on top of matrices. This enables us to constructively prove that the category of these modules form a suitable setting for developing homological algebra. We further show that any finitely presented module over an elementary divisor ring can be decomposed to a direct sum of a free module and cyclic modules in a unique way. This decomposition gives a decision procedure for testing if two finitely presented modules are isomorphic. i ii List of publications This thesis is based on the work contained in the following papers: 1. A Refinement-Based Approach to Computational Algebra in Coq. Maxime Den´ es,` Anders Mortberg¨ and Vincent Siles. In Interactive Theorem Proving, volume 7406 of Lectures Notes in Computer Science, pages 83–98. Springer, 2012. 2. Refinements for free!. Cyril Cohen, Maxime Den´ es` and Anders Mortberg.¨ In Certified Programs and Proofs, volume 8307 of Lecture Notes in Computer Science, pages 147–162. Springer, 2013. 3. A Formal Proof of Sasaki-Murao Algorithm. Thierry Coquand, Anders Mortberg¨ and Vincent Siles. Journal of Formalized Reasoning, 5(1):27–36, 2012. 4. Coherent and Strongly Discrete Rings in Type Theory. Thierry Coquand, Anders Mortberg¨ and Vincent Siles. In Certified Programs and Proofs, vol- ume 7679 of Lecture Notes in Computer Science, pages 273–288. Springer, 2012. 5. A Coq Formalization of Finitely Presented Modules. Cyril Cohen and Anders Mortberg.¨ In Interactive Theorem Proving, volume 8558 of Lecture Notes in Computer Science, pages 193–208. Springer, 2014. 6. Formalized Linear Algebra over Elementary Divisor Rings in Coq. Guil- laume Cano, Cyril Cohen, Maxime Den´ es,` Anders Mortberg¨ and Vincent Siles. Preprint, 2014. The following papers are related but not included in the thesis: Towards a Certified Computation of Homology Groups for Digital Images. Jonathan´ Heras, Maxime Den´ es,` Gadea Mata, Anders Mortberg,¨ Mar´ıa Poza and Vincent Siles. In Computational Topology in Image Context, volume 7309 of Lecture Notes In Computer Science, pages 49–57. Springer, 2012. Computing Persistent Homology Within Coq/SSReflect. Jonathan´ Heras, Thierry Coquand, Anders Mortberg¨ and Vincent Siles. ACM Transactions on Computational Logic, 14(4):1–26, 2013. iii Statement of contribution The authors’ contributions to each of the papers included in the thesis are: 1. Implementation of list based polynomials and the algebraic hierarchy of computational structures. Wrote the sections on these and participated in writing the other sections. 2. Collaborated on developing the library and designing the methodology. Implemented the theory on sparse polynomials. Writing was distributed evenly among the authors. 3. Mainly contributed to the formalization of the correctness proof and the implementation of the efficient version of the algorithm. 4. Contributed to all parts, both formalization and writing. Implemented the executable versions and correctness proof of the algorithms and structures. 5. Collaborated on the formalization and wrote most parts of the paper. 6. Contributed to all parts of the formalization, in particular to the theory of rings with explicit divisibility, the proof that elementary divisor rings are coherent and the development on the Kaplansky condition. Wrote parts of most sections of the paper. iv Contents Introduction1 1 Software verification..........................1 2 Formalization of mathematics.....................5 3 This thesis................................7 3.1 Method..............................8 3.2 Formal developments.....................8 3.3 Structure and organization of the thesis...........9 4 Program and data refinements....................9 4.1 A refinement-based approach to computational algebra in Coq.............................. 10 4.2 Refinements for free!...................... 11 4.3 A formal proof of the Sasaki-Murao algorithm....... 12 5 Constructive algebra in type theory................. 13 5.1 Coherent and strongly discrete rings in type theory.... 13 5.2 A Coq formalization of finitely presented modules.... 14 5.3 Formalized linear algebra over elementary divisor rings in Coq.............................. 15 I Program and Data Refinements 17 1 A Refinement-Based Approach to Computational Algebra in Coq 19 1.1 Introduction............................... 19 1.2 Refinements............................... 20 1.3 Matrices................................. 21 1.3.1 Representation......................... 22 1.3.2 Computing the rank...................... 23 1.3.3 Strassen’s fast matrix product................. 24 1.4 Polynomials............................... 26 1.4.1 Karatsuba’s fast polynomial multiplication......... 27 1.4.2 Computing the gcd of multivariate polynomials...... 29 1.5 Hierarchy of computable structures................. 30 1.5.1 Design of the library...................... 31 1.5.2 Example: computable ring of polynomials......... 32 1.5.3 Examples of computations.................. 33 1.6 Conclusions and future work..................... 33 v 2 Refinements for free! 35 2.1 Introduction............................... 35 2.2 Data refinements............................ 37 2.2.1 Refinement relations...................... 37 2.2.2 Comparison with the previous approach.......... 40 2.2.3 Indexing and using refinements............... 41 2.3 Generic programming......................... 41 2.4 Parametricity.............................. 42 2.4.1 Splitting refinement relations................. 42 2.4.2 Parametricity for refinements................. 43 2.4.3 Generating the parametricity lemma............. 44 2.5 Example: Strassen’s fast matrix product............... 44 2.6 Related work............................... 47 2.7 Conclusions and future work..................... 48 3 A Formal Proof of the Sasaki-Murao Algorithm 51 3.1 Introduction............................... 51 3.2 The Sasaki-Murao algorithm..................... 52 3.2.1 Matrices............................. 52 3.2.2 The algorithm.......................... 54 3.3 Correctness proof............................ 54 3.4 Representation in type theory..................... 56 3.5 Conclusions and benchmarks..................... 60 II Constructive Algebra in Type Theory 61 4 Coherent and Strongly Discrete Rings in Type Theory 63 4.1 Introduction............................... 63 4.2 Coherent rings.............................. 64 4.2.1 Ideal intersection and coherence............... 66 4.3 Strongly discrete rings......................... 67 4.3.1 Ideal theory........................... 68 4.3.2 Coherent strongly discrete rings............... 69 4.3.3 Bezout´ domains are coherent and strongly discrete.... 70 4.4 Prufer¨ domains............................. 71 4.4.1 Principal localization matrices and strong discreteness.. 71 4.4.2 Coherence............................ 73 4.4.3 Examples of Prufer¨ domains................. 74 4.5 Computations.............................. 74 4.6 Conclusions and future work..................... 76 5 A Coq Formalization of Finitely Presented Modules 79 5.1 Introduction............................... 79 5.2 Finitely presented modules.....................