Misplaced Pages

Coinduction

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
(Redirected from Codata (computer science)) This article is about computer science. For the term in abstract algebra, see Change of rings. For the use of this term in medicine and anaesthesia, see coinduction (anaesthetics).
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
This article may be too technical for most readers to understand. Please help improve it to make it understandable to non-experts, without removing the technical details. (October 2011) (Learn how and when to remove this message)
This article relies excessively on references to primary sources. Please improve this article by adding secondary or tertiary sources.
Find sources: "Coinduction" – news · newspapers · books · scholar · JSTOR (November 2019) (Learn how and when to remove this message)
(Learn how and when to remove this message)

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 a concise statement is given 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 {\displaystyle U} be a set and F {\displaystyle F} be a monotone function 2 U 2 U {\displaystyle 2^{U}\rightarrow 2^{U}} , that is:

X Y F ( X ) F ( Y ) {\displaystyle X\subseteq Y\Rightarrow F(X)\subseteq F(Y)}

Unless otherwise stated, F {\displaystyle F} will be assumed to be monotone.

X is F-closed if F ( X ) X {\displaystyle F(X)\subseteq X}
X is F-consistent if X F ( X ) {\displaystyle X\subseteq F(X)}
X is a fixed point if X = F ( X ) {\displaystyle X=F(X)}

These terms can be intuitively understood in the following way. Suppose that X {\displaystyle X} is a set of assertions, and F ( X ) {\displaystyle F(X)} is the operation that yields the consequences of X {\displaystyle X} . Then X {\displaystyle X} is F-closed when you cannot conclude anymore than you've already asserted, while X {\displaystyle X} is F-consistent when all of your 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 {\displaystyle F} (denoted μ F {\displaystyle \mu F} ) is given by the intersection of all F-closed sets, while the greatest fixed-point (denoted ν F {\displaystyle \nu 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 {\displaystyle X} is F-closed, then μ F X {\displaystyle \mu F\subseteq X}
Principle of coinduction: If X {\displaystyle X} is F-consistent, then X ν F {\displaystyle X\subseteq \nu 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 {\displaystyle \mu F} . By the principle of induction, it suffices to exhibit an F-closed set X {\displaystyle X} for which the property holds. Dually, suppose you wish to show that x ν F {\displaystyle x\in \nu F} . Then it suffices to exhibit an F-consistent set that x {\displaystyle x} is known to be a member of.

Examples

Defining a set of datatypes

Consider the following grammar of datatypes:

T = | | T × T {\displaystyle T=\bot \;|\;\top \;|\;T\times T}

That is, the set of types includes the "bottom type" {\displaystyle \bot } , the "top type" {\displaystyle \top } , and (non-homogenous) lists. These types can be identified with strings over the alphabet Σ = { , , × } {\displaystyle \Sigma =\{\bot ,\top ,\times \}} . Let Σ ω {\displaystyle \Sigma ^{\leq \omega }} denote all (possibly infinite) strings over Σ {\displaystyle \Sigma } . Consider the function F : 2 Σ ω 2 Σ ω {\displaystyle F:2^{\Sigma ^{\leq \omega }}\rightarrow 2^{\Sigma ^{\leq \omega }}} :

F ( X ) = { , } { x × y : x , y X } {\displaystyle F(X)=\{\bot ,\top \}\cup \{x\times y:x,y\in X\}}

In this context, x × y {\displaystyle x\times y} means "the concatenation of string x {\displaystyle x} , the symbol × {\displaystyle \times } , and string y {\displaystyle y} ." We should now define our set of datatypes as a fixpoint of F {\displaystyle F} , but it matters whether we take the least or greatest fixpoint.

Suppose we take μ F {\displaystyle \mu F} as our set of datatypes. Using the principle of induction, we can prove the following claim:

All datatypes in μ F {\displaystyle \mu F} are finite

To arrive at this conclusion, consider the set of all finite strings over Σ {\displaystyle \Sigma } . Clearly F {\displaystyle 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 {\displaystyle \nu F} as our set of datatypes. We would like to use the principle of coinduction to prove the following claim:

The type × × ν F {\displaystyle \bot \times \bot \times \cdots \in \nu F}

Here × × {\displaystyle \bot \times \bot \times \cdots } denotes the infinite list consisting of all {\displaystyle \bot } . To use the principle of coinduction, consider the set:

{ × × } {\displaystyle \{\bot \times \bot \times \cdots \}}

This set turns out to be F-consistent, and therefore × × ν F {\displaystyle \bot \times \bot \times \cdots \in \nu F} . This depends on the suspicious statement that

× × = ( × × ) × ( × × ) {\displaystyle \bot \times \bot \times \cdots =(\bot \times \bot \times \cdots )\times (\bot \times \bot \times \cdots )}

The formal justification of this is technical and depends on interpreting strings as sequences, i.e. functions from N Σ {\displaystyle \mathbb {N} \rightarrow \Sigma } . Intuitively, the argument is similar to the argument that 0. 0 ¯ 1 = 0 {\displaystyle 0.{\bar {0}}1=0} (see Repeating decimal).

Coinductive datatypes in programming languages

Consider the following definition of a stream:

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

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

Source:

Consider the endofunctor F {\displaystyle F} in the category of sets:

F ( x ) = A × x {\displaystyle F(x)=A\times x}
F ( f ) = i d A , f {\displaystyle F(f)=\langle \mathrm {id} _{A},f\rangle }

The final F-coalgebra ν F {\displaystyle \nu F} has the following morphism associated with it:

o u t : ν F F ( ν F ) = A × ν F {\displaystyle \mathrm {out} :\nu F\rightarrow F(\nu F)=A\times \nu F}

This induces another coalgebra F ( ν F ) {\displaystyle F(\nu F)} with associated morphism F ( o u t ) {\displaystyle F(\mathrm {out} )} . Because ν F {\displaystyle \nu F} is final, there is a unique morphism

F ( o u t ) ¯ : F ( ν F ) ν F {\displaystyle {\overline {F(\mathrm {out} )}}:F(\nu F)\rightarrow \nu F}

such that

o u t F ( o u t ) ¯ = F ( F ( o u t ) ¯ ) F ( o u t ) = F ( F ( o u t ) ¯ o u t ) {\displaystyle \mathrm {out} \circ {\overline {F(\mathrm {out} )}}=F\left({\overline {F(\mathrm {out} )}}\right)\circ F(\mathrm {out} )=F\left({\overline {F(\mathrm {out} )}}\circ \mathrm {out} \right)}

The composition F ( o u t ) ¯ o u t {\displaystyle {\overline {F(\mathrm {out} )}}\circ \mathrm {out} } induces another F-coalgebra homomorphism ν F ν F {\displaystyle \nu F\rightarrow \nu F} . Since ν F {\displaystyle \nu F} is final, this homomorphism is unique and therefore i d ν F {\displaystyle \mathrm {id} _{\nu F}} . Altogether we have:

F ( o u t ) ¯ o u t = i d ν F {\displaystyle {\overline {F(\mathrm {out} )}}\circ \mathrm {out} =\mathrm {id} _{\nu F}}
o u t F ( o u t ) ¯ = F ( F ( o u t ) ¯ ) o u t ) = i d F ( ν F ) {\displaystyle \mathrm {out} \circ {\overline {F(\mathrm {out} )}}=F\left({\overline {F(\mathrm {out} )}}\right)\circ \mathrm {out} )=\mathrm {id} _{F(\nu F)}}

