Coco: Corecursion with Compositional Heterogeneous Productivity

Jaewoo Kim, Yeonwoo Nam, Chung-Kil Hur

TL;DR

This paper introduces "Compositional Heterogeneous Productivity" (CHP), a theoretical framework for handling complex corecursive definitions in proof assistants. CHP offers a compositional approach to automatically verify the productivity of these definitions, overcoming limitations in existing tools like Rocq and AmiCo by balancing broad coverage with high automation.

What Problem Does This Paper Address?

Formal verification tools, known as proof assistants, are crucial for rigorously checking complex software and hardware. Corecursive definitions are essential for reasoning about infinite data structures and behaviors, but proof assistants often impose strict syntactic rules that reject many valid corecursive definitions. Existing approaches to relax these rules face a trade-off: either they offer broad coverage but require significant manual effort (like Charguéraud's approach), or they provide good automation but have limited coverage (like AmiCo). This paper addresses the need for a unified framework that achieves both extensive coverage and high automation for corecursive definitions, particularly for coinductive datatypes.

Methods

The core contribution is the Compositional Heterogeneous Productivity (CHP) framework. Key aspects include:

  • Heterogeneous Productivity: CHP defines productivity not just for coinductive types but for functions operating on diverse domain and codomain types, including non-coinductive ones. This is achieved by associating type-specific "level sets" with types, generalizing the notion of "equality up to n elements."
  • Compositionality: The productivity of composite functions is systematically computed from the productivities of their components. This is enabled by defining productivity as a relation and establishing combination principles for various function combinators (composition, pairing, etc.).
  • Second-Order Productivity: To handle cases where productivity depends on the productivity of the function itself (e.g., smapS), CHP introduces second-order productivity. This framework allows for automatic derivation of both the fixed point and its productivity.
  • Coco Library: Building on CHP, the authors developed "Coco," a Rocq library that automates productivity computation and fixed-point generation for a wide range of corecursive definitions.

Datasets

Not discussed in the paper.

Key Insights and Ideas

  • Levels as a Generalization: The concept of "levels" (generalizing "equality up to n elements") is crucial for defining heterogeneous productivity. Different types can have different, type-specific level structures, allowing for more nuanced analysis.
  • Compositionality is Key to Automation: By breaking down complex functions into their components and defining how their productivities combine, CHP enables modular reasoning and significant automation.
  • Second-Order Productivity Solves Circularity: For functions whose productivity depends on themselves, second-order productivity provides a way to automatically derive both the function and its desired productivity.
  • Balancing Coverage and Automation: CHP aims to bridge the gap between existing approaches by offering a theoretical framework and a practical implementation (Coco) that achieve both broad applicability and user-friendly automation.

Key Results

  • The paper presents a formal framework (CHP) for compositional heterogeneous productivity.
  • It introduces a Rocq library (Coco) that automates productivity computation and fixed-point generation for a large class of corecursive definitions.
  • Illustrative examples demonstrate CHP's ability to handle cases that challenge existing tools, such as s2 (multiple friend functions) and s3 (guardedness compensation).
  • The framework successfully distinguishes between well-defined and ill-defined corecursive definitions, like s4 and s5.

Limitations and Future Work

  • Manual Effort for Combinators: While Coco automates much of the process, users still need to manually express functions using proper CTTs, STTs, and function combinators. Automatic translation of generating functions into combinator form is a future goal.
  • Inference for Second-Order Productivity: Currently, users must specify the expected productivity for second-order productivity proofs. Automating this inference is a key area for future work.
  • Mixed Recursion-Corecursion: Handling mixed recursion-corecursion examples still requires manual intervention, and improving automation in this area is a future direction.

Summary updated

BibTeX
@inproceedings{kim2025coco,
  author = {Jaewoo Kim and Yeonwoo Nam and Chung-Kil Hur},
  title = {{Coco: Corecursion with Compositional Heterogeneous Productivity}},
  booktitle = {Proc. ACM Program. Lang},
  year = {2025},
}
Figure