Hostname: page-component-89b8bd64d-shngb Total loading time: 0 Render date: 2026-05-05T14:07:51.638Z Has data issue: false hasContentIssue false

Fold–unfold lemmas for reasoning about recursive programs using the Coq proof assistant

Published online by Cambridge University Press:  29 September 2022

OLIVIER DANVY*
Affiliation:
Yale-NUS College and School of Computing, National University of Singapore, Singapore, Singapore (e-mail: danvy@acm.org)
Rights & Permissions [Opens in a new window]

Abstract

Fold–unfold lemmas complement the rewrite tactic in the Coq Proof Assistant to reason about recursive functions, be they defined locally or globally. Each of the structural cases gives rise to a fold–unfold lemma that equates a call to this function in that case with the corresponding case branch. As such, they are “boilerplate” and can be generated mechanically, though stating them by hand is a learning experience for a beginner, to say nothing about explaining them. Their proof is generic. Their use is precise (e.g., in terms with multiple calls) and they scale seamlessly (e.g., to continuation-passing style and to various patterns of recursion), be the reasoning equational or relational. In the author’s experience, they prove effective in the classroom, considering the clarity of discourse in the subsequent term reports and oral exams, and beyond the classroom, considering their subsequent use when continuing to work with the Coq Proof Assistant. Fold–unfold lemmas also provide a measure of understanding as well as of control about what is cut short when one uses a shortcut, i.e., an automated simplification tactic. Since Version 8.0, the functional-induction plugin provides them for functions that are defined globally, i.e., recursive equations, and so does the Equations plugin now, both for global and for local declarations, a precious help for advanced users.

Information

Type
Tutorial Paper
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2022. Published by Cambridge University Press
Supplementary material: File

Danvy supplementary material 1

Danvy supplementary material 1

Download Danvy supplementary material 1(File)
File 7.9 KB
Supplementary material: File

Danvy supplementary material 2

Danvy supplementary material 2

Download Danvy supplementary material 2(File)
File 54.2 KB
Supplementary material: File

Danvy supplementary material 3

Danvy supplementary material 3

Download Danvy supplementary material 3(File)
File 13 KB
Submit a response

Discussions

No Discussions have been published for this article.