[Paper Review] Using Structural Recursion for Corecursion
This paper presents a systematic method to define corecursive stream values in constructive type theory-based theorem provers—like Coq—using structural recursion, even when recursive equations violate the guardedness condition due to functions like 'map' appearing inside recursive calls. By encoding streams as functions over natural numbers, the approach enables formal verification of infinite data structures that would otherwise be rejected by standard guarded corecursion rules, extending the class of definable corecursive functions without relying on advanced recursion principles.
We propose a (limited) solution to the problem of constructing stream values defined by recursive equations that do not respect the guardedness condition. The guardedness condition is imposed on definitions of corecursive functions in Coq, AGDA, and other higher-order proof assistants. In this paper, we concentrate in particular on those non-guarded equations where recursive calls appear under functions. We use a correspondence between streams and functions over natural numbers to show that some classes of non-guarded definitions can be modelled through the encoding as structural recursive functions. In practice, this work extends the class of stream values that can be defined in a constructive type theory-based theorem prover with inductive and coinductive types, structural recursion and guarded corecursion
Motivation & Objective
- To address the limitation in Coq and similar theorem provers where corecursive definitions are rejected if recursive calls appear under functions, violating the guardedness condition.
- To extend the class of definable coinductive streams beyond those satisfying the 'guarded-by-constructors' criterion.
- To provide a syntactic, systematic, and lightweight alternative to well-founded recursion or complex coinductive predicates for defining productive corecursive functions.
- To enable formal verification of functional programs involving infinite data structures, such as streams of natural numbers or Fibonacci sequences, using only structural recursion and guarded corecursion.
Proposed method
- Map each stream to a total function from natural numbers to values, establishing a reversible correspondence between streams and functions.
- Define corecursive stream values via structural recursion on natural number indices, transforming non-guarded recursive equations into structurally recursive functions.
- Use the standard Coq 'Function' command to define the underlying function over natural numbers, ensuring termination via structural recursion.
- Reconstruct the stream from the function using a lifting operation (e.g., '⟨ ⟩' in the paper), ensuring the resulting stream satisfies the original recursive equation.
- Leverage the fact that functions like 'map' and 'merge' can be encoded in a way that preserves the semantics of the original stream definition when translated to index-based recursion.
- Prove that the resulting stream satisfies the original recursive equation automatically, using Coq’s built-in reasoning mechanisms.
Experimental results
Research questions
- RQ1Can corecursive stream definitions that violate the guardedness condition due to function applications (e.g., 'map' or 'merge') be formally verified in a constructive type theory setting?
- RQ2Is it possible to model such non-guarded corecursive definitions using only structural recursion and standard guarded corecursion?
- RQ3Can a reversible encoding of streams as functions over natural numbers enable the construction of formally verified infinite data structures that are otherwise rejected by proof assistants?
- RQ4Does this method preserve the intended computational behavior and complexity of the original specification, or does it introduce inefficiencies?
Key findings
- The method successfully defines corecursive streams such as the stream of natural numbers and the Fibonacci sequence using structural recursion, even when the original equations violate the guardedness condition.
- The approach is systematic and does not require the introduction of complex coinductive types or ad-hoc predicates, making it simpler than prior work.
- The resulting stream values are formally proven to satisfy the original recursive equations, with proofs handled automatically by Coq.
- The method can be applied to functions like 'dTimes' that involve multiple stream arguments and recursive combinations, demonstrating scalability.
- However, the method does not handle all corecursive definitions—such as the Hamming sequence with 'merge'—due to the lack of a suitable form-shifting lemma for the merge function.
- The extracted code from the structural recursive model may have worse computational complexity (e.g., exponential for Fibonacci) than the original specification, suggesting that the specification should be used as the implementation for efficiency.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.