- Source: 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." 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:
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:
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
F-coalgebra
Corecursion
Bisimulation
Anamorphism
Total functional programming
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). "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
Kata Kunci Pencarian:
- Coinduction
- Coinduction (anesthetics)
- Grigore Roșu
- Calculus of constructions
- Non-well-founded set theory
- Area under the curve (pharmacokinetics)
- Change of rings
- Axiom of regularity
- IC50
- Volume of distribution