In computer science, coinduction is a technique for defining and proving properties of systems of concurrent interacting objects. 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 implementations 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 Let U be a set and F be a monotone function 2U→2U, that is: X⊆Y⇒F(X)⊆F(Y) Unless otherwise stated, F will be assumed to be monotone.
X is F-closed if F(X)⊆X X is F-consistent if X⊆F(X) X is a fixed point if X=F(X) These terms can be intuitively understood in the following way. Suppose that X is a set of assertions, and F(X) is the operation that yields the consequences of X. Then X is F-closed when one cannot conclude any more than has already been asserted, while X 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 of F (denoted μF) is given by the intersection of all F-closed sets, while the greatest fixed-point (denoted νF) is given by the union of all F-consistent sets. We can now state the principles of induction and coinduction.
Definition Principle of induction: If X is F-closed, then μF⊆X Principle of coinduction: If X is F-consistent, then X⊆νF
Discussion The principles, as stated, are somewhat opaque, but can be usefully thought of in the following way. Suppose you wish to prove a property of μF. By the principle of induction, it suffices to exhibit an F-closed set X for which the property holds. Dually, suppose you wish to show that x∈νF. Then it suffices to exhibit an F-consistent set that x is known to be a member of.
Examples
Proving a program can't crash Many programs or machines can be viewed abstractly as a collection of states s∈S, each of which has possible continuation states Next(s)⊆S. Suppose crash∈S is some undesirable state we wish to avoid, it is then useful to know from which starting states this undesirable state is impossible to reach. Let NeverCrashes(s) be the property that crash is impossible to reach from s via state transitions. One way that one might wish to define NeverCrashes(s) is via recursion: NeverCrashes(s)⟺(s≠crash)∧(∀n∈Next(s).NeverCrashes(n)) But as intuitive as this definition is it doesn't work as written because the recursion is not well-founded; If we have two states a,b∈S such that a∈Next(b) and b∈Next(a) then the definition is circular. A way to avoid this problem is by encoding the same recursive relation via a monotone function and then taking its greatest fixed-point: F:P(S)→P(S)F(X):={s∈X∣(s≠crash)∧(∀n∈Next(s).n∈X)}NeverCrashes(s)⟺s∈νF Now suppose there is a specific state initial∈S for which we want to prove NeverCrashes(initial). This can be done by constructing a subset of states V⊆S for which the following hold: initial∈Vcrash∉V∀s∈V.Next(s)⊆V Then the logic goes as follows: The machine starts at initial, which is in V, and each state transition after that gives another state from V, so at all points in time the machine's state must be among the ones in V. Then since crash∉V the machine's state can never be crash. This can be formalized into a proof via the principle of coinduction: crash∉V and ∀s∈V.Next(s)⊆V are precisely the conditions under which V is F-consistent, and thus by the principle of coinduction V⊆νF. Then since initial∈V it directly follows that initial∈νF, and thus NeverCrashes(initial).
Defining a set of data types
Consider the following grammar of datatypes: T=⊥|⊤|T×T That is, the set of types includes the "bottom type" ⊥, the "top type" ⊤, and product types. These types can be identified with strings over the alphabet Σ={⊥,⊤,×}. Let Σ≤ω denote all (possibly infinite) strings over Σ. Consider the function F:2Σ≤ω→2Σ≤ω: F(X)={⊥,⊤}∪{x×y:x,y∈X} In this context, x×y means "the concatenation of string x, the symbol ×, and string y." We should now define our set of datatypes as a fixpoint of F, but it matters whether we take the least or greatest fixpoint. Suppose we take μF as our set of datatypes. Using the principle of induction, we can prove the following claim:
To arrive at this conclusion, consider the set of all finite strings over Σ. Clearly F cannot produce an infinite string, so it turns out this set is F-closed and the conclusion follows. Now suppose that we take νF as our set of datatypes. We would like to use the principle of coinduction to prove the following claim:
… excerpt ends here. Continue reading the full article.