nLab
categorical model of dependent types

Context

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-level 1-type/h-prop
proofgeneralized elementprogram
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 monadmodal type theory, monad (in computer science)

homotopy levels

semantics

Categorical models of dependent types

Idea

In the relation between type theory and category theory, dependent types are said to correspond to morphisms regarded as indexed families. That is, if a type A corresponds to an object in some category, then a dependent type

(x:A)(B(x)type)(x:A) \;\vdash\; (B(x) \;type)

corresponds to a morphism BA in that category. We think of this morphism as a bundle or fibration, whose fiber over x:A is the type B(x). We can then say that type forming operations such as dependent sum type and dependent product type correspond to category-theoretic operations of dependent sum and dependent product.

However, this correspondence is not quite precise; in the case of dependent types there are extra coherence issues. Substitution in type theory should correspond to pullback in category theory; that is, given a term

(y:C)(f(y):A)(y:C) \;\vdash\; (f(y) : A)

corresponding to a morphism f:CA, the substituted dependent type

(y:C)(B(f(y))type)(y:C) \;\vdash\; (B(f(y)) \;type)

should correspond to the pullback of BA along f. However, substitution in type theory is strictly associative. That is, given also g:DC, the dependent type

(z:C)(B(f(g(z)))type)(z:C) \;\vdash\; (B(f(g(z))) \;type)

is syntactically the same regardless of whether we obtain it by substituting yg(z) into B(f(y)), or xf(g(z)) into B(x). In category theory, however, pullback is not generally strictly associative, so there is a mismatch. Similarly, every type-forming operation must also be strictly preserved by substitition/pullback.

The way this is generally dealt with is to introduce a category-theoretic structure which does have a “substitution” operation which is strictly associative, hence does correspond directly to type theory, and then show that any category can be “strictified” into such a stricter structure. Unfortunately, there are many different such structures which have been used, differing only slightly. On this page we define and compare them all.

Definitions

In all the definitions, C will be a category. Generally, we will regard the objects of C as contexts in a type theory.

So far, we do not assume anything about C as a category. Usually, one at least wants C to have a terminal object, representing the empty context, although this is not always included in the definitions. The additional structures we impose on C below will imply in particular that certain pullbacks exist in C.

Sometimes, we want to consider C as a strict category, that is, we consider its objects up to equality rather than isomorphism. However, for most of the definitions below (until we get to contextual categories), it is still sensible to treat C in an ordinary category-theoretic way, with the strictness living in the additional structure.

All of this could be made more precise by assembling the structures considered below into categories, 2-categories, and/or strict 2-categories.

Comprehension categories

Definition

A comprehension category consists of a commutative triangle of functors

E C I C\array{ E && \to && C^I\\ & \searrow && \swarrow\\ && C }

where C I is the arrow category of C, and such that

  1. EC is a Grothendieck fibration, and
  2. EC I takes cartesian morphisms in E to cartesian morphisms in C I (i.e. to pullback squares in C).
Remark

We do not ask that C IC be a fibration (that would require C to have all pullbacks), only that the particular morphisms in the image of E are cartesian.

Definition

A comprehension category is called

Remark

In the latter case, we must consider E at least to be a strict category (that is, we consider its objects up to equality rather than isomorphism) for the notion to make sense.

Remark

The interpretation of this definition is as follows.

In a comprehension category, we may regard the objects of C as contexts, and the fiber E Γ of EC over an object Γ as the category of dependent types in context Γ. If the comprehension category is split, then such dependent types have strictly associative substitution.

The functor EC I assigns to each “type A in context Γ” a new context which we think of as Γ extended by a fresh variable of type A, and write as Γ.A. This new context Γ.A comes with a projection Γ.AΓ (which forgets the fresh variable), and all substitutions in E are realized as pullbacks in C.

Display map categories

Definition

A display map category consists of a category C together with a class D of morphisms in C called display maps, such that all pullbacks of display maps exist and are display maps.

If C is a display map category, then by defining E to be the full subcategory of C I whose objects are display maps, we obtain a full comprehension category. Thus, we have:

Lemma

Display map categories may be identified with comprehension categories, def. 1, for which the functor EC I is the inclusion of a full subcategory.

Remark

Working up to equivalence of categories, as is usual in category theory, it is natural to consider display map categories to also be equivalent to full comprehension categories, def. 2, (those where EC I is merely fully faithful).

However, this breaks down when we are interested in split comprehension categories, def. 2, for modeling substitution with strict associativity, since then E at least must be regarded as a strict category and considered up to isomorphism rather than equivalence. Thus, display map categories may be said to be equivalent to non-split full comprehension categories, but “split display map categories” are not equivalent to split full comprehension categories. (In fact, split display map categories are not very useful; usually in order to make pullbacks strictly associative we have to introduce extra “names” for the same objects.)

Categories with attributes

Definition

A category with attributes is a comprehension category, def. 1, for which EC is a discrete fibration.

Remark

That is, in a category with attributes we demand only that each context comes with a set of dependent types in that context, rather than a category of such. The intent is that the morphisms between two types in context Γ should be determined by the morphisms in C between the extended contexts over Γ.

