Wikipedia / Coinduction
Wikipedia / Coinduction
In computer science, coinduction is a technique for defining and proving properties of systems of concurrent interacting objectss.
Coinduction is the mathematical dual to structural induction. Coinductively defined data types are known as codata and are typically infinite data structures, such as streams.
As a definition or specification, coinduction describes how an object may be "observed", "broken down" or "destructed" into simpler objects. As a proof technique, it may be used to show that an equation is satisfied by all possible implementationss of such a specification.
To generate and manipulate codata, one typically uses corecursive functions, in conjunction with lazy evaluation. Informally, rather than defining a function by pattern-matching on each of the inductive constructors, one defines each of the "destructors" or "observers" over the function result.
In programming, co-logic programming (co-LP for brevity) "is a natural generalization of logic programming and coinductive logic programming, which in turn generalizes other extensions of logic programming, such as infinite trees, lazy predicates, and concurrent communicating predicates. Co-LP has applications to rational trees, verifying infinitary properties, lazy evaluation, concurrent logic programming, model checking, bisimilarity proofs, etc." Experimental implementations of co-LP are available from the University of Texas at Dallas and in the language Logtalk (for examples see ) and SWI-Prolog.
Description
In his book Types and Programming Languages, Benjamin C. Pierce gives a concise statement of both the principle of induction and the principle of coinduction. While this article is not primarily concerned with induction, it is useful to consider their somewhat generalized forms at once. In order to state the principles, a few preliminaries are required.
Preliminaries
be a monotone function, that is:
will be assumed to be monotone.
X is F-closed
X is F-consistent
X is a fixed point
is F-closed is F-consistent when all of the assertions are supported by other assertions (i.e. there are no "non-F-logical assumptions").
The Knaster–Tarski theorem tells us that the least fixed-point) is given by the intersection of all F-closed sets, while the greatest fixed-point) is given by the union of all F-consistent sets. We can now state the principles of induction and coinduction.
Definition
Principle of induction is F-closed
Principle of coinduction is F-consistent
Discussion
. By the principle of induction, it suffices to exhibit an F-closed. Then it suffices to exhibit an F-consistent is known to be a member of.
Examples
Defining a set of data types
Consider the following grammar of datatypes:
:
, but it matters whether we take the least or greatest fixpoint.
as our set of datatypes. Using the principle of induction, we can prove the following claim:
cannot produce an infinite string, so it turns out this set is F-closed and the conclusion follows.
as our set of datatypes. We would like to use the principle of coinduction to prove the following claim:
. To use the principle of coinduction, consider the set:
This set is F-consistent. Interpreting strings as sequences, and by the principle of coinduction.
Note., so distinct trees may be identified. This does not affect the argument above, which only illustrates the principle of coinduction via F; see F-coalgebra for details.
Coinductive datatypes in programming languages
Consider the following definition of a stream in Haskell:
The first line says that a stream is made up of an element followed by a stream (S is a constructor of elements, and a denotes for an arbitrary type for the elements). As there is no base case, this would seem to be a definition that is not well-founded, but it is nonetheless useful in programming and can be reasoned about. In any case, a stream is an infinite list of elements from which you may observe the first element, or place an element in front of to get another stream.
Relationship with F-coalgebras
Consider the endofunctor in the category of sets:
The final F-coalgebra has the following morphism associated with it:
is final, there is a unique morphism
such that
induces another F. Altogether we have:
and justifies the notation.
Stream as a final coalgebra
We will show that Stream A. Consider the following implementations:
These are easily seen to be mutually inverse, witnessing the isomorphism. See the reference for more details.
Relationship with mathematical induction
We will demonstrate how the principle of induction be some property of natural numbers. We will take the following definition of mathematical induction:
:
. Therefore, by the principle of induction is F-closed. In detail, we require:
That is,
This is precisely mathematical induction as stated.
See also
References
Further reading
Textbooks
Davide Sangiorgi (2012). Introduction to Bisimulation and Coinduction. Cambridge University Press.
Davide Sangiorgi and Jan Rutten (2011). Advanced Topics in Bisimulation and Coinduction. Cambridge University Press.
Introductory texts
Andrew D. Gordon (1994). mathematically oriented description
Bart Jacobs and Jan Rutten (1997). A Tutorial on (Co)Algebras and (Co)Induction (alternate link) describes induction and coinduction simultaneously
Eduardo Giménez and Pierre Castéran (2007).
[Co-]
Inductive Types in Coq"
Coinduction short introduction
History
Davide Sangiorgi. "On the Origins of Bisimulation and Coinduction", ACM Transactions on Programming Languages and Systems, Vol. 31, Nb 4, Mai 2009.
Miscellaneous
Co-Logic Programming: Extending Logic Programming with Coinduction describes the co-logic programming paradigm