Categories with Families: Unityped, Simply Typed, and Dependently Typed

04/01/2019 ∙ by Simon Castellan, et al. ∙ Chalmers University of Technology 0

We show how the categorical logic of untyped, simply typed and dependently typed lambda calculus can be structured around the notion of category with family (cwf). To this end we introduce subcategories of simply typed cwfs (scwfs), where types do not depend on variables, and unityped cwfs (ucwfs), where there is only one type. We prove several equivalence and biequivalence theorems between cwf-based notions and basic notions of categorical logic, such as cartesian operads, Lawvere theories, categories with finite products and limits, cartesian closed categories, and locally cartesian closed categories. Some of these theorems depend on the restrictions of contextuality (in the sense of Cartmell) or democracy (used by Clairambault and Dybjer for their biequivalence theorems). Some theorems are equivalences between notions with strict preservation of chosen structure. Others are biequivalences between notions where properties are only preserved up to isomorphism. In addition to this we discuss various constructions of initial ucwfs, scwfs, and cwfs with extra structure.

READ FULL TEXT VIEW PDF
POST COMMENT

Comments

There are no comments yet.

Authors

page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

An important part of categorical logic is to establish correspondences between languages (from logic) and categorical models. For example, in their book “Introduction to higher order categorical logic” LS86 Lambek and Scott prove equivalences between typed lambda calculi and cartesian closed categories, between untyped lambda calculi and C-monoids, and between intuitionistic type theories and toposes. Lambek and Scott’s intuitionistic type theories are intuitionistic versions of Church’s simple theory of types, which should not be confused with Martin-Löf’s intuitionistic type theories. Interestingly, in the preface of their book (LS86, , p viii) Lambek and Scott express a desire to include a result concerning the latter too:

We also claim that intuitionistic type theories and toposes are closely related, in as much as there is a pair of adjoint functors between their respective categories. This is worked out out in Part II. The relationship between Martin-Löf type theories and locally cartesian closed categories was established too recently (by Robert Seely) to be treated here.

Seely’s seminal paper SeelyRAG:locccc claims to prove that a category of Martin-Löf type theories is equivalent to a category of locally cartesian closed categories (lcccs). However, his result relies on an interpretation of substitution as pullback, and these are only defined up to isomorphism. It is not clear how to choose pullbacks in such a way that the strict laws for substitution are satisfied. This coherence problem was identified and solved by Curien curien:fi and Hofmann hofmann:csl who provided alternative methods for interpreting Martin-Löf type theory in lcccs (see also CurienGH14 ). By using Hofmann’s interpretation Clairambault and Dybjer ClairambaultD11 ; ClairambaultD14 could then show that there is an actual biequivalence of 2-categories.

In this paper we ask ourselves what it would take to add the missing chapter on Martin-Löf type theory and its correspondence with lcccs to the book by Lambek and Scott.

First we would need to add some material to Part 0 in the book on “Introduction to category theory”, including introductions to lcccs, 2-categories, bicategories, pseudofunctors, and biequivalences. But more profoundly, our biequivalence theorem differs from Lambek and Scott’s (and Seely’s) equivalence theorems in important respects, since we replace Seely’s category of Martin-Löf theories by a 2-category of categories with families (cwfs), with extra structure for type formers , and pseudo cwf-morphisms which preserve the structure up to isomorphism. Thus cwfs with extra structure replace Martin-Löf theories on the “syntactic” side of the biequivalence.

This style of presenting the correspondence between “syntax” and “semantics” for Martin-Löf’s dependent type theory applies equally well to the simply typed lambda calculus and the untyped lambda calculus, provided we consider subcategories of simply typed cwfs (scwfs), where types do not depend on variables, and of untyped cwfs (ucwfs), where there is only one type. As for full cwfs we need to provide extra structure for modelling -abstraction and application in the untyped -calculus and for modelling type formers in the simply typed -calculus.