Another way to convey this same intent with a comprehension category would be to ask that it be full, def. 2, i.e. that the functor EC I be fully faithful.

In fact, any category with attributes gives rise to a full comprehension category by factoring the functor EC I into a bijective on objects functor followed by a fully faithful one. In this way, we obtain:

Lemma

Categories with attributes, def. 4, are equivalent to full split comprehension categories, def. 2.

Categories with families

A category with attributes specifies only for each “context”, a set of “types” in that context. A comprehension category, by contrast, specifies a whole category of “types” in each context. If A,BE Γ, then we can think of a morphism f:AB in E Γ as a term

(1)(x:Γ),(a:A(x))(f(x,a):B(x))(\vec{x} : \Gamma), (a:A(\vec{x})) \;\vdash\; (f(\vec{x},a) : B(\vec{x}))

in type theory.
A category with families specifies instead, for each context and each type in that context, a set of “terms belonging to that type”. These should be thought of as terms

(2)(x:Γ)(f(x):B(x))(\vec{x} : \Gamma) \;\vdash\; (f(\vec{x}) : B(\vec{x}))

in type theory.

Remark

A term of the form (1) can equivalently be regarded as a term of the form (2) by replacing Γ by the extended context Γ.A, and B by its substitution along the projection Γ.AΓ.

The additional insight in the following definition is that if we expect all of these terms to be determined by the morphisms in C, as in a category with attributes or a full comprehension category, then instead of specifying the functor EC I and then asking either that it be fully faithful or that E be discrete (removing the information about extra morphisms in E), if we specify the terms of the form (2), then the functor EC I is determined by a universal property.

Let Fam denote the category of families of sets. Its morphisms are set-indexed families (A i) iI, and its morphisms (A i) iI(B j) jJ consist of a function f:IJ and functions g j:A iB f(i). We can equivalently, of course, regard this as the arrow category Set I of Set, where (A i) iI corresponds to the arrow AI.

Definition

A category with families is a category C together with

  • A functor F:C opFam, written F(Γ)=(Tm(A)) ATy(Γ).

  • For each ΓC and ATy(Γ), a representing object for the functor

    (C/Γ) op Set (ΔfΓ) Tm(f *(A))\begin{aligned} (C/\Gamma)^{op} & \to Set\\ (\Delta \xrightarrow{f} \Gamma) & \mapsto Tm(f^*(A)) \end{aligned}

We can then prove:

Lemma

Categories with attributes, def. 4 are equivalent to categories with families, def. 5.

Proof

If we forget the terms in a category with families and let EC be the Grothendieck construction of the functor Ty:C opSet, it is easy to show that we obtain a category with attributes. Conversely, given a category with attributes, let Ty:C opSet be the functor corresponding to the discrete fibration EC, and for ATy(Γ) let Tm(A) be the set of sections of the morphism in C that is the image of A in C I. These constructions are inverses up to isomorphism.

The following alternative characterization was observed by Steve Awodey.

Theorem

If we modify Def. 5 by requiring only that the functors (ΔfΓ)Tm(f *(A)) be representable (rather than equipped with representing objects), then it is equivalent to giving

  1. a category C, together with
  2. a morphism TmTy in the category of presheaves on C which is a representable morphism.

Contextual categories

Recall that if C is a comprehension category, ΓC is a “context” and AE Γ is a “type” in context Γ, we denote by Γ.A the “extended context” in C.

Definition

A contextual category is a category with attributes C, def. 4, together with a length function :ob(C) such that

  1. There is a unique object of length 0, which is a terminal object.
  2. For any ΓC and AE Γ, we have (Γ.A)=(Γ)+1.
  3. For any ΔC with (Δ)>0, there exists a unique ΓC and AE Γ such that Δ=Γ.A.
Remark

Since def. 6 refers to equality of objects, a contextual category C must be a strict category.

Remark

The idea which distinguishes a contextual category is that “every context must be built out of types” in a unique way.

This makes for the closest match with type theory; in fact we have

Theorem

The category of contextual categories, def. 6, and (strictly) structure-preserving functors is equivalent to the category of dependent type theories and interpretations?.

Remark

Since contextual categories are strict categories, the category of such is really a 1-category, or perhaps a strict 2-category.

Definition

Given any category with attributes C, def. 4, possessing a terminal object, there is a canonical way to build a contextual category cxt(C), def. 6, from it.

  1. Choose a terminal object 1C (the resulting contextual category does not depend on this choice, up to isomorphism).

  2. The objects of cxt(C) are the finite lists

    (A 0,A 1,,A n)(A_0,A_1,\dots,A_n)

    such that A 0E 1 and A k+1E 1.A 0.A 1..A k for all k.

  3. The morphisms (A 0,,A n)(B 0,,B m) in cxt(C) are the morphisms 1.A 0.A 1..A n1.B 0.B 1..B m in C.

All the rest of the structure on cxt(C) is induced in an evident way from C.

Examples

Comprehension categories and display map categories are easy to come by “in nature”, but it is more difficult to find examples of the “split” versions of the above structure (which are what is needed for modeling type theory). Here we summarize some basic known constructions.

