Abstract
This paper proposes a new approach to writing and verifying divide-and-conquer programs in Coq. Extending the rich line of previous work on algebraic approaches to recursion schemes, we present an algebraic approach to divide-and-conquer recursion: recursions are represented as a form of algebra, and from outer recursions, one may initiate inner recursions that can construct data upon which the outer recursions may legally recurse. Termination is enforced entirely by the typing discipline of our recursion schemes. Despite this, our approach requires little from the underlying type system, and can be implemented in System Fω plus a limited form of positive-recursive types. Our implementation of the method in Coq does not rely on structural recursion or on dependent types. The method is demonstrated on several examples, including mergesort, quicksort, Harper’s regular-expression matcher, and others. An indexed version is also derived, implementing a form of divide-and-conquer induction that can be used to reason about functions defined via our method.
- Pedro Abreu, Benjamin Delaware, Alex Hubers, Christa Jenkins, J. Garrett Morris, and Aaron Stump. 2023. A Type-Based Approach to Divide-And-Conquer Recursion in Coq: POPL'23 Artifact. Zenodo. https://doi.org/10.5281/zenodo.7305612
Google Scholar
Digital Library
- Reynald Afeldt and David Nowak. 2021. Extending Equational Monadic Reasoning with Monad Transformers. In 26th International Conference on Types for Proofs and Programs (TYPES 2020 ) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 188 ), Ugo de'Liguoro, Stefano Berardi, and Thorsten Altenkirch (Eds.). Schloss Dagstuhl-Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 2 : 1-2 : 21. https://doi.org/10.4230/LIPIcs.TYPES. 2020.2
Google Scholar
Cross Ref
- Ki Yung Ahn and Tim Sheard. 2011. A Hierarchy of Mendler Style Recursion Combinators: Taming Inductive Datatypes with Negative Occurrences. In Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming (Tokyo, Japan) ( ICFP '11). ACM, New York, NY, USA, 234-246.
Google Scholar
Digital Library
- Robert Atkey. 2012. Relational Parametricity for Higher Kinds. In Computer Science Logic (CSL'12)-26th International Workshop/21st Annual Conference of the EACSL, CSL 2012, September 3-6, 2012, Fontainebleau, France (LIPIcs, Vol. 16 ), Patrick Cégielski and Arnaud Durand (Eds.). Schloss Dagstuhl-Leibniz-Zentrum für Informatik, 46-61. https://doi.org/ 10.4230/LIPIcs.CSL. 2012.46
Google Scholar
Cross Ref
- Gilles Barthe, Julien Forest, David Pichardie, and Vlad Rusu. 2006. Defining and Reasoning About Recursive Functions: A Practical Tool for the Coq Proof Assistant. In Functional and Logic Programming, 8th International Symposium, FLOPS 2006, Fuji-Susono, Japan, April 24-26, 2006, Proceedings (Lecture Notes in Computer Science, Vol. 3945 ), Masami Hagiya and Philip Wadler (Eds.). Springer, 114-129. https://doi.org/10.1007/11737414_9
Google Scholar
Digital Library
- Gilles Barthe, Maria João Frade, Eduardo Giménez, Luís Pinto, and Tarmo Uustalu. 2004a. Type-based termination of recursive definitions. Mathematical Structures in Computer Science 14, 1 ( 2004 ), 97-141. https://doi.org/10.1017/S0960129503004122
Google Scholar
Digital Library
- Gilles Barthe, Maria João Frade, Eduardo Giménez, Luís Pinto, and Tarmo Uustalu. 2004b. Type-based termination of recursive definitions. Math. Struct. Comput. Sci. 14, 1 ( 2004 ), 97-141. https://doi.org/10.1017/S0960129503004122
Google Scholar
Digital Library
- J. L. Bell. 1993. Hilbert's epsilon-Operator and Classical Logic. Journal of Philosophical Logic 22, 1 (Feb 01 1993 ), 1. http://login.proxy.lib.uiowa.edu/login?url=https://www.proquest.com/scholarly-journals/hilberts-epsilon-operatorclassical-logic/docview/1292914019/se-2 Last updated-2013-02-22.
Google Scholar
Cross Ref
- Jean-Philippe Bernardy and Marc Lasson. 2011. Realizability and Parametricity in Pure Type Systems. In Foundations of Software Science and Computational Structures-14th International Conference, FOSSACS 2011, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2011, Saarbrücken, Germany, March 26-April 3, 2011. Proceedings (Lecture Notes in Computer Science, Vol. 6604 ), Martin Hofmann (Ed.). Springer, 108-122. https: //doi.org/10.1016/j.tcs. 2006. 12.042
Google Scholar
Cross Ref
- Julian Biendarra, Jasmin Christian Blanchette, Aymeric Bouzy, Martin Desharnais, Mathias Fleury, Johannes Hölzl, Ondrej Kuncar, Andreas Lochbihler, Fabian Meier, Lorenz Panny, Andrei Popescu, Christian Sternagel, René Thiemann, and Dmitriy Traytel. 2017. Foundational (Co)datatypes and (Co)recursion for Higher-Order Logic. In Frontiers of Combining Systems-11th International Symposium, FroCoS 2017, Brasília, Brazil, September 27-29, 2017, Proceedings (Lecture Notes in Computer Science, Vol. 10483 ), Clare Dixon and Marcelo Finger (Eds.). Springer, 3-21. https://doi.org/10.1007/978-3-319-66167-4_1
Google Scholar
Cross Ref
- Richard S. Bird and Oege de Moor. 1997. Algebra of programming. Prentice Hall.
Google Scholar
- Frédéric Blanqui. 2005. Inductive types in the Calculus of Algebraic Constructions. Fundam. Informaticae 65, 1-2 ( 2005 ), 61-86. http://content.iospress.com/articles/fundamenta-informaticae /fi65-1-2-04
Google Scholar
- Ana Bove and Venanzio Capretta. 2005. Modelling general recursion in type theory. Mathematical Structures in Computer Science 15, 4 ( 2005 ), 671-708. https://doi.org/10.1017/S0960129505004822
Google Scholar
Digital Library
- Ana Bove, Alexander Krauss, and Matthieu Sozeau. 2016. Partiality and recursion in interactive theorem provers-an overview. Mathematical Structures in Computer Science 26, 1 ( 2016 ), 38-88. https://doi.org/10.1017/S0960129514000115
Google Scholar
Cross Ref
- Joachim Breitner, Antal Spector-Zabusky, Yao Li, Christine Rizkallah, John Wiegley, Joshua M. Cohen, and Stephanie Weirich. 2021. Ready, Set, Verify! Applying hs-to-coq to real-world Haskell code. J. Funct. Program. 31 ( 2021 ), e5. https://doi.org/10.1017/S0956796820000283
Google Scholar
Cross Ref
- Jonathan Chan and William J. Bowman. 2019. Practical Sized Typing for Coq. CoRR abs/ 1912.05601 ( 2019 ). arXiv: 1912.05601 http://arxiv.org/abs/ 1912.05601
Google Scholar
- Arthur Charguéraud. 2010. The Optimal Fixed Point Combinator. In Interactive Theorem Proving, Matt Kaufmann and Lawrence C. Paulson (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 195-210.
Google Scholar
- Arthur Charguéraud. 2021. The TLC Coq Library. https://github.com/charguer/tlc
Google Scholar
- Guillaume Claret. 2021. Coq of Ocaml. https://github.com/clarus/coq-of-ocaml. Accessed: 2021-09-09.
Google Scholar
- Robin Cockett and Dwight Spencer. 1992. Strong Categorical Datatypes I. In International Meeting on Category Theory 1991 (Canadian Mathematical Society Proceedings), R. A. G. Seely (Ed.). AMS.
Google Scholar
- Ernesto Copello, Alvaro Tasistro, and Bruno Bianchi. 2014. Case of (Quite) Painless Dependently Typed Programming: Fully Certified Merge Sort in Agda. In Programming Languages-18th Brazilian Symposium, SBLP 2014, Maceio, Brazil, October 2-3, 2014. Proceedings (Lecture Notes in Computer Science, Vol. 8771 ), Fernando Magno Quintão Pereira (Ed.). Springer, 62-76.
Google Scholar
Cross Ref
- T. Coquand and G. Huet. 1988. The Calculus of Constructions. Information and Computation 76, 2-3 ( 1988 ), 95-120.
Google Scholar
Digital Library
- Thierry Coquand and Christine Paulin. 1988. Inductively defined types. In COLOG-88, International Conference on Computer Logic, Tallinn, USSR, December 1988, Proceedings (Lecture Notes in Computer Science, Vol. 417 ), Per Martin-Löf and Grigori Mints (Eds.). Springer, 50-66. https://doi.org/10.1007/3-540-52335-9_47
Google Scholar
Cross Ref
- Leonardo Mendonça de Moura, Soonho Kong, Jeremy Avigad, Floris van Doorn, and Jakob von Raumer. 2015. The Lean Theorem Prover (System Description). In Automated Deduction-CADE-25-25th International Conference on Automated Deduction, Berlin, Germany, August 1-7, 2015, Proceedings (Lecture Notes in Computer Science, Vol. 9195 ), Amy P. Felty and Aart Middeldorp (Eds.). Springer, 378-388. https://doi.org/10.1007/978-3-319-21401-6_26
Google Scholar
Cross Ref
- Benjamin Delaware, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2013a. Meta-Theory à La Carte. SIGPLAN Not. 48, 1 (jan 2013 ), 207-218. https://doi.org/10.1145/2480359.2429094
Google Scholar
Digital Library
- Benjamin Delaware, Steven Keuchel, Tom Schrijvers, and Bruno C.d. S. Oliveira. 2013b. Modular Monadic Meta-Theory. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (Boston, Massachusetts, USA) ( ICFP '13). Association for Computing Machinery, New York, NY, USA, 319-330. https://doi.org/10.1145/2500365.2500587
Google Scholar
Digital Library
- Denis Firsov, Richard Blair, and Aaron Stump. 2018. Eficient Mendler-Style Lambda-Encodings in Cedille. In Interactive Theorem Proving-9th International Conference, ITP 2018, Held as Part of the Federated Logic Conference, FloC 2018, Oxford, UK, July 9-12, 2018, Proceedings (Lecture Notes in Computer Science, Vol. 10895 ), Jeremy Avigad and Assia Mahboubi (Eds.). Springer, 235-252.
Google Scholar
Cross Ref
- Denis Firsov and Aaron Stump. 2018. Generic derivation of induction for impredicative encodings in Cedille. In Proceedings of the 7th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2018, Los Angeles, CA, USA, January 8-9, 2018, June Andronick and Amy P. Felty (Eds.). ACM, 215-227.
Google Scholar
- Gaëtan Gilbert, Jesper Cockx, Matthieu Sozeau, and Nicolas Tabareau. 2019. Definitional proof-irrelevance without K. Proc. ACM Program. Lang. 3, POPL ( 2019 ), 3 : 1-3 : 28. https://doi.org/10.1145/3290316
Google Scholar
Digital Library
- Tatsuya Hagino. 1987. A Categorical Programming Language. Ph. D. Dissertation. University of Edinburgh.
Google Scholar
- Robert Harper. 1999. Proof-directed debugging. Journal of Functional Programming 9, 4 ( 1999 ), 463-469. https://doi.org/10. 1017/S0956796899003378
Google Scholar
Digital Library
- John Hughes, Lars Pareto, and Amr Sabry. 1996. Proving the Correctness of Reactive Systems Using Sized Types. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (St. Petersburg Beach, Florida, USA) ( POPL '96). Association for Computing Machinery, New York, NY, USA, 410-423. https://doi.org/10.1145/237721.240882
Google Scholar
Digital Library
- Joomy Korkut, Maksim Trifunovski, and Daniel Licata. 2016. Intrinsic Verification of a Regular Expression Matcher. Unpublished, available from Licata's web site.
Google Scholar
- Alexander Krauss. 2010. Partial and Nested Recursive Function Definitions in Higher-order Logic. J. Autom. Reasoning 44, 4 ( 2010 ), 303-336. https://doi.org/10.1007/s10817-009-9157-2
Google Scholar
Digital Library
- Sava Krstić and John Matthews. 2003. Inductive Invariants for Nested Recursion. In Theorem Proving in Higher Order Logics, David Basin and Burkhart Wolf (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 253-269.
Google Scholar
- K. Rustan M. Leino. 2010. Dafny: An Automatic Program Verifier for Functional Correctness. In Logic for Programming, Artificial Intelligence, and Reasoning-16th International Conference, LPAR-16, Dakar, Senegal, April 25-May 1, 2010, Revised Selected Papers (Lecture Notes in Computer Science, Vol. 6355 ), Edmund M. Clarke and Andrei Voronkov (Eds.). Springer, 348-370. https://doi.org/10.1007/978-3-642-17511-4_20
Google Scholar
Cross Ref
- Standard library Coq. 2009. Sorting/Mergesort.v.
Google Scholar
- Ralph Matthes. 2009. An induction principle for nested datatypes in intensional type theory. J. Funct. Program. 19, 3-4 ( 2009 ), 439-468. https://doi.org/10.1017/S095679680900731X
Google Scholar
Digital Library
- John Matthews. 1999. Recursive Function Definition over Coinductive Types. In Theorem Proving in Higher Order Logics, 12th International Conference, TPHOLs'99, Nice, France, September, 1999, Proceedings (Lecture Notes in Computer Science, Vol. 1690 ), Yves Bertot, Gilles Dowek, André Hirschowitz, Christine Paulin-Mohring, and Laurent Théry (Eds.). Springer, 73-90. https://doi.org/10.1007/3-540-48256-3_6
Google Scholar
Cross Ref
- The Agda development team. 2016. Agda. http://wiki.portal.chalmers.se/agda/pmwiki. php Version 2.5.1.
Google Scholar
- The Coq development team. 2016. The Coq proof assistant reference manual. LogiCal Project. http://coq.inria. fr Version 8.5.
Google Scholar
- Conor McBride. 2002. Elimination with a Motive. In Types for Proofs and Programs, International Workshop, TYPES 2000, Durham, UK, December 8-12, 2000, Selected Papers (Lecture Notes in Computer Science, Vol. 2277 ), Paul Callaghan, Zhaohui Luo, James McKinna, and Robert Pollack (Eds.). Springer, 197-216.
Google Scholar
- N. P. Mendler. 1991. Inductive types and type constraints in the second-order lambda calculus. Annals of Pure and Applied Logic 51, 1 ( 1991 ), 159-172.
Google Scholar
Cross Ref
- Neil Mitchell. 2021. Data.List.Extra. https://hackage.haskell.org/package/extra-1.7.10/docs/Data-List-Extra.html
Google Scholar
- Tobias Nipkow, Lawrence C Paulson, and Markus Wenzel. 2002. Isabelle/HOL: a proof assistant for higher-order logic. Vol. 2283. Springer Science & Business Media.
Google Scholar
Digital Library
- Scott Owens and Konrad Slind. 2008. Adapting functional programs to higher order logic. Higher-Order and Symbolic Computation 21, 4 ( 2008 ), 377-409. https://doi.org/10.1007/s10990-008-9038-0
Google Scholar
Digital Library
- David Salomon and Giovanni Motta. 2009. Handbook of Data Compression. Springer.
Google Scholar
Cross Ref
- Matthieu Sozeau. 2006. Subset Coercions in Coq. In Types for Proofs and Programs, International Workshop, TYPES 2006, Nottingham, UK, April 18-21, 2006, Revised Selected Papers (Lecture Notes in Computer Science, Vol. 4502 ), Thorsten Altenkirch and Conor McBride (Eds.). Springer, 237-252. https://doi.org/10.1007/978-3-540-74464-1_16
Google Scholar
Cross Ref
- Matthieu Sozeau, Abhishek Anand, Simon Boulier, Cyril Cohen, Yannick Forster, Fabian Kunze, Gregory Malecha, Nicolas Tabareau, and Théo Winterhalter. 2020. The MetaCoq Project. Journal of Automated Reasoning 64, 5 ( 2020 ), 947-999. https://doi.org/10.1007/s10817-019-09540-0
Google Scholar
Digital Library
- Matthieu Sozeau and Cyprien Mangin. 2019. Equations reloaded: high-level dependently-typed functional programming and proving in Coq. Proc. ACM Program. Lang. 3, ICFP ( 2019 ), 86 : 1-86 : 29. https://doi.org/10.1145/3341690
Google Scholar
Digital Library
- Aaron Stump, Christopher Jenkins, Stephan Spahn, and Colin McDonald. 2020. Strong Functional Pearl: Harper's RegularExpression Matcher in Cedille. Proc. ACM Program. Lang. 4, ICFP, Article 122 ( Aug. 2020 ), 25 pages. https://doi.org/10. 1145/3409004
Google Scholar
Digital Library
- Wouter Swierstra. 2008. Data Types à La Carte. J. Funct. Program. 18, 4 ( July 2008 ), 423-436.
Google Scholar
Digital Library
- Dmitriy Traytel, Andrei Popescu, and Jasmin Christian Blanchette. 2012. Foundational, Compositional (Co)datatypes for Higher-Order Logic: Category Theory Applied to Theorem Proving. In Proceedings of the 27th Annual IEEE Symposium on Logic in Computer Science, LICS 2012, Dubrovnik, Croatia, June 25-28, 2012. IEEE Computer Society, 596-605. https: //doi.org/10.1109/LICS. 2012.75
Google Scholar
Cross Ref
- D. A. Turner. 1995. Elementary Strong Functional Programming. In Proceedings of the First International Symposium on Functional Programming Languages in Education (FPLE '95). Springer-Verlag, Berlin, Heidelberg, 1-13.
Google Scholar
Cross Ref
- Tarmo Uustalu and Varmo Vene. 1999. Mendler-style Inductive Types, Categorically. Nordic J. of Computing 6, 3 (Sept. 1999 ), 343-361.
Google Scholar
Digital Library
- Tarmo Uustalu and Varmo Vene. 2011. The Recursion Scheme from the Cofree Recursive Comonad. Electron. Notes Theor. Comput. Sci. 229, 5 ( 2011 ), 135-157. https://doi.org/10.1016/j.entcs. 2011. 02.020
Google Scholar
Cross Ref
- Hongwei Xi. 2002. Dependent Types for Program Termination Verification. Higher-Order and Symbolic Computation 15, 1 (March 2002 ), 91-131. https://doi.org/10.1023/A:1019916231463
Google Scholar
Digital Library
- Qianchuan Ye and Benjamin Delaware. 2022. Scrap your boilerplate definitions in 10 lines of Ltac!. In The Eighth International Workshop on Coq for Programming Languages.
Google Scholar
Index Terms
A Type-Based Approach to Divide-and-Conquer Recursion in Coq
Recommendations
Recursion Unrolling for Divide and Conquer Programs
LCPC '00: Proceedings of the 13th International Workshop on Languages and Compilers for Parallel Computing-Revised PapersThis paper presents recursion unrolling, a technique for improving the performance of recursive computations. Conceptually, recursion unrolling inlines recursive calls to reduce control flow overhead and increase the size of the basic blocks in the ...
A type system for well-founded recursion
POPL '04In the interest of designing a recursive module extension to ML that is as simple and general as possible, we propose a novel type system for general recursion over effectful expressions. The presence of effects seems to necessitate a backpatching ...
A type system for well-founded recursion
POPL '04: Proceedings of the 31st ACM SIGPLAN-SIGACT symposium on Principles of programming languagesIn the interest of designing a recursive module extension to ML that is as simple and general as possible, we propose a novel type system for general recursion over effectful expressions. The presence of effects seems to necessitate a backpatching ...






Comments