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.
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.
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 one cannot conclude anymore than has already been asserted, while X {\displaystyle 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 {\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.
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.
See also: Data type
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:
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:
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).
Consider the following definition of a stream:5
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.
Further information: F-coalgebra
Consider the endofunctor F {\displaystyle F} in the category of sets:
F ( x ) = A × x F ( f ) = ⟨ i d A , f ⟩ {\displaystyle {\begin{aligned}F(x)&=A\times x\\F(f)&=\langle \mathrm {id} _{A},f\rangle \end{aligned}}}
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 o u t ∘ F ( o u t ) ¯ = F ( F ( o u t ) ¯ ) ∘ o u t ) = i d F ( ν F ) {\displaystyle {\begin{aligned}{\overline {F(\mathrm {out} )}}\circ \mathrm {out} &=\mathrm {id} _{\nu F}\\\mathrm {out} \circ {\overline {F(\mathrm {out} )}}=F\left({\overline {F(\mathrm {out} )}}\right)\circ \mathrm {out} )&=\mathrm {id} _{F(\nu F)}\end{aligned}}}
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 fixed point of F {\displaystyle F} and justifies the notation.6[verification needed]
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.
Further information: 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.
"Co-Logic Programming | Lambda the Ultimate". http://lambda-the-ultimate.org/node/2513 ↩
"Gopal Gupta's Home Page". http://www.utdallas.edu/~gupta/ ↩
"Logtalk3/Examples/Coinduction at master · LogtalkDotOrg/Logtalk3". GitHub. https://github.com/LogtalkDotOrg/logtalk3/tree/master/examples/coinduction ↩
Pierce, Benjamin C. Types and Programming Languages. MIT Press. /wiki/Benjamin_C._Pierce ↩
Kozen, Dexter; Silva, Alexandra. "Practical Coinduction". CiteSeerX 10.1.1.252.3961. /wiki/Dexter_Kozen ↩
Hinze, Ralf (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. 978-3-642-32201-3 ↩