Coinduction

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."[1] Experimental implementations of co-LP are available from the University of Texas at Dallas[2] and in the language Logtalk (for examples see [3]) and SWI-Prolog.

## Contents

* 1 Description
* 1.1 Preliminaries
* 1.2 Definition
* 2 Discussion
* 3 Examples
* 3.1 Defining a set of data types
* 3.2 Coinductive datatypes in programming languages
* 3.3 Relationship with F-coalgebras
* 3.3.1 Stream as a final coalgebra
* 3.4 Relationship with mathematical induction
* 4 See also
* 5 References
* 6 Further reading

## Description

In his book Types and Programming Languages,[4] 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

### Defining a set of data types

See also: Data type

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:

All datatypes in μF are finite

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:

The type ⊥×⊥×⋯∈νF

Here ⊥×⊥×⋯ denotes the infinite string (⊥,×,⊥,×,…). To use the principle of coinduction, consider the set:

S={⊥,⊥×⊥×⋯}

This set is F-consistent. First, ⊥∈{⊥,⊤}⊆F(S). Second, since ⊥∈S and ⊥×⊥×⋯∈S, we have ⊥×(⊥×⊥×⋯)∈F(S). Interpreting strings as sequences (functions from ℕ->Σ), prepending the finite prefix ⊥× to the infinite string ⊥×⊥×⋯ yields ⊥×⊥×⋯ itself, so ⊥×⊥×⋯∈F(S). Therefore S⊆F(S), and by the principle of coinduction, ⊥×⊥×⋯∈νF.

Note. The representation of types as strings over Σ is not faithful to the underlying tree structure. Finite strings such as ⊥×⊤×⊥ are ambiguous without bracketing, and for any infinite string s the concatenation s×t=s for all t, so distinct trees may be identified. This does not affect the argument above, which only illustrates the principle of coinduction via F-consistency, but it would matter in settings where constructor structure must be preserved. A standard structural treatment represents types via the isomorphism T≅1+1+(T×T); see F-coalgebra for details.

### Coinductive datatypes in programming languages

Consider the following definition of a stream in Haskell:[5]

data Stream a = S a (Stream a)

-- Stream "destructors"
head :: Stream a -> a
head (S a astream) = a
tail :: Stream a -> Stream a
tail (S a astream) = astream

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 F in the category of sets:

F(x)=A×xF(f)=⟨idA,f⟩

The final F-coalgebra νF has the following morphism associated with it:

out:νF->F(νF)=A×νF

This induces another coalgebra F(νF) with associated morphism F(out). Because νF is final, there is a unique morphism

F(out)‾:F(νF)->νF

such that

out∘F(out)‾=F(F(out)‾)∘F(out)=F(F(out)‾∘out)

The composition F(out)‾∘out induces another F-coalgebra homomorphism νF->νF. Since νF is final, this homomorphism is unique and therefore idνF. Altogether we have:

F(out)‾∘out=idνFout∘F(out)‾=F(F(out)‾∘out)=idF(νF)

This witnesses the isomorphism νF≃F(νF), which in categorical terms indicates that νF is a fixed point of F and justifies the notation.[6][verification needed]

#### Stream as a final coalgebra

We will show that `Stream A` is the final coalgebra of the functor F(x)=A×x. Consider the following implementations:

out astream = (head astream, tail astream)
out' (a, astream) = S a astream

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 subsumes mathematical induction. Let P be some property of natural numbers. We will take the following definition of mathematical induction:

0∈P∧(n∈P⇒n+1∈P)⇒ℕ⊆P

Now consider the function F:2ℕ->2ℕ:

F(X)={0}∪{x+1:x∈X}

It should not be difficult to see that μF=ℕ. Therefore, by the principle of induction, if we wish to prove some property P of ℕ, it suffices to show that P is F-closed. In detail, we require:

F(P)⊆P

That is,

{0}∪{x+1:x∈P}⊆P

This is precisely mathematical induction as stated.

## See also

* F-coalgebra
* Corecursion
* Bisimulation
* Anamorphism
* Total functional programming

## References

1. ↑ "Co-Logic Programming | Lambda the Ultimate". http://lambda-the-ultimate.org/node/2513.
2. ↑ "Gopal Gupta's Home Page". http://www.utdallas.edu/~gupta/.
3. ↑ "Logtalk3/Examples/Coinduction at master · LogtalkDotOrg/Logtalk3". https://github.com/LogtalkDotOrg/logtalk3/tree/master/examples/coinduction.
4. ↑ Pierce, Benjamin C.. Types and Programming Languages. MIT Press. https://mitpress.mit.edu/9780262303828/types-and-programming-languages/.
5. ↑ Kozen, Dexter; Silva, Alexandra. "Practical Coinduction". CiteSeerX 10.1.1.252.3961.
6. ↑ Hinze, Ralf (2012). "Generic Programming with Adjunctions". Generic and Indexed Programming. Lecture Notes in Computer Science. 7470. Springer. pp. 47–129. doi:10.1007/978-3-642-32202-0_2. ISBN 978-3-642-32201-3. https://link.springer.com/chapter/10.1007/978-3-642-32202-0_2.

## 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). "A Tutorial on Co-induction and Functional Programming". 1994. pp. 78–95\. CiteSeerX 10.1.1.37.3914. -- 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). "A Tutorial on [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

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Coinduction. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Coinduction&oldid=4299286"