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.
In [4] 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.
Let
U
F
2U → 2U
X\subseteqY ⇒ F(X)\subseteqF(Y)
Unless otherwise stated,
F
X is F-closed if
F(X)\subseteqX
X is F-consistent if
X\subseteqF(X)
X is a fixed point if
X=F(X)
These terms can be intuitively understood in the following way. Suppose that
X
F(X)
X
X
X
The Knaster–Tarski theorem tells us that the least fixed-point of
F
\muF
\nuF
Principle of induction: If
X
\muF\subseteqX
Principle of coinduction: If
X
X\subseteq\nuF
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
\muF
X
x\in\nuF
x
Consider the following grammar of datatypes:
T=\bot | \top | T x T
That is, the set of types includes the "bottom type"
\bot
\top
\Sigma=\{\bot,\top, x \}
\Sigma\leq
\Sigma
F:
\Sigma\leq | |
2 |
→
\Sigma\leq | |
2 |
F(X)=\{\bot,\top\}\cup\{x x y:x,y\inX\}
In this context,
x x y
x
x
y
F
Suppose we take
\muF
All datatypes in
\muF
To arrive at this conclusion, consider the set of all finite strings over
\Sigma
F
Now suppose that we take
\nuF
The type
\bot x \bot x … \in\nuF
Here
\bot x \bot x …
\bot
\{\bot x \bot x … \}
This set turns out to be F-consistent, and therefore
\bot x \bot x … \in\nuF
\bot x \bot x … =(\bot x \bot x … ) x (\bot x \bot x … )
The formal justification of this is technical and depends on interpreting strings as sequences, i.e. functions from
N → \Sigma
0.\bar{0}1=0
Consider the following definition of a stream:[5]
-- Stream "destructors"head (S a astream) = atail (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.
Source:[6]
F
F(x)=A x x
F(f)=\langleidA,f\rangle
The final F-coalgebra
\nuF
out:\nuF → F(\nuF)=A x \nuF
This induces another coalgebra
F(\nuF)
F(out)
\nuF
\overline{F(out)}:F(\nuF) → \nuF
such that
out\circ\overline{F(out)}=F\left(\overline{F(out)}\right)\circF(out)=F\left(\overline{F(out)}\circout\right)
The composition
\overline{F(out)}\circout
\nuF → \nuF
\nuF
id\nu
\overline{F(out)}\circout=id\nu
out\circ\overline{F(out)}=F\left(\overline{F(out)}\right)\circout)=idF(\nu
This witnesses the isomorphism
\nuF\simeqF(\nuF)
\nuF
F
We will show that
Stream Ais the final coalgebra of the functor
F(x)=A x x
These are easily seen to be mutually inverse, witnessing the isomorphism. See the reference for more details.
We will demonstrate how the principle of induction subsumes mathematical induction.Let
P
0\inP ∧ (n\inP ⇒ n+1\inP) ⇒ P=N
Now consider the function
F:2N → 2N
F(X)=\{0\}\cup\{x+1:x\inX\}
It should not be difficult to see that
\muF=N
P
N
P
F(P)\subseteqP
\{0\}\cup\{x+1:x\inP\}\subseteqP
This is precisely mathematical induction as stated.