nLab
inductive type

Context

Deduction and Induction

Type theory

natural deduction metalanguage, practical foundations

  1. type formation rule
  2. term introduction rule
  3. term elimination rule
  4. computation rule

type theory (dependent, intensional, observational type theory, homotopy type theory)

syntax object language

computational trinitarianism = propositions as types +programs as proofs +relation type theory/category theory

logiccategory theorytype theory
trueterminal object/(-2)-truncated objecth-level 0-type/unit type
falseinitial objectempty type
proposition(-1)-truncated objecth-proposition, mere proposition
proofgeneralized elementprogram
cut rulecomposition of classifying morphisms / pullback of display mapssubstitution
cut elimination for implicationcounit for hom-tensor adjunctionbeta reduction
introduction rule for implicationunit for hom-tensor adjunctioneta conversion
conjunctionproductproduct type
disjunctioncoproduct ((-1)-truncation of)sum type (bracket type of)
implicationinternal homfunction type
negationinternal hom into initial objectfunction type into empty type
universal quantificationdependent productdependent product type
existential quantificationdependent sum ((-1)-truncation of)dependent sum type (bracket type of)
equivalencepath space objectidentity type
equivalence classquotientquotient type
inductioncolimitinductive type, W-type, M-type
higher inductionhigher colimithigher inductive type
completely presented setdiscrete object/0-truncated objecth-level 2-type/preset/h-set
setinternal 0-groupoidBishop set/setoid
universeobject classifiertype of types
modalityclosure operator, (idemponent) monadmodal type theory, monad (in computer science)
linear logic(symmetric, closed) monoidal categorylinear type theory/quantum computation
proof netstring diagramquantum circuit
(absence of) contraction rule(absence of) diagonalno-cloning theorem
synthetic mathematicsdomain specific embedded programming language

homotopy levels

semantics

Induction

Contents

Idea

An inductive type is…

In terms of categorical semantics, an inductive type is a type whose interpretation is given by an initial algebra of an endofunctor.

This has the usual meaning in ordinary category theory. In applications to (∞,1)-category theory, the uniqueness clause in the notion of initial object is modified to allow for a contractible space of choices (as discussed at initial object in an (∞,1)-category), and this difference is reflected accordingly in the type-theoretic set-up. The syntax will give back the traditional meaning whenever equality is interpreted extensionally.

Definition

There are two equivalent ways of defining the judgement rules for inductive types. The first describes elimination on dependent types over the given type. This is the formalization of the notion of induction, and discussed below in

The second describes elimination on absolute types. This is the formalization of the notion of recursion, and discussed below

Induction: dependent elimination, computation

(…)

Recursion: elimination, computation

(…)

Categorical semantics

We discuss the categorical semantics of inductive types.

Definition

The categorical interpretation of induction, hence of the dependent elimination and computation rules from above are the following.

Let 𝒞\mathcal{C} be the ambient category.

  1. term introduction rule

    The interpretation of inductive term introduction is by an endofunctor F:𝒞𝒞F : \mathcal{C} \to \mathcal{C} and an algebra over an endofunctor, exhibited by a morphism in 𝒞\mathcal{C} of the form

    F(W)W. F(W) \to W \,.
  2. term elimination rule

    The interpretation of the dependent elimination rule says that given a display map BWB \to W, where BB is given an FF-algebra structure and the display map is an FF-algebra homomorphism, the dependent eliminator is interpreted as a specified section σ:WB𝒞 /W\sigma : W \to B \in \mathcal{C}_{/W}, hence as a diagram

    W σ B id W \array{ W &&\stackrel{\sigma}{\to}&& B \\ & {}_{\mathllap{id}}\searrow && \swarrow_{\mathrlap{}} \\ && W }

    in 𝒞\mathcal{C}.

  3. computation rule

    The interpretation of the dependent computation rules is that the section σ\sigma from above is required to be an algebra homomorphism.