However, first we should mention the examples that come from type theory itself.

Syntactic categories

Example

The syntactic category of any dependent type theory has all of the above structures. Its objects are contexts in the theory, and the types in context Γ form the set or category E Γ. The strict associativity of substitution in type theory makes this fibration automatically split.

Splitting fibrations

There are standard constructions which can replace any Grothendieck fibration by an equivalent split fibration. Therefore,

Example

Given any comprehension category, def. 1,

  1. we may replace it by a split comprehension category, def. 2,

  2. then consider the underlying category with attributes, def. 4,

  3. and finally pass to a contextual category by the construction in def. 7.

Of course, comprehension categories are easy to come by; perhaps they arise most commonly as display map categories. For instance, if C has all pullbacks, then we can take all maps to be display maps. If C is a category of fibrant objects, we can take the fibrations to be the display maps.

So, for the record, we have in particular:

Example

For C a locally cartesian closed category C, it becomes a model for dependent type theory by regarding its codomain fibration C IC as a comprehension category, def. 1, and then strictifying that as in example 2.

Remark

It turns out that for modeling additional type-forming operations, however, not all splitting constructions are created equal.

Given EC, one classical construction (due to John Power) defines EC, where an object of E over ΓC consists of a morphism f:ΓΔ in C along with an object A of E over Δ. Type-theoretically, we can regard (f,A) as a type A with a “delayed substitution” f. This produces a split fibration (the chosen cartesian arrows are given by composition of morphisms in C), but it seems impossible to define dependent sums and products on it in a strict way.

A better choice is a construction due to Benabou, which defines the objects of E over ΓC to be functors C/ΓE over C which map every morphism of C/Γ to a cartesian arrow. Type-theoretically, we can think of such an object as a type together with specified compatible substitutions along any possible morphism. That type-formers can be extended in this case was proven by Martin Hofmann for dependent sums and dependent products and extensional identity types, and by Michael Warren in the case of intensional identity types (but not for the eliminator).

Universes

Suppose given a particular morphism p:U˜U in C. We can then define a category with attributes, def. 4, as follows: the discrete fibration EC corresponds to the representable presheaf C(,U), and the functor EC I is defined by pullback of p. We are thus treating U as a “universe” of types. We can then of course pass to a contextual category, as described above.

Type-forming operations can be extended strictly in this case by performing them once in the “universal” case, then acting by composition. This construction is due to Voevodsky. It also meshes quite well with type theories that contain internal universes – a type of types– , and in particular for modeling the univalence axiom.

Particular important universes include:

Simple fibrations

Let C be any category with finite products, and define EC to be the discrete fibration corresponding to the presheaf C opSet which is constant at ob(C). Thus, the objects of E are pairs (Γ,A) of objects of C, with the only morphisms being of the form (Γ,A)(Δ,A) induced by a morphism ΓΔ in C.

Define the functor EC I to take (Γ,A) to the projection Γ×AΓ. It is straightforward to check that this defines a category with attributes. The corresponding (split) full comprehension category is called the simple fibration of C.

The dependent type theory which results from this structure “has no nontrivial dependency”. That is, whenever we have a dependent type Γ(Atype), it is already the case that A is a type in the empty context (that is, we have (Atype)), and so it cannot depend nontrivially on Γ. In effect, it is not really a dependent type theory, but a simple (non-dependent) type theory — hence the name “simple fibration”.

References

A general overview can be found in

  • Martin Hofmann, Syntax and semantics of dependent types, Semantics and logics of computation (Cambridge, 1995), Publ. Newton Inst., vol. 14, Cambridge Univ. Press, Cambridge, 1997, pp. 79–130

Comprehension categories are defined in

  • Bart Jacobs, Comprehension categories and the semantics of type dependency, Theoret. Comput. Sci. 107 (1993), no. 2, 169–207

Display maps are discussed in

Categories with attributes are discussed in

  • John Cartmell, Generalised algebraic theories and contextual categories, Ph.D. thesis, Oxford, 1978

  • Eugenio Moggi, A category-theoretic account of program modules, Math. Structures Comput. Sci. 1 (1991), no. 1, 103–139

  • Andrew M. Pitts, Categorical logic, Handbook of logic in computer science, Vol. 5, Handb. Log. Comput. Sci., vol. 5, Oxford Univ. Press, New York, 2000, pp. 39–128

Categories with families are defined in

  • Peter Dybjer, Internal type theory, Types for proofs and programs (Torino, 1995), Lecture Notes in Comput. Sci., vol. 1158, Springer, Berlin, 1996, pp. 120–134, PDF

and shown to be equivalent to categories with attributes in

  • Martin Hofmann, Syntax and semantics of dependent types, citeseer.

Contextual categories are defined in

  • John Cartmell, Generalised algebraic theories and contextual categories, Ann. Pure Appl. Logic 32 (1986), no. 3, 209–243

  • Thomas Streicher, Semantics of type theory, Progress in Theoretical Computer Science, Birkhäuser Boston Inc., Boston, MA, 1991, Correctness, completeness and independence results.

Strictification is discussed in

Revised on October 5, 2012 19:58:13 by Mike Shulman (192.16.204.218)