This suggests that we ought to rewrite Lambek and Scott’s Part I “Cartesian closed categories and -calculus” in a way which harmonizes with our presentation of the biequivalence between Martin-Löf type theory and lcccs.

Categories wifh families (cwfs) model the most basic rules of dependent type theory, those which deal with substitution, context formation, assumption, and general reasoning about equality. A key feature of cwfs is that the definition can be unfolded to yield a generalized algebraic theory in Cartmell’s sense cartmell:apal . As such it suggests a language of cwf-combinators which can be used for the construction of initial cwfs (with extra structure for modelling type formers).

We prove several correspondence theorems between “syntax” in the guise of a number of cwf-based notions and “semantics” in the guise of some basic notions from category theory. Some of our theorems require “contextuality”, a notion introduced by Cartmell cartmell:apal for his contextual categories. Others require “democracy”, a notion introduced by Clairambault and Dybjer for their biequivalence theorems. Moreover, our equivalence theorems require strict preservation of chosen cwf-structure, while our biequivalence theorems only require preservation of cwf-structure up to isomorphism. In this way we can relate a number of notions from categorical logic such as cartesian operads, Lawvere’s algebraic theories, Obtułowicz’ algebraic theories of type - Obtulowicz77 , categories with finite products and limits, cccs, and lcccs, to the corresponding cwf-based notions. In addition to this we discuss different constructions of initial ucwfs, scwfs and cwfs (with extra structure) with and without explicit substitutions.

The purpose of our work is not so much to prove new results, but to suggest a new way to organize basic correspondence theorems in categorical logic, where the ucwf-scwf-cwf-sequence provides a smooth progression of the categorical model theory of untyped, simply typed, and dependently typed -calculi. We will also highlight some of the subtleties which arise when relating syntactic and semantic notions. Another important feature is that the correspondences between logical theories and categorical notions are now split into two phases: (i) equivalences and biequivalences between cwf-based notions and basic categorical notions, and (ii) the constructions of initial cwf-based notions. This yields an “abstract syntax” perspective of formal systems, where specific formalisms for untyped, simply typed and dependently typed -calculi are instances of the respective isomorphism classes of initial cwf-based notions. This is particularly important for dependent types and Martin-Löf type theory, since different authors make different choices in the exact formulation of the syntax and inference rules. Being initial in the appropriate category of cwfs is a suitable correctness criterion for these formulations.

Plan of the paper

In Section 2 we will introduce cwfs and explain their connection to Martin-Löf type theory. We will also define contextual and democratic cwfs. In Section 3 we consider unityped cwfs and show that contextual ucwfs are equivalent both to cartesian operads and to Lawvere theories. We will then add extra structure to model the untyped -calculus, and show how initial ucwfs can be built both as calculi of explicit and implicit substitutions. In Section 4 we consider simply typed cwfs. We first show the equivalence between contextual scwfs with finite product types and categories with finite products as structure. Then we show the biequivalence between democratic scwfs and categories with finite products as property. Moreover, we add function types to our contextual scwfs with finite product types and show their equivalence to cartesian closed categories as structure. (This is our analogoue of the equivalence between simply typed -calculi and cartesian closed categories in Lambek and Scott.) In Section 5 we discuss alternative definitions of full dependently typed cwfs. We also show an explicit construction of a free cwf. Moreover, we present two biequivalences: one is between categories with finite limits and democratic cwfs with extensional identity types, -types; the other is between lcccs and democratic cwfs with extensional identity types, -types and -types. Finally, we outline the construction of a free lccc, and how we can use our biequivalence theorem to prove that equality in this lccc is undecidable. In this section we only give an overview of these theorems and refer the reader to the journal articles ClairambaultD14 ; castellan:lmcs for detailed proofs.

2 Dependent type theory and categories with families

We recall the general structure of judgments and inference rules of Martin-Löf type theory and explain its connection to the definition of cwfs.

2.1 Martin-Löf type theory

We shall here consider Martin-Löf type theory with extensional identity types in the style of martinlof:hannover ; martinlof:padova .

Judgments

In Martin-Löf martinlof:hannover a new formulation of intuitionistic type theory as a formal system with four forms of judgment was introduced:

These respectively state that is a well-formed type; that and are equal types; that is a valid term of type ; and that and are equal terms of type . These four forms of judgments are hypothetical, that is, relative to a context which assigns types to free variables.

Martin-Löf martinlof:gbg92 gave an alternative version of the theory in the form of a substitution calculus (see also tasistro:lic ) with four new forms of judgments:

One aim was to make the rules for context formation explicit. Another was to formulate a calculus where substitution is a first-class citizen (a term constructor), and not just an operation defined by induction on the types and terms of the theory. The judgment expresses that is a substitution (an assignment) of terms for free variables , where are terms in the context . Substitutions can be applied to terms and types, e.g. if and and , then and . But rather than defining and (which simultaneously substitute terms for free variables) by induction, they are instead explicit term constructors, and the effect of replacing a variable by a term is expressed a posteriori via judgmental equality.

Inference rules

The inference rules of intuitionistic type theory can be separated into two kinds. The first kind are the general rules, the most basic rules for reasoning with dependent types. They deal with substitution, context formation, assumption, and general equality reasoning. They form the backbone of the dependently typed structure, and bear no information yet on term and type formers. The second kind consists of the rules for type formers, such as and extensional identity types. These rules are divided into formation, introduction, elimination, and equality rules (also called computation rules).

Categories with families capture models of the first kind of rules: the backbone of Martin-Löf type theory, independently of type and term constructors.

2.2 Categories with families

We first give the definition and then explain the connection to type theory.

Definition

The definition uses the category of families of sets. Its objects are families . A morphism with source and target is a pair consisting of a reindexing function , and a family where for each , is a function.

Definition 1

A category with families (cwf) consists of the following:

  • A category with a terminal object .

    Notation and terminology. We use etc, to range over objects of , and refer to those as “contexts”. Likewise, we use etc, to range over morphisms, and refer to those as “substitutions”. We refer to as the empty context. We write for the terminal map, representing the empty substitution.

  • A -valued presheaf, i.e. a functor .

    Notation and terminology. If , we write and refer to its elements as types over – we use to range over such “types”. For , we write and refer to its elements as terms of type in context . Finally, for , the functorial action yields

    consisting of a pair of a reindexing function referred to as substitution on types, and for each a function referred to as substitution on terms.

  • A context comprehension operation which to a given context and type assigns a context and two projections

    satisfying the following universal property: for all , for all , there is a unique such that

    We say that is a context comprehension of and .

Observe the similarity between the universal properties of context comprehension and cartesian products – the former is a skewed dependently typed version of the latter. It is also closely related to Lawvere comprehension

lawvere:hyperdoctrines .

This definition is the standard, historical definition of cwfs dybjer:torino . As notations and terminology suggest, it is closely connected to the syntax of type theory, and particularly to Martin-Löf’s substitution calculus.

Remark 1

The structure from Definition 1 exactly matches that of Martin-Löf’s substitution calculus mentioned before. The correspondence follows:

  • models the judgment and models .

  • models the judgment and models .

  • models the judgment and models .

  • models the judgment and models .

The connection with Martin-Löf’s substitution calculus contributes to the appeal of cwfs: they give rise to categorical combinators for dependent types in the same way as cccs give rise to categorical combinators for the simply typed -calculus Curien86 . However, Definition 1 has sometimes been criticized for being too close to the syntax, or for relying on less standard mathematical objects such as -valued presheaves. We will see in Section 5.1 alternative formulations of cwfs highlighting other aspects of the structure.

Remark 2

A key feature of the notion of cwf is that it can be presented as a generalized algebraic theory in the sense of Cartmell cartmell:apal .

  • The generalized algebraic theory of categories introduces the sorts and , the operations and , and associativity and identity laws.

  • The -valued presheaf adds the sorts and , the operations and , and associativity and identity laws for both.

  • The terminal object adds the operation 1 and , and its uniqueness law.

  • Context comprehension adds the operations , and , and the projection and surjective pairing laws.

See dybjer:torino for a complete presentation of this generalized algebraic theory.

A cwf is thus a structure , subject to some equations. However, we often refer to a cwf by the first two components or even the first component . We also freely drop arguments to operations in order to simplify notation, and for example, write or for the official , etc. We also remark that we sometimes write for .

As already mentioned, cwfs only organize the core of dependent type theory, the basic structure and operations on contexts, types, terms, and substitutions. We will see later how cwfs naturally generalize well-known notions in categorical logic to dependent types. We will also see how they may be enriched with type and term formers, in order to capture Martin-Löf type theory with -types, -types and identity types. Finally, we will see that the syntax of Martin-Löf type theory may be defined as the initial cwf, in a sense to be made precise later on.

Structure of contexts

The definition of cwfs just contains two operations on contexts: the terminal object representing the empty context and an operation mapping a context and a type to a new context . It is however not required that all contexts are obtained in this way. In contrast to this, Cartmell cartmell:apal added such a constraint on the structure of context for his contextual categories. We shall use the following formulation, which is equivalent to Cartmell’s:

Definition 2 (Contextuality)

A cwf is contextual iff there is a length function

such that iff , and iff there are unique and such that , and .

Although this requirement will be used in some of our equivalence theorems, it is not part of our definition of cwf. The reason is that unlike the other parts of the definition of cwfs, it does not correspond to an inference rule of dependent type theory, and it is not expressed in the language of generalized algebraic theories. However, the free cwf is contextual.

Without going as far as requiring all contexts to be defined inductively, we sometimes wish to overcome the intrinsic distinction between contexts and types by asking that up to isomorphism, every context is represented by a type ClairambaultD11 ; ClairambaultD14 .

Definition 3 (Democracy)

A cwf is democratic provided each context is represented by a type in the sense that there is an isomorphism

Democracy does not imply contextuality. However, in the presence of unit types and -types, the converse holds: any context may be represented by the iterated -type . Like contextuality, democracy does not correspond to an inference rule of dependent type theory. However, unlike contextuality, democracy can be expressed in the language of generalized algebraic theories.

Strict morphisms of cwfs

We will now introduce a notion of morphisms between cwfs.

Definition 4

A (strict) cwf-morphism from cwf to is a pair where is a functor preserving on the nose, and

is a natural transformation between -valued presheaves, preserving context comprehension on the nose.

For each , gives , and for

It is convenient to alleviate notations and write all the components of a cwf-morphism as ; for instance writing for and for . Naturality of amounts to preservation of substitution, i.e., for all in , we have

Finally, preservation of context comprehension on the nose amounts to the fact that , with and .

Small cwfs and strict cwfs-morphisms form a category, written .

3 Unityped cwfs

As we explained in the introduction, a key feature of the notion of cwf is that it can be presented as a generalized algebraic theory. As a consequence it can be seen both as a notion of model and as an (idealized) language for dependent type theory. It is therefore a suitable intermediary between traditional formal systems for dependent type theory and categorical notions of model. This paper is based on the observation that restricted classes of cwfs can play a similar role for untyped and simply typed systems. In this section we will look at cwfs with only one type and claim that they provide a similar role for untyped systems as cwfs do for dependently typed systems.

3.1 Plain ucwfs

The definition of cwfs with only one typed can be simplified as follows.

Definition 5

A unityped category with families (ucwf) consists of the following:

  • A category with a terminal object, written .

    Notation and terminlogy. We use etc to range over objects of , and refer to those as “contexts”. Likewise, we use etc to range over morphisms, and refer to those as “substitutions”. We refer to as the empty context. We write for the terminal morphism, representing the empty substitution.

  • A presheaf .

    Notation and terminlogy. We refer to the elements of as the terms of arity – we use etc to range over terms. Finally, for , the functorial action of yields a substitution operation

  • A context comprehension operation which to a given context assigns a context along with two projections

    satisfying the following universal property: for all , for all , there is a unique such that

Remark 3

The context comprehension operation for ucwfs amounts to the data of a representation for the presheaf

for all .

If is a natural number, we write for the context obtained by applications of the context comprehension operation. As the notation suggests, we think of objects of as natural numbers, the arities, although nothing forces all objects to be natural numbers, i.e. of the form . We think of “terms” in as boxes with inputs and one output. “Substitutions” are then tuples

where, for . For convenience we write . For , performing the substitution amounts to connecting the box to the -th input of the box , see Figure 1.

Figure 1: Substitution as plugging boxes

Figure 1 reminds us about other categorical notions that aim to capture algebraic theories, such as Lawvere theories. We will come back later to this similarity. However, Figure 1 is misleading in one respect: it suggests that the boxes have free variables in . In reality, in the context of ucwfs, these free variables are not first-class citizens but are obtained indirectly through sequences of projections. More precisely, the term

will serve in place of the free variable in the context of size . With the notations introduced, we then have the expected equation

These notations suggest a correspondence to cartesian operads trimble:nlab , and we will come back to this connection. Before that, writing for the category of small ucwfs and strict cwf-morphisms, we note:

Proposition 1

The category has an initial object.

Construction 1. From the definition of ucwf it is immediately clear that an initial ucwf can be generated as a higher inductive type: we simultaneously define the three families , and where the ucwf-operations become point introduction rules and the equations become path introduction rules. (In other words, we define by generators and relations.)

Construction 2. Alternatively, we can construct it as the presheaf of variables over the category of renamings:

  • The category of renamings, with objects and ;

  • Presheaf given by and ;

  • Context comprehension as , , and .

This construction and its isomorphism with have been formalized in Agda by Brilakis Brilakis18 .

Interestingly, this is the same as the free cartesian operad. This initial ucwf has the interesting property that it is contextual. As we will see, this requirement is necessary for the connection with cartesian operads.

3.2 Contextual ucwfs

Cartesian operads

Let us now consider the special case of a contextual ucwf , where the length function induces a bijection . It follows from the laws of cwfs that

From right to left we use the -ary tupling introduced above, while from left-to-right we apply projections. Thus contextual ucwfs correspond to cartesian operads.

Definition 6

A cartesian operad consists of the following:

  • a family , where , of “n-ary operations”,

  • an operation which maps and to of “operad composition” which satisfies identity and associativity laws,

  • projections , such that

Focusing on contextual ucwfs allows us to extract the mechanism for terms and substitutions that is at play in full cwfs, but without considering types.

Lawvere theories

Contextual ucwfs are also equivalent to Lawvere theories. The following definition is from HylandP07 .

Definition 7

A Lawvere theory consists of a small category with (necessarily strictly associative) finite products and a strict finite-product preserving identity-on-objects functor . Here, refers to the category of renamings introduced in the proof of Proposition 1, with terminal object and finite products defined by .

A map of Lawvere theories from to is a (necessarily strict) finite-product preserving functor from to that commutes with the functors and . Lawvere theories and their maps form a category .

Note that differs from the perhaps more familiar looking , where , a skeleton of the category of finite sets and functions, has an initial object and finite coproducts given by the sum of integers.

Theorem 3.1

The full subcategory of , having as object contextual ucwfs, is equivalent to .

Proof

Let be a contextual ucwf. We already noted that . Moreover, we observe that there is a unique contextual ucwf , isomorphic to and such that with terminal and for all . Hence we assume from now on that contextual ucwfs have natural numbers as objects. Now, by Proposition 1, is the base category of the initial ucwf. Hence, if is a contextual ucwf, there is a unique functor

which is the first component of a cwf-morphism. In particular, preserves the terminal object and context comprehension on the nose, from which it immediately follows that it is identity-on-objects and strictly finite-product preserving.

If is a cwf-functor between contextual ucwfs (assuming w.l.o.g. that these ucwfs have as objects), it follows that is a morphism between the corresponding Lawvere theories. Conversely, for any morphism between the corresponding Lawvere theories, can be uniquely recovered from and projection. This yields a full and faithful functor from to .

Finally this functor is surjective on objects: from a Lawvere theory, there is a ucwf with category ; terms , and context comprehension . The universal property follows from that of the finite product. From all that, it follows that and are equivalent.

Remark 4

In a recent paper Fiore and Voevodsky VoevodskyF17 prove a closely related result about C-systems, a variant of Cartmell’s contextual categories. They prove that their category of Lawvere theories is isomorphic to the subcategory of C-systems whose length functions (in the definition of contextuality) are bijections.

A proof of the equivalence of Lawvere theories and cartesian operads is given by Trimble trimble:nlab .

3.3 -ucwfs

Ucwfs capture the combinatorics of terms and substitution in a similar way as cartesian operads and Lawvere theories. This primitive structure may then be enriched with operations and equations for capturing specific theories, such as the pure -calculus.

Definition 8

A -ucwf is a ucwf with two more operations:

for all , and four more equations:

for , , and . A -ucwf has the same operations, but it not subject to the equation.

The definition above is natural and close to the syntax; and as we will see later on, it is the direct simplification of the notions of arrow and -types in the simply-typed and the dependently typed case discussed later on. However, in the unityped case, this definition can be simplified dramatically.

Proposition 2

Let be a ucwf. Then, -structures on are equivalently defined as natural isomorphisms between presheaves

where the functorial action of is defined as . More precisely, (1) for any -structure is such a natural isomorphism, and (2) given such a natural isomorphism, there is a unique -structure giving rise to it.

Proof

For (1), given a -structure on , we first observe that is natural by the substitution law. For we set – using and the substitution law for , and are inverse.

For (2), given a natural iso , we set . The -rule follows from the fact that is the identity. The -rule follows from the naturality of plus the fact that is the identity. The substitution law for is by naturality of , and the substitution law for is by naturality of . Finally, uniqueness of the -structure (i.e. of ) relies on the substitution rule for .

Some related models of the untyped -calculus

There are many notions of model of -calculus, see for example Barendregt barendregt:lambda . We will only briefly discuss the ones given by Obtułowicz Obtulowicz77 , Aczel aczel:frege , and Lambek and Scott LS86 .

Obtułowicz’s algebraic theories of type are Lawvere theories similar to the Lawvere theories corresponding to -ucwfs, but use an evaluation morphism as a primitive instead of . These operations are interdefinable, via and for .

As a basis for his notion of Frege structure, Aczel introduces a notion of lambda structure. This in turn is based on the notion of an explicitly closed family, which is a cartesian operad where , so that is function composition, and projections are the projections in the metalanguage. It is thus a cartesian operad which is well-pointed in the sense that and for all implies . To model the -calculus he added two operations

The resulting notion of lambda structure is equivalent to well-pointed -ucwfs. Since terms are functions, there is a unique way to define the operations and for so that they satisfy the substitution laws of -ucwfs:

for . The general substitution rules follow from this definition.

Lambek and Scott propose C-monoids as their notion of model of the untyped -calculus. These are monoids with extra structure coming from combinators of cartesian closed categories. C-monoids capture the equational behaviour of closed rather than open terms. Like in -ucwfs and cartesian closed categories, variables are dealt with indirectly as projections. But in -ucwfs, variable addressing is external, that is, handled by the ucwfs structure. There are no term constructors for pairs and projections – in particular closed terms, i.e. terms in , do not form a C-monoid as they support no pairing and projection operations. In contrast, C-monoids handle variable addressing through pairs and projections at the term level.

We expect a strong relationship between C-monoids and -ucwfs with term-level pairs and projections. The proof should follow LS86 , encoding open terms and substitution within C-monoids via functional completeness.

Initial -ucwfs

To conclude the discussion on -ucwf, we include a construction of the untyped -calculus as the initial such structure. For that, let us say that a strict cwf-morphism between -ucwfs and is a strict -ucwf-morphism iff the action of on terms preserves all the term constructors on the nose. Let us write for the category of small -ucwfs and strict -ucwf-morphisms. Then, we have:

Proposition 3

The category has an initial object.

Construction 1. The most direct construction is as a higher inductive type where each operation of the generalized algebraic theory of -ucwf is turned into a point constructor, and there is one path constructor for each equation. This construction can be viewed as a well-scoped variable free version of the -calculus of Abadi, Cardelli, Curien, and Lévy AbadiCCL90 .

Construction 2. Another initial ucwf can be constructed from the (well-scoped) -calculus. It is a higher inductive type with the point constructors

and with path constructors for the following equations:

where we define substitution by induction on :

for , and then define the equational theory of -conversion:

for and . Note that this construction is an extension of the construction of as an initial plain ucwf.

The two constructions, and the fact that they give rise to initial -ucwfs, have been formalised in Agda by Brilakis Brilakis18 .

4 Simply-typed cwfs

En route to full cwfs, we now add types yielding simply-typed cwfs (scwfs). We will then study the relationship with cartesian and cartesian closed categories.

4.1 Plain scwfs

A simply-typed cwf (scwf) is a cwf where the presheaf of types is constant, i.e. forms a set not depending on the context and invariant under substitution. We can thus simplify the definition as follows:

Definition 9

An scwf consists of the following:

  • A category with a terminal object .

  • A set .

  • A family of presheaves for . (We also write for .)

  • A context comprehension operation which to and assigns a context and two projections

    satisfying the following universal property: for all , for all , there is a unique such that

    We say that is a context comprehension of and .

Remark 5

Context comprehension for scwfs amounts to the data of a representation for the presheaf

for all and .

An scwf is a particular kind of cwf, and a (strict) scwf-morphism is simply a (strict) cwf-morphism between scwfs. Small scwfs and strict cwf-morphisms form a category .

has an initial object, but it is not very interesting since its set of types is empty and its base category is restricted to the terminal object. Therefore we fix as a set of basic types and consider the category - where objects are small scwfs together with an interpretation function . Morphisms are strict scwfs-morphisms that commute with the interpretation.

Proposition 4

For all sets the category - has an initial object.

Proof

The initial -scwf, also called the free scwf over a set of types , can be constructed in much the same way as we constructed initial ucwfs, either directly as a higher inductive type formalizing scwfs combinators and their equations, or as a typed version of the category of Proposition 1. For the second construction we let . Then we define

where is the set of variables, for . Moreover, we define the projections as

and substitution .

Just as for ucwfs, the free scwf over a set is contextual. In analogy with Section 3.2 we could relate scwfs to coloured cartesian operads (multicategories) and multi-sorted Lawvere theories, but we omit the unsurprising details. Instead, we discuss their relationship with cartesian categories.

4.2 Finite products as structure

Cartesian categories (categories with finite products) are categories with a terminal object and binary cartesian products. Straightforward as it seems, this definition hides some subtleties which are put to the forefront when one considers the associated notions of morphism between cartesian categories. Namely, does the mere existence of a product for any two objects suffice to obtain a cartesian category, or are the finite products part of the data of a cartesian category? Texts in category theory adopt one view or the other, not always explicitely. In Lambek and Scott’s book, the latter view is explicitely adopted; and morphisms between cartesian categories must preserve this explicit data on the nose.

Definition 10

A cartesian category (with structure) consists of the following:

  • A category with a terminal object ,

  • A product operation which to any assigns an object and two projections

    satisfying the following universal property: for all , for all , there is a unique such that

A strict cartesian functor from cartesian category (leaving implicit the other components) to is a functor preserving the structure on the nose, i.e. for all , , and

We write for the category of small cartesian categories (with structure) and strict cartesian functors, preserving the structure on the nose.

We will later consider another notion of cartesian category, where we are content with the mere existence of a cartesian product for any two objects, but the only data part of the structure is the basic category – there are no chosen products. This, of course, constrains the maps: the notion of strict cartesian morphisms as above would make no sense without chosen structure.

We observe in passing that from the preservation of projections and the universal property, it follows directly that strict cartesian functors also preserve tuples on the nose, in the sense that .

Finite product types

We now wish to compare cartesian categories with structure, as above, with scwfs. They are very similar, the main difference being that scwfs distinguish contexts and types; whereas cartesian categories do not have this distinction. In particular, when constructing an scwf from a cartesian category we must recover the types as the objects of . It follows that the resulting scwfs supports a finite product operation on types. Looking for an equivalence, we define what it means for an scwf to support finite product types and introduce a binary product type, and a unit type .

Definition 11

An -structure on an scwf consists of a type , and for each a term such that for all , .

Definition 12

A -structure on an scwf consists of, for each and , a type and term formers

such that, for appropriate

We thus have a type formation rule for and term formation rules for projections and pairs. The first three equations are the usual rules for product types with surjective pairing, while the last one states stability under substitution. By an scwf with finite product types we mean an scwf with an -structure and a -structure.

Remark 6

Having a -structure on scwf amounts to requiring that there is a binary type former and a natural isomorphism of preheaves

Likewise, an -structure corresponds to a type and a natural isomorphism between and the constant singleton presheaf.

The product type structure on scwfs should be preserved by morphisms.

Definition 13

If have the adequate structure, a strict cwf-morphism (strictly) preserves -structure if , and . Similarly, it (strictly) preserves -structure if , and .

We write for the category where the objects are small scwfs with product types, and morphisms are strict structure-preserving cwf-morphisms.

Given an scwf with product types we construct a cartesian category as follows. First, we define the category of types and terms in context.

Definition 14

Let be an scwf with products. We define the category of types and terms in context as having: (1) as objects, ; (2) as morphisms from to , the terms , composed with, for and ,

with identity . We write for this category.

It follows that is a cartesian category with structure for all .

Lemma 1

For any , we let be the chosen terminal object in . For every , we let their product be and the projections be

We omit the (straightforward) proof. This entails that given an scwf with products , there is one canonical cartesian category with structure, the cartesian category of closed terms .

Proposition 5

There is a functor

which to any scwf with products associates , and which to any structure-preserving cwf-morphism associates given by the action of on types and terms.

From cartesian categories to scwfs

Since forgets the structure of contexts and only remembers closed types, we expect a functor in the opposite direction to somehow reconstruct contexts. There are two natural candidates for this. The first is to reverse the effect of by reconstructing the context formally, in an operation analogous to the construction of the cartesian category of polynomials in Lambek and Scott. We will detail this below. In this way we do not directly get an equivalence, because if is an arbitrary scwf, the contexts of are generated inductively from types. However, we get an equivalence for contextual scwfs.

The other option is to let the category of contexts of be , reflecting the dual role of objects in cartesian categories as both contexts and types. Context comprehension is defined via finite products. As simple as it looks, this construction does not yield an equivalence even when restricting scwfs. (It would if one restricted to democratic scwfs such that for each , we have , but this is not a natural hypothesis as it is not satisfied by the syntax). It is, however, behind the biequivalence between scwfs and cartesian categories as property which we shall discuss in the following subsection.

Definition 15

If is a cartesian category, we define an scwf analogously to the free scwf in Proposition 4. The set of types is . We define

where and . The terms are

Substitution is defined as

for and and composition in by .

For and , we write for the corresponding variable, obtained as the -ary projection. For and we let . The projections are defined by