Indexed copatterns : reasoning about infinite structures by observations

Reasoning about finite data such as lists or even lambda terms is well understood and programming languages and proof systems o↵er extensive support to inductively define such finite data. Beyond encoding such structures in a simply typed setting, indexing types allows us to enforce even more precise invariants about inductive objects; for example, we may index lists with their length to reason about their size or index lambda-terms with their types to guarantee that we are only working with well-typed objects and our interpreter is type preserving. The dual notion of induction is coinduction, which enables representing and reasoning about infinite data such as processes or streams. Unlike the latter, current representations of coinduction have been proven to be unsatisfactory, either because their lack of elegance makes them di cult to use and reason about or because they break desirable properties (for example subject reduction is broken in Coq [4][7]). We have proposed in [2] the idea to think of infinite data as defined by observations and characterize the result of each observation using copatterns. We then demonstrated in [1] how to guarantee that programs in this language are productive. In this line of work, infinite structures are defined by observations, and finite data, defined by constructors, can be mixed. In this talk, we investigate how to extend the idea of defining infinite data by allowing observations to be indexed by a domain. This is dual to indexing constructors with a domain. Just as in the inductive case, this indexing gives us the ability to reason about infinite structures and fix specifics invariants, together with the possibility to define coinductive predicates or relations. Our extension towards indexed types is restricted to Beluga’s type system. Beluga [3][8][9] is a twolevels language. The first one is an implementation of the logical framework LF [5]. The other level is a functional programming language environment supporting dependent types and pattern matching on LF data. We have developed an extension to Beluga that permits defining indexed observations and writing corecursive/recursive programs about them. Since our observations are defined as records, indexing obeservations correspond to indexed records; as far as we know, indexed records have been absent in dependently typed programming. While dependent records allow latter fields to depend on earlier ones, they typically do not allow us to distinguish between fields based on an index. We demonstrate the elegance and power of indexed observations using three examples: 1) Indexing a stream of bits by a natural number indicating how many bits have been read so far. These indices allow us to certify programs reading sequences of bits of fixed length from the stream and modifying them. 2) The divergence of evaluation of lambda terms with evaluation inside lambda abstractions. In particular, we will prove that ( x.x x) ( x.x x) diverges. 3) A type-preserving environment-based interpreter where we represent closures coinductively following ideas by Milner and Tofte [6]. Our prototype is the first programming environment that supports coinductive reasoning about LF specifications. This will allow us to explore new applications such as bisimulation proofs and proofs about contextual equivalence. We are currently extending and adapting our prior work on copatterns [2] to indexed copatterns in Beluga. More broadly, we see our work which restricts dependencies to a decidable domain as an interesting step towards supporting copatterns in a fully dependently typed languages.