This witnesses the isomorphism ν F F ( ν F ) {\displaystyle \nu F\simeq F(\nu F)} , which in categorical terms indicates that ν F {\displaystyle \nu F} is a fixpoint of F {\displaystyle F} and justifies the notation.

Stream as a final coalgebra

We will show that

Stream A

is the final coalgebra of the functor F ( x ) = A × x {\displaystyle F(x)=A\times 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 {\displaystyle P} be some property of natural numbers. We will take the following definition of mathematical induction:

0 P ( n P n + 1 P ) P = N {\displaystyle 0\in P\land (n\in P\Rightarrow n+1\in P)\Rightarrow P=\mathbb {N} }

Now consider the function F : 2 N 2 N {\displaystyle F:2^{\mathbb {N} }\rightarrow 2^{\mathbb {N} }} :

F ( X ) = { 0 } { x + 1 : x X } {\displaystyle F(X)=\{0\}\cup \{x+1:x\in X\}}

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

F ( P ) P {\displaystyle F(P)\subseteq P}

That is,

{ 0 } { x + 1 : x P } P {\displaystyle \{0\}\cup \{x+1:x\in P\}\subseteq P}

This is precisely mathematical induction as stated.

See also

References

  1. "Co-Logic Programming | Lambda the Ultimate".
  2. "Gopal Gupta's Home Page".
  3. "Logtalk3/Examples/Coinduction at master · LogtalkDotOrg/Logtalk3". GitHub.
  4. Benjamin C. Pierce. "Types and Programming Languages". The MIT Press.
  5. Dexter Kozen, Alexandra Silva. "Practical Coinduction". CiteSeerX 10.1.1.252.3961.
  6. Ralf Hinze (2012). "Generic Programming with Adjunctions". Generic and Indexed Programming. Lecture Notes in Computer Science. Vol. 7470. Springer. pp. 47–129. doi:10.1007/978-3-642-32202-0_2. ISBN 978-3-642-32201-3.

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
History
Miscellaneous
Categories: