Hostname: page-component-8448b6f56d-tj2md Total loading time: 0 Render date: 2024-04-23T18:09:32.848Z Has data issue: false hasContentIssue false

Proof-relevant unification: Dependent pattern matching with only the axioms of your type theory

Published online by Cambridge University Press:  10 May 2018

JESPER COCKX
Affiliation:
Department of Computer Science and Engineering, Chalmers and Gothenburg University, Gothenburg, Sweden (e-mail: jesper@sikanda.be)
DOMINIQUE DEVRIESE
Affiliation:
Computer Science, KULeuven, Heverlee, Belgium (e-mail: dominique.devriese@cs.kuleuven.be)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

Dependently typed languages such as Agda, Coq, and Idris use a syntactic first-order unification algorithm to check definitions by dependent pattern matching. However, standard unification algorithms implicitly rely on principles such as uniqueness of identity proofs and injectivity of type constructors. These principles are inadmissible in many type theories, particularly in the new and promising branch known as homotopy type theory. As a result, programs and proofs in these new theories cannot make use of dependent pattern matching or other techniques relying on unification, and are as a result much harder to write, modify, and understand. This paper proposes a proof-relevant framework for reasoning formally about unification in a dependently typed setting. In this framework, unification rules compute not just a unifier but also a corresponding soundness proof in the form of an equivalence between two sets of equations. By rephrasing the standard unification rules in a proof-relevant manner, they are guaranteed to preserve soundness of the theory. In addition, it enables us to safely add new rules that can exploit the dependencies between the types of equations, such as rules for eta-equality of record types and higher dimensional unification rules for solving equations between equality proofs. Using our framework, we implemented a complete overhaul of the unification algorithm used by Agda. As a result, we were able to replace previous ad-hoc restrictions with formally verified unification rules, fixing a substantial number of bugs in the process. In the future, we may also want to integrate new principles with pattern matching, for example, the higher inductive types introduced by homotopy type theory. Our framework also provides a solid basis for such extensions to be built on.

Type
Research Article
Copyright
Copyright © Cambridge University Press 2018 

References

Abel, A. (2011) Irrelevance in type theory with a heterogeneous equality judgement. In Foundations of Software Science and Computational Structures, Hofmann, M. (ed). Berlin Heidelberg: Springer, pp. 5771. ISBN 978-3-642-19805-2.CrossRefGoogle Scholar
Abel, A. (2012) MiniAgda: Integrating sized and dependent types. In PAR-10. Partiality and Recursion in Interactive Theorem Provers, volume 5 of EPiC Series in Computing, Ekaterina, K., Ana, B. & Milad, N. (eds). EasyChair, pp. 1833. Available at: https://easychair.org/publications/paper/RM.Google Scholar
Abel, A. (2015a) Injectivity of type constructors is partially back. Agda refutes excluded middle. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/1406 (on the Agda bug tracker).Google Scholar
Abel, A. (2015b) Order of patterns matters for checking left hand sides. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/1411 (on the Agda bug tracker).Google Scholar
Abel, A. (2015c) Circumvention of forcing analysis brings back easy proof of Fin injectivity. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/1427 (on the Agda bug tracker).Google Scholar
Abel, A. (2015d) Eta-expanded implicit patterns are not used for instance search. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/1613 (on the Agda bug tracker).Google Scholar
Abel, A. & Pientka, B. (2011) Higher-order dynamic pattern unification for dependent types and records. In International Conference on Typed Lambda Calculi and Applications, TLCA. Springer, pp. 10–26.CrossRefGoogle Scholar
Asperti, A., Ricciotti, W., Sacerdoti Coen, C., & Tassi, E. (2009) Hints in unification. In Theorem Proving in Higher Order Logics, Berghofer, S., Nipkow, T., Urban, C. & Wenzel, M. (eds). Berlin, Heidelberg: Springer, pp. 8498. ISBN 978-3-642-03359-9.CrossRefGoogle Scholar
Baader, F. & Snyder, W. (2001) Unification theory. In Handbook of Automated Reasoning (in 2 volumes), Robinson, J. A. & Voronkov, A. (eds). Elsevier and MIT Press, pp. 445532. ISBN 0-444-50813-9.CrossRefGoogle Scholar
Bezem, M., Coquand, T., & Huber, S. (2014) A Model of Type Theory in Cubical Sets. In 19th International Conference on Types for Proofs and Programs (TYPES 2013), volume 26 of Leibniz International Proceedings in Informatics (LIPIcs), Matthes, R. & Schubert, A. (eds). Dagstuhl, Germany: Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, pp. 107–128. ISBN 978-3-939897-72-9. Accessed April 17, 2017. Available at: http://drops.dagstuhl.de/opus/volltexte/2014/4628.Google Scholar
Brady, E. (2013) Idris, a general-purpose dependently typed programming language: Design and implementation. J. Funct. Program. 23 (5): 552593.CrossRefGoogle Scholar
Brady, E., McBride, C., & McKinna, J. (2004) Inductive families need not store their indices. In Types for Proofs and Programs, Berardi, S., Coppo, M., & Damiani, F. (eds). Berlin, Heidelberg: Springer, pp. 115–29. ISBN 978-3-540-24849-1.CrossRefGoogle Scholar
Braibant, T. (2013) A new Coq tactic for inversion. Accessed April 17, 2017. Available at: http://gallium.inria.fr/blog/a-new-Coq-tactic-for-inversionGoogle Scholar
Cockx, J. (2017) Dependent Pattern Matching and Proof-Relevant Unification. PhD Thesis, KU Leuven.Google Scholar
Cockx, J. & Devriese, D. (2017) Lifting proof-relevant unification to higher dimensions. In Proceedings of the 6th Conference on Certified Programs and Proofs, CPP. ACM.CrossRefGoogle Scholar
Cockx, J., Devriese, D. & Piessens, F. (2014) Pattern matching without K. In Proceedings of the 19th International Conference on Functional Programming, ICFP. ACM.CrossRefGoogle Scholar
Cockx, J., Devriese, D. & Piessens, F. (2016a) Unifiers as equivalences: Proof-relevant unification of dependently typed data. In Proceedings of the 21th International Conference on Functional Programming, ICFP. ACM.CrossRefGoogle Scholar
Cockx, J., Devriese, D., & Piessens, F. (2016b) Eliminating dependent pattern matching without K. J. Funct. Program. 26, e16.CrossRefGoogle Scholar
Cohen, C., Coquand, T., Huber, S. & Mörtberg, A. (2016) Cubical type theory: A constructive interpretation of the univalence axiom. In CoRR. Accessed April 17, 2017. Available at: http://arxiv.org/abs/1611.02108Google Scholar
Coquand, T. (1992) Pattern matching with dependent types. In Proceedings of the 1992 Workshop on Types for Proofs and Programs, TYPES, Nordstrom, B., Petersson, K., & Plotkin, G. (eds). Chalmers University of Technology, pp. 66–79.Google Scholar
Cornes, C. & Terrasse, D. (1996) Automating inversion of inductive predicates in Coq. In Types for Proofs and Programs, Berardi, S. & Coppo, M. (eds). Berlin, Heidelberg: Springer, pp. 85104. ISBN 978-3-540-70722-6.CrossRefGoogle Scholar
Danielsson, N. A. (2010) Heterogenous equality is crippled by the Bool /= Fin 2 fix. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/292 (on the Agda bug tracker).Google Scholar
Danielsson, N. A. (2011) The unification machinery does not respect η-equality. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/473 (on the Agda bug tracker).Google Scholar
Danielsson, N. A. (2014) Regression in unifier, possibly related to modules and/or heterogeneous constraints. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/1071 (on the Agda bug tracker).Google Scholar
Danielsson, N. A. (2015) Dependent pattern matching is broken. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/1435 (on the Agda bug tracker).Google Scholar
de Bruijn, N. G. (1991) Telescopic mappings in typed lambda calculus. Inf. Comput. 91 (2), 189204. ISSN . Accessed April 17, 2017. Available at: http://www.sciencedirect.com/science/article/pii/089054019190066BCrossRefGoogle Scholar
de Moura, L., Kong, S., Avigad, J., van Doorn, F. & von Raumer, J. (2015) The Lean theorem prover (system description). In Proceedings of the 25th International Conference on Automated Deduction, CADE.CrossRefGoogle Scholar
Dijkstra, G. (2015) Disunifying non-fully applied constructors is inconsistent with function extensionality. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/1497 (on the Agda bug tracker).Google Scholar
Dybjer, P. (1991) Inductive sets and families in Martin-Löf's type theory and their set-theoretic semantics. In Proceedings of the 1st Workshop on Logical Frameworks.CrossRefGoogle Scholar
Goguen, H., McBride, C., & McKinna, J. (2006) Eliminating dependent pattern matching. In Algebra, Meaning, and Computation: Essays dedicated to Joseph A. Goguen on the Occasion of His 65th Birthday, Futatsugi, K., Jouannaud, J.-P., & Meseguer, J. (eds). Berlin, Heidelberg: Springer, pp. 521540. ISBN 978-3-540-35464-2.CrossRefGoogle Scholar
Goguen, Joseph A. (1989) What is unification?: A categorical view of substitution, equation and solution. In Algebraic Techniques, Aït-Kaci, H. & Nivat, M. (eds). Academic Press, pp. 217261. ISBN 978-0-12-046370-1.CrossRefGoogle Scholar
Hur, C. K. (2010) Agda with the excluded middle is inconsistent?. Accessed April 17, 2017. Available at: https://lists.chalmers.se/pipermail/agda/2010/001522.html (On the Agda mailing list).Google Scholar
Jouannaud, J.-P. & Kirchner, C. (1991) Solving equations in abstract algebras: A rule-based survey of unification. In Computational Logic - Essays in Honor of Alan Robinson, Lassez, J.-L. & Plotkin, G. D. (eds). The MIT Press, pp. 257321.Google Scholar
Licata, D. R. & Shulman, M. (2013) Calculating the fundamental group of the circle in homotopy type theory. In 28th Symposium on Logic in Computer Science, LICS.CrossRefGoogle Scholar
Luo, Z. (1994) Computation and Reasoning: A Type Theory for Computer Science, volume 11 of International Series of Monographs on Computer Science. New York, NY, USA: Oxford University Press, Inc. ISBN 0-19-853835-9.CrossRefGoogle Scholar
Martin-Löf, P. (1972) An intuitionistic theory of types. In Proceedings of the 25th Years of Constructive Type Theory (Venice, 1995). Oxford University Press, pp. 127–172.Google Scholar
Martin-Löf, P. (1984) Intuitionistic Type Theory, volume 1 of Studies in Proof Theory. Bibliopolis. ISBN 88-7088-105-9.Google Scholar
McBride, C. (1998a) Towards dependent pattern matching in LEGO. Unpublished.Google Scholar
McBride, C. (1998b) Inverting inductively defined relations in LEGO. In Types for Proofs and Programs, Giménez, E. & Paulin-Mohring, C. (eds). Berlin, Heidelberg: Springer, pp. 236253. ISBN 978-3-540-49562-8.CrossRefGoogle Scholar
McBride, C. (2000) Dependently Typed Functional Programs and their Proofs. PhD Thesis, University of Edinburgh.Google Scholar
McBride, C. (2002) Elimination with a motive. In Types for Proofs and Programs, Callaghan, P., Luo, Z., McKinna, J., & Pollack, R. (eds). Berlin, Heidelberg: Springer, pp. 197216. ISBN 978-3-540-45842-5.CrossRefGoogle Scholar
McBride, C., Goguen, H., & McKinna, J. (2006) A few constructions on constructors. In Types for Proofs and Programs, Filliâtre, J.-C., Paulin-Mohring, C., and Werner, B. (eds). Berlin, Heidelberg: Springer, pp. 186200. ISBN 978-3-540-31429-5.CrossRefGoogle Scholar
McKinna, J. & Forsberg, F. N. (2015) The Encode-Decode Method, Relationally, Institute of Cybernetics at Tallinn University of Technology, pp. 6364. ISBN 978-9949-430-86-4.Google Scholar
Miquel, A. (2010) Re: Agda with the excluded middle is inconsistent?. Accessed April 17, 2017. Available at: https://lists.chalmers.se/pipermail/agda/2010/001543.html (Proof posted by Chung-Kil Hur on the Agda mailing list).Google Scholar
Monin, J.-F. (2010) Proof Trick: Small Inversions. In Second Coq Workshop, Bertot, Y. (ed). Edinburgh, U.K. Accessed April 17, 2017. Available at: https://hal.inria.fr/inria-00489412.Google Scholar
Norell, U. (2007) Towards a Practical Programming Language Based on Dependent Type Theory. PhD Thesis, Chalmers University of Technology.Google Scholar
Peebles, D. (2012) Case splitting emits hidden record patterns that should remain implicit. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/635 (on the Agda bug tracker).Google Scholar
Reed, J. (2009) Higher-order constraint simplification in dependent type theory. In Proceedings of the 4th International Workshop on Logical Frameworks and Meta-Languages: Theory and Practice. ACM, pp. 49–56.CrossRefGoogle Scholar
Sicard-Ramírez, A. (2016) The –without-K option generates unsolved metas. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/1775 (on the Agda bug tracker).Google Scholar
Sozeau, M. (2010) Equations: A dependent pattern-matching compiler. In Interactive Theorem Proving, Kaufmann, M. & Paulson, L. C. (eds). Berlin, Heidelberg: Springer, pp. 419434. ISBN 978-3-642-14052-5.CrossRefGoogle Scholar
Streicher, T. (1993) Investigations into intensional type theory. Habilitation thesis, Ludwig Maximilian University of Munich.Google Scholar
The Univalent Foundations Program. (2013) Homotopy Type Theory: Univalent Foundations of Mathematics. Accessed April 17, 2017. Available at: http://homotopytypetheory.org/book, Institute for Advanced Study.Google Scholar
Vezzosi, A. (2015) Heterogeneous equality incompatible with univalence even –without-k. Accessed April 17, 2017. Available at: https://github.com/agda/agda/issues/1408 (on the Agda bug tracker).Google Scholar
Ziliani, B. & Sozeau, M. (2015) A unification algorithm for Coq featuring universe polymorphism and overloading. In International Conference on Functional Programming, ICFP.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.