Definition

The categorical interpretation of recursion, hence of the absolute elimination rules from above in a suitable category 𝒞\mathcal{C} is the following

  1. term introduction rule

    The interpretation of inductive term introduction is by an endofunctor F:𝒞𝒞F : \mathcal{C} \to \mathcal{C} and an algebra over an endofunctor, exhibited by a morphism in 𝒞\mathcal{C} of the form

    F(W)W. F(W) \to W \,.
  2. term elimination rule

    The interpretation of the absolute elimination rule is that for AA any other FF-algebra, there is a morphism WAW \to A in 𝒞\mathcal{C}.

  3. computation rule

    The interpretation of the absolute computation rule says that the morphism WAW \to A from above is an algebra homomorphism and is unique as such.

In summary this says that the recursion rules are interpretd as an initial algebra of an endofunctor.

Proposition

When interpreted in a category 𝒞\mathcal{C} of homotopy 0-types = sets, definition 3 and definition 2 are indeed equivalent.

Proof

First suppose that WW is an initial FF-algebra as in def. 2. Then since initiality entails first of all the existence of a morphims to any other object it follows that with BB another FF-algebra there is a homomorphism WBW \to B, and since secondly initiality entails uniqueness of this morphism, it follows that given a homomorphism BWB \to W the composite WBWW \to B \to W has to equal the identity id Wid_W, hence that BWB \to W has a section, and uniquely so.

Conversely, assume that WW satisfies definition 3. For AA any other FF-algebra we can form the trivial display map W×AWW \times A \to W by projection and a section of this is equivalently just a morphism WAW \to A, so we have a homomorphism from WW to any other FF-algebra AA. Therefore to show that WW is an initial FF-algebra it remains to show that for f,g:WAf, g : W \to A two algebra homomorphism, they are necessarily equal.

To that end, notice that by the assumption of 0-truncation, the diagonal δ:AA×A\delta \colon A \to A \times A is a display map / fibration.

Form its pullback PP

P A δ W f,g A×A,, \array{ P & \to & A \\ \downarrow & & \downarrow^\mathrlap{\delta} \\ W & \underset{\langle f, g \rangle}{\to} & A \times A, } \,,

which is also an algebra homomorphism. Therefore by the interpretation of the elimination rule it has a (specified) section σ:WP\sigma : W \to P. But PWP \to W is the pullback of a monomorphism and therefore itself a monomorphism, and so the section forces it to be in fact an isomorphism. This in turn means that ff and gg are equal.

Remark

In intensional type theory, where the diagonal is not a display map, we can perform the same argument using a path object PAA×AP A \to A \times A (represented in type theory by an identity type), showing thereby that ff and gg are homotopic. A fancier version of this argument enables us to show that the space of algebra maps WAW\to A is actually contractible. In other words, the axioms for an inductive type still imply that algebra maps out of WW are essentially unique, even though the axioms do not state this explicitly.

Properties

Homotopy initiality

Any inductive type WW is a homotopy initial F-algebra: the space of FF-algebra maps WXW \to X is contractible.

(Awodey-Gambino-Sojakova)

Examples

Natural numbers

Introduction, elimination, computation

Definition

The type of natural numbers \mathbb{N} is the inductive type defined as follows.

  1. term introduction rule

    0ns(n) \frac{}{0 \in \mathbb{N}} \;\; \frac{n \in \mathbb{N}}{s(n) \in \mathbb{N}}
  2. term elimination rule

    (xP(x):Typep 0:P(0)x,p:P(x)q:P(sx))np(n):P(n) \frac{ \left( x \in \mathbb{N} \vdash P(x) : Type \;\; \vdash p_0 : P(0) \;\;\; x \in \mathbb{N}, p : P(x) \vdash q : P(s x) \right) \;\; \vdash n \in \mathbb{N} }{ p(n) : P(n) }

    (check, this probably still has syntax errors…)

  3. computation rule

    (…)

See for instance (Pfenning, section 2).

In Coq-syntax the natural numbers are the inductive type defined by

Inductive nat : Type :=
 | zero : nat
 | succ : nat -> nat.

In the categorical semantics this is interpreted as the initial algebra for the endofunctor FF that sends an object to its coproduct with the terminal object

F(X)=*X, F(X) = * \coprod X \,,

or in different equivalent notation, which is very suggestive here:

F(X)=1+X. F(X) = 1 + X \,.

That initial algebra is (as explained there) precisely a natural number object \mathbb{N}. The two components of the morphism F()F(\mathbb{N}) \to \mathbb{N} that defines the algebra structure are the 0-element zero:*zero : * \to \mathbb{N} and the successor endomorphism successor:successor : \mathbb{N} \to \mathbb{N}

(zero,successor):*. (zero,successor) : * \coprod \mathbb{N} \to \mathbb{N} \,.

In the following we write of course for short 0:*0 : * \to \mathbb{N} and s:s : \mathbb{N} \to \mathbb{N}.

Induction

Example

We spell out in detail how the fact that \mathbb{N} satisfied def. 3 is the classical induction principle.

That principle says informally that if a proposition PP depending on the natural numbers is true at n=0n = 0 and such that if it is true for some nn then it is true for n+1n+1, then it is true for all natural numbers.

Here is how this is formalized in type theory and then interpreted in some suitable ambient category 𝒞\mathcal{C}.

First of all, that PP is a proposition depending on the natural numbers means that it is a dependent type

nP(n):Type. n \in \mathbb{N} \vdash P(n) : Type \,.

The categorical interpretation of this is by a display map

P \array{ P \\ \downarrow \\ \mathbb{N} }

in the given category 𝒞\mathcal{C}.

Next, the fact that PP holds at 0 means that there is a (proof-)term

p 0P(0). \vdash p_0 \in P(0) \,.

In the categorical semantics the substitution of nn for 0 that gives P(0)P(0) is given by the pullback of the above fibration

0 *P P * 0 \array{ 0^* P &\to& P \\ \downarrow && \downarrow \\ * &\stackrel{0}{\to}& \mathbb{N} }

and the term p 0p_0 is interpreted as a section of the resultig fibration over the terminal object

* p 0 0 *P P * 0 . \array{ * &\stackrel{p_0}{\to}& 0^* P &\to& P \\ &\searrow& \downarrow && \downarrow \\ && * &\stackrel{0}{\to}& \mathbb{N} } \,.

But by the defining universal property of the pullback, this is equivalently just a commuting diagram

* p 0 P * 0 . \array{ * &\stackrel{p_0}{\to}& P \\ \downarrow && \downarrow \\ * &\stackrel{0}{\to}& \mathbb{N} } \,.

Next the induction step. Formally it says that for all nn \in \mathbb{N} there is an implication p s(n):P(n)P(n+1)p_s(n) : P(n) \to P(n+1)

np s(n):P(n)P(n+1) n \in \mathbb{N} \vdash p_s(n) : P(n) \to P(n+1)

The categorical semantics of the substitution of n+1n+1 for nn is now given by the pullback

P(()+1) s *P P s \array{ P((-)+1) \coloneqq & s^*P &\to& P \\ & \downarrow && \downarrow \\ & \mathbb{N} &\stackrel{s}{\to}& \mathbb{N} }

and the interpretation of the implication term p s(n)p_s(n) is as a morphism Ps *PP \to s^* P in 𝒞 /\mathcal{C}_{/\mathbb{N}}

P p s s *P P s . \array{ P & \stackrel{p_s}{\to} & s^*P &\to& P \\ &\searrow & \downarrow && \downarrow \\ && \mathbb{N} &\stackrel{s}{\to}& \mathbb{N} } \,.

Again by the universal property of the pullback this is the same as a commuting diagram

P p s P s . \array{ P &\stackrel{p_s}{\to}& P \\ \downarrow && \downarrow \\ \mathbb{N} &\stackrel{s}{\to}& \mathbb{N} } \,.

In summary this shows that the fact that PP is a proposition depending on natural numbers which holds at 0 and which holds at n+1n+1 if it holds at nn is interpreted precisely as an FF-algebra homomorphism

P . \array{ P \\ \downarrow \\ \mathbb{N} } \,.

The induction principle is supposed to deduce from this that PP holds for every nn, hence that there is a proof p n:P(n)p_n : P(n) for all nn:

np(n):P(n). n \in \mathbb{N} \vdash p(n) : P(n) \,.

The categorical interpretation of this is as a morphism p:Pp : \mathbb{N} \to P in 𝒞 /\mathcal{C}_{/\mathbb{N}}. The existence of this is indeed exactly what the interpretation of the elimination rule, def. 3, gives, or (equivalently by prop. 1) exactly what the initiality of the FF-algebra \mathbb{N} gives.

Recursion

Example

We spell out how the fact that \mathbb{N} satisfies def. 2 is the classical recursion principle.

So let AA be an FF-algebra object, hence equipped with a morphism

a 0:*A a_0 : * \to A

and a morphism

h:AA. h : A \to A \,.

By initiality of the FF-algebra \mathbb{N}, there is then a (unique) morphism

f:A f : \mathbb{N} \to A

such that the diagram

* 0 ()+1 f f * a 0 A h A \array{ * &\stackrel{0}{\to}& \mathbb{N} &\stackrel{(-)+1}{\to}& \mathbb{N} \\ \downarrow && \downarrow^{\mathrlap{f}} && \downarrow^{\mathrlap{f}} \\ * &\stackrel{a_0}{\to}& A &\stackrel{h}{\to}& A }

commutes. This means precisely that ff is the function defined recursively by

  1. f(0)=a 0f(0) = a_0;

  2. f(n+1)=h(f(n))f(n+1) = h(f(n)).

Identity types

The introduction, elimination and computation rules for identity types are discussed there.

In Coq-syntax the identity types are the inductive types (or more precisely, the inductive family) defined by

Inductive id {A} : A -> A -> Type := 
  idpath : forall x, id x x.

Categorical semantics

We may interpret identity types in suitable categories 𝒞\mathcal{C} such as a type-theoretic model category.

Example

The categorical interpretation of identity types in a category 𝒞\mathcal{C} is as the initial algebra for the endofunctor

F:𝒞 /A×A𝒞 /A×A F : \mathcal{C}_{/A \times A} \to \mathcal{C}_{/A \times A}

of the slice category 𝒞 /A×A\mathcal{C}_{/A \times A} over A×AA\times A which is constant at the diagonal AA×AA\to A\times A:

F(EA×A)=AΔA×A. F (\langle E \to A \times A\rangle) = \langle A \stackrel{\Delta}{\to} A \times A\rangle \,.

So an algebra for this endofunctor is a morphism

A E Δ A×A \array{ A &&\to&& E \\ & {}_{\mathllap{\Delta}}\searrow && \swarrow \\ && A \times A }

and the initial such is the path space object A IA×AA^I \to A \times A.

Path induction

Example

We spell out in detail how the the induction principle def. 3 for identity types is the principle of substitution of equals for equals.

To have an FF-algebra EA×A\langle E \to A\times A\rangle over A IA×A\langle A^I \to A \times A\rangle means precisely to have a diagram

E A A I A×A \array{ && E \\ & \nearrow& \downarrow \\ A &\to& A^I \\ &\searrow& \downarrow \\ && A \times A }

in 𝒞\mathcal{C}.

This is the interpretation of the elimination rule: EA IE \to A^I is the interpretation of a type

a,bA,p:(a=b)E(a,b,p) a,b \in A , p : (a = b) \vdash E(a,b,p)

and the lift AEA \to E is a section of the pullback of EE to AA, hence an interpretation of a term in the substitution

s:E(a,a,r a). s : E(a,a,r_a) \,.

The elimination rule then says that this extends to a section A IEA^I \to E, hence a “proof of EE over all identifications” a=ba = b.

Path recursion

Example

We spell out how the the recursion principle def. 2 for identity types is related to the Segal-completeness condition and in particular to univalence.

Notice that an algebra over the endofunctor that defines identity types, example 3,

X 0 σ 0 X 1 δ 0,δ 1 X 0×X 0 \array{ X_0 &&\stackrel{\sigma_0}{\to}&& X_1 \\ & \searrow && \swarrow_{\mathrlap{\delta_0, \delta_1}} \\ && X_0 \times X_0 }

constitutes the 1-skeleton of a simplicial object

X 1 δ 0 σ 0 δ 1 X 0. \array{ X_1 \\ {}^{\mathllap{\delta_0}}\downarrow \uparrow^{\mathrlap{\sigma_0}} \downarrow^{\mathrlap{\delta_1}} \\ X_0 } \,.

The recursion principle says that the degeneracy map σ 0\sigma_0 factors through the path space object of X 0X_0 as a lift σ^ 0\hat \sigma_0 in the diagram

X 0 σ 0 X 1 σ^ 0 X 0 I X 0×X 0. \array{ X_0 &\stackrel{\sigma_0}{\to}& X_1 \\ \downarrow &\nearrow_{\hat \sigma_0}& \downarrow \\ X_0^I &\to& X_0 \times X_0 } \,.

Semantically, this lift exists because X 0X 0 IX_0 \to X_0^I is an acyclic cofibration by definition of path space object, and X 1X 0×X 0X_1 \to X_0 \times X_0 is a fibration (display map) by the interpretation rule for dependent types.

This morphism

σ^ 0:X 0 IX 1 \hat \sigma_0 : X_0^I \to X_1

lifts paths/morphisms that exist in X 0X_0 to the morphisms exhibited by X 1X_1, if we think of the above as the 1-skeleton of a simplicial object that represents an internal category in an (infinity,1)-category.

Suppose this exists, then there will be a notion of equivalences in X 1X_1, those morphisms that are invertible with respect to the given composition operation. In good situations this will give the core inclusion

Core(X 1)X 1. Core(X_1) \hookrightarrow X_1 \,.

In this case the Segal-completeness condition in degree 1 says that the path recursion σ^ 0\hat \sigma_0 exhibits this inclusion

σ^ 0:X 0 ICore(X 1)X 1. \hat \sigma_0 : X_0^I \simeq Core(X_1) \to X_1 \,.

In the case that X X_\bullet is the classifier of the codomain fibration, then this is called the univalence-condition.

W-types

References

A very basic introduction to the concept, with an eye towards explaining identity types is in

A textbook account in the context of programming languages is in section 15 of

Discussion of inductive types in the context of Coq-programming is in chapter 3 of

See also

Expositions with an eye towards higher inductive types include

Original references include

  • Per Martin-Löf, Intuitionistic Type Theory. Notes by G. Sambin of a series of lectures given in Padua, 1980. Bibliopolis, 1984.

The formalization in Coq is discussed in

  • Eduardo Giménez, Pierre Castéran, A Tutorial on [Co-]Inductive Types in Coq (pdf)

A study of the homotopy-initiality of inductive types in homotopy type theory is in

The corresponding Coq-code is at

Exposition and discussion of that result is in

Discussion of the inductive type of natural numbers is in

  • Frank Pfenning, Lecture notes on natural numbers (2009) (pdf)

Discussion of inductive types in the context of linear type theory is in

  • Stéphane Gimenez, Towards Generic Inductive Constructions in Systems of Nets (pdf)

Revised on September 28, 2014 04:07:40 by Colin Zwanziger (108.32.26.99)