Categories for Types (Cambridge Mathematical Textbooks) [1 ed.] 0521457017, 9780521457019

This textbook explains the basic principles of categorical type theory and the techniques used to derive categorical sem

221 19 4MB

English Pages 356 [355] Year 1994

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Categories for Types (Cambridge Mathematical Textbooks) [1 ed.]
 0521457017, 9780521457019

Table of contents :
Contents
Preface
Advice for the Reader
1 Order, Lattices and Domains
1.1 Introduction
1.2 Ordered Sets
1.3 Basic Lattice Theory
1.4 Boolean and Heyting Lattices
1.5 Elementary Domain Theory
1.6 Further Exercises
1.7 Pointers to the Literature
2 A Category Theory Primer
2.1 Introduction
2.2 Categories and Examples
2.3 Functors and Examples
2.4 Natural Transformations and Examples
2.5 Isomorphisms and Equivalences
2.6 Products and Coproducts
2.7 The Yoneda Lemma
2.8 Cartesian Closed Categories
2.9 Monies, Equalisers, Pullbacks and their Duals
2.10 Adjunctions
2.11 Limits and Colimits
2.12 Strict Indexed Categories
2.13 Further Exercises
2.14 Pointers to the Literature
3 Algebraic Type Theory
3.1 Introduction
3.2 Definition of the Syntax
3.3 Algebraic Theories
3.4 Motivating a Categorical Semantics
3.5 Categorical Semantics
3.6 Categorical Models and the Soundness Theorem
3.7 Categories of Models
3.8 Classifying Category of an Algebraic Theory
3.9 The Categorical Type Theory Correspondence
3.10 Further Exercises
3.11 Pointers to the Literature
4 Functional Type Theory
4.1 Introduction
4.2 Definition of the Syntax
4.3 Ax-Theories
4.4 Deriving a Categorical Semantics
4.5 Categorical Semantics
4.6 Categorical Models and the Soundness Theorem
4.7 Categories of Models
4.8 Classifying Category of a λ×-Theory
4.9 The Categorical Type Theory Correspondence
4.10 Categorical Gluing
4.11 Further Exercises
4.12 Pointers to the Literature
5 Polymorphic Functional Type Theory
5.1 Introduction
5.2 The Syntax and Equations of 2λ×-Theories
5.3 Deriving a Categorical Semantics
5.4 Categorical Semantics and Soundness Theorems
5.5 A PER Model
5.6 A Domain Model
5.7 Classifying Hyperdoctrine of a 2λ×-Theory
5.8 Categorical Type Theory Correspondence
5.9 Pointers to the Literature
6 Higher Order Polymorphism
6.1 Introduction
6.2 The Syntax and Equations of ωλ×-Theories
6.3 Categorical Semantics and Soundness Theorems
6.4 A PER Model
6.5 A Domain Model
6.6 Classifying Hyperdoctrine of an ωλ×-Theory
6.7 Categorical Type Theory Correspondence
6.8 Pointers to the Literature
Bibliography
Index

Citation preview





ROY L. CROLE

x : n

t V

Suc(x)

: n



N^N



XnM+l>N

NAnM+\N

CAMBRIDGE MATHEMATICAL TEXTBOOKS

Categories

for

Types

Categories for Types

Roy

L. Crole

S.E.R.C. Research Fellow, Imperial College, London

HI Cambridge ^W

UNIVERSITY PRESS

Published by the Press Syndicate of the University of Cambridge The Pitt Building, Trumpington Street, Cambridge CB2 IRP 40 West 20th Street, New York, NY 10011-4211, USA 10 Stamford Road, Oakleigh, Melbourne 3166, Australia ?

Cambridge University

First

published

Press 1993

1993

Printed in Great Britain at the British

Library cataloguing

in

University Press, Cambridge

publication

Library of Congress cataloguing

ISBN 0 521 45092 6 hardback ISBN 0 521 45701 7 paperback

in

data available

publication

data available

To Andrew M. Pitts

Contents

Preface







the Reader

xiv

Advice

for

Order,

Lattices and Domains



1.1

Introduction



1.2

Ordered Sets



1.3

Basic Lattice

Theory

1.4

Boolean and

Heyting

1.5

Elementary

1.6

Further Exercises

33

1.7

Pointers to the Literature

36



Domain

Category Theory

12

Lattices

20 24

Theory

Primer

SI

2.1

Introduction

37

2.2

Categories

2.3

Functors and

2.4

Natural Transformations and

2.5

Isomorphisms

and

2.6

Products and

Coproducts

2.7

The Yoneda Lemma

2.8

Cartesian Closed

Categories

67

2.9

Monies, Equalisers, Pullbacks and their Duals

73

2.10

Adjunctions

77

and

Examples

40

Examples

45

Examples

Equivalences

52 55 61

2.11 Limits and Colimits 2.12 Strict Indexed

49

91

Categories

106

2.13 Further Exercises

113

2.14 Pointers to the Literature

118 vii

viii



Contents

Algebraic Type Theory

120

3.1

Introduction

120

3.2

Definition of the

3.3

Algebraic

3.4

Motivating

3.5

Categorical

Semantics

132

3.6

Categorical

Models and the Soundness Theorem

134

3.7

Categories

3.8

Classifying Category

3.9

The

Syntax

121

127

Theories a

Categorical

Semantics

of Models

137 of

an

Algebraic Theory

Categorical Type Theory Correspondence

139 147

3.10 Further Exercises

151

3.11 Pointers to the Literature

152

4 Functional Type Theory



129

154

4.1

Introduction

4.2

Definition of the

4.3

Ax-Theories

4.4

Deriving

4.5

Categorical

Semantics

168

4.6

Categorical

Models and the Soundness Theorem

171

4.7

Categories

4.8

Classifying Category

4.9

The

4.10

Categorical Gluing



154

Syntax

156 161

Categorical

Semantics

163

172

of Models of

Ax-Theory



Categorical Type Theory Correspondence

175 180 185

4.11 Further Exercises

192

4.12 Pointers to the Literature

199

Polymorphic

Functional

Type Theory

201

5.1

Introduction

201

5.2

The

5.3

Deriving

5.4

Categorical

5.5

A PER Model

234

5.6

A Domain Model

241

Syntax and Equations of 2Ax-Theories a

Categorical

Semantics

Semantics and Soundness Theorems

203

214 224

Contents



ix

5.7

Classifying Hyperdoctrine

5.8

Categorical Type Theory Correspondence

268

5.9

Pointers to the Literature

274

Higher

Order

of



2Ax-Theory

Polymorphism

262

275

6.1

Introduction

6.2

The

6.3

Categorical

6.4

A PER Model

291

6.5

A Domain Model

292

6.6

Classifying Hyperdoctrine

6.7

Categorical Type Theory Correspondence

313

6.8

Pointers to the Literature

314

Syntax

and

275

Equations

of

u; Ax-Theories

Semantics and Soundness Theorems

of

an u;

Ax-Theory

275

285

310

Bibliography

315

Index

320

Preface During the Michaelmas term of 1990, while Computer Laboratory, the opportunity arose of lambda calculi. The duration twice

this



course

at the to

University of Cambridge lecture on categorical models

consisted of sixteen lectures of about

one

hour's

eight weeks, and covered much of the material in higher order polymorphism and some of the category

week for

book, but excluded

theory. The lectures were delivered to an audience of computer scientists and mathematicians, with an emphasis on presenting the material to the former. It was kindly suggested by the Cambridge University Press that these lectures might form the core of a textbook, and the original suggestion has now been realised as "Categories for Types."

"Categories for Types" ? I will try to answer this question for those who know little about categorical type theory. In Chapter 1, we begin with a discussion of ordered sets. These are collections of things with an order placed on the collection. For example, the natural numbers form a What

set

are

the contents of

{1,2,3...}

with

an

order

given by

1 < 2 < 3 <

...

where <

means

"less

equal to." A number of different kinds of ordered set are defined, and results proved about them. Such ordered sets then provide a stock of examples of categories. A category is a very general mathematical world and various different sorts of mathematical structures form categories. It is precisely because of this generality that apparently diverse properties of different than

or

property from the point of view of category theory. A categorical property might be thought of as a specification of a property which may hold of categories in general, mathematical structures

can

be

seen as

instances of the

same

particular mathematical structure (particular category) may be shown to yield a specific implementation of this property. We give the definition of a category in Chapter 2, show how various categories are related and give many examples. We then go on to describe some results about categories, using material on ordered sets to give gentle introductions to the categorical results. Chapters 1 and 2 contain (most of) the background mathematical machinery used in the remainder of "Categories for Types." Chapter 3 begins by showing how the definition of a category is related to certain underlying principles of syntax formation, giving us a first glance of the connections of category theory with type theory in particular and computer science in general. We but



Preface

xi

particular kind of formal syntactic language is intimately related to a particular kind of category theory—the study of such correspondences is known as categorical type theory. In Chapter 4 we introduce a functional type theory based on the simply typed A-calculus. This is a formal syntactic language which can be viewed as a very basic programming language. Once again we show a connection between a language (this time functional type theory) and a particular kind of category theory, thus further developing the theme of categorical type theory. We use the category theory to prove a result about functional type theory which says (in a certain sense) that the functional type theory has given us a richer programming language than that of Chapter 3, but that the things we can actually express and prove in the richer language are the same as those in the language of the previous chapter. In Chapter 5 the idea of polymorphism is introduced. In certain programming languages, one needs to write a different sorting algorithm to sort a list of numbers or a list of words. However, the essence of the process of sorting is the same for both kinds of list. A polymorphic language allows one sorting program to work for both lists. We give a formal language which incorporates the basic feature of polymorphism, and once again describe the category theory which corresponds to this language. We give a full account of two examples of categorical models of second order polymorphism. Finally, in Chapter 6, we enrich the polymorphic capabilities of the language from Chapter 5. In this new language we are able to write programs which involve not only the usual syntax of simple functional languages but also a syntax which allows programs to be written involving types and type constructors. Once again we discuss categorical models, examples of such models, and also the precise correspondence between the type theory and category theory. show how



I have tried to maintain

presenting material rapidly with a minimum of background discussion on the one hand, and proceeding too slowly with obvious points on the other hand. Categorical type theory a

balance between

often involves many "routine" calculations: because this work is intended

introductory textbook,

might even be used for undergraduate courses, I often present some of these computations in detail. Note also that because this book is aimed at both computer scientists and mathematicians, some discussions may seem laboured to one group and not the other. Although I have included some background discussions which motivate definitions, I have decided to keep these to a minimum. I hope that the reader will put in time to flesh out the material which this book provides. In most cases where new topics are introduced, I have tried to give simple definitions and examples which are then followed by the more general cases; I think this is appropriate an

which

as

xii

for

Preface

working



textbook of this nature.

I have included fall ?

(roughly)



small number of exercises

into three

throughout categories (no pun(s) intended):

routine exercises which may appear

verify

details omitted from the

They

anywhere (often asking the reader to

text);



less routine exercises which may appear



further exercises which

are

the book.

given

anywhere; and

at the ends of

chapters.

Mathematics in much

general and theoretical computer science in particular are very doing subjects, and to understand them requires an active role on the

part of the student.

least

To make full

of this book it is essential that at

attempted. When easy details need to be filled in to make everything crystal clear, but may (for example) involve a lengthy calculation, this will often be brought to the reader's attention with an exercise. Of course, the attentive reader will always ensure that details are understood before progressing with the text, but I think it appropriate in a working student textbook to point out occasionally that technical details are missing from the text and should be worked out. In general, the routine exercises are intended to reinforce the basic contents of the material presented in the book. The exercises given at the end of some chapters cover all topics which have been discussed up to that point in the book. I have not given large numbers of problems. Students often find it difficult to select tasks when given a large collection of exercises; and if the questions are too easy very little will be learned. Thus I have presented a small number of problems which will make (some) readers stop to think. Experience suggests this is a good approach to learning. Finally, the text will often say "it is easy to see that..." some

of the exercises

use

are

Sometimes this will be very true, but at other times this is code for "a short

exercise," meaning that the reader will have to scribble with pencil and paper for a minute or so in order to understand fully what is going on. I have to thank

number of



special mention, namely Andrew Pitts, who introduced me to categorical type theory and from whom I have probably learnt more about the subject matter of this book than from anyone else. For this reason I dedicate "Categories for Types" to him. He has been a constant source of inspiration and I am indebted to him a

for the many discussions

provided to





have had

over

single

out

one

person for

recent years. An anonymous referee

number of very useful comments and

suggestions for improvements

(they will be pleased to see that certain removed). Samson Abramsky has always shown

draft version

have been

we

people.

"fatuous mottos" a

keen interest in

Preface

xiii

project and has provided encouragement and advice at all stages. Mark Dawson kept the machines running and patiently answered some of my more naive questions about the Unix system. Peter Freyd provided some inspiration for me to finish "Categories for Types" during the latter stages of production. Paul Taylor has given me more help than I deserve with typesetting in IATjtX and the diagrams in "Categories for Types" are drawn using his Commutative Diagrams package. He has also provided help with a number of mathematical questions and ensured that there was never a dull moment at Imperial College. I have had very useful technical conversations with Martin Hyland and Eugenio Moggi who have helped greatly in smoothing out parts of the presentation. the

John Harrison, Eike Ritter and Joshua Ross gave draft versions which led to

me

significant improvements

detailed comments

on

presentation. A number of other people have contributed towards the production of this book by way of discussion, past lecture notes or simply enthusiasm, including Bart Jacobs, Peter Johnstone, Luke Ong, Edmund Robinson, Wesley Phoa and Steve Vickers. The category theory reading group at Imperial College proved a

in the

useful test-bed for parts of the book and I have had useful comments from

Clark, Abbas Edalat, Lindsay Errington, Simon Gay, Martin Kohler, David Lillie, Ian Mackie, Nick Merriam, Raja Nagarajan and Mark Ryan. Last, but by no means least, I thank my parents for their encouragement. Dave



am

grateful

Cambridge University Press for Roger Astley for helping efficiently with

to David Tranah of the

suggesting that I write this book, and to all stages of the production. Thanks also to the copy editors who did a very thorough and professional job. Let me conclude by emphasising that the blame for any errors which remain in "Categories for Types" must lie solely at my feet.

Advice

Uses

for

the Reader

of "Categories for Types"

This text is intended to be

introduction to

also be useful

(a particular

as a



student textbook which

kind

primarily provides

an

of) categorical type theory, but which should

reference to those mathematicians and computer scientists

pursuing research in related of lectures

basis for

a course

graduate

students. Given the

envisaged that it could provide the aimed at advanced undergraduate or beginning current content of typical British undergraduate

areas.

It is

mathematics and computer science courses, it is difficult to describe audience at whom the book is aimed.

For

example,

the material

on

an

exact

ordered

sets should be

readily accessible to first and second year undergraduates and indeed I know of courses which contain elements of such topics. However, the material on category theory, while probably accessible to good third year undergraduate students, does require a certain amount of mathematical maturity. Perhaps it is better suited to graduate students in their early stages. Chapters 3 and 4 are probably of second and third year undergraduate level respectively, assuming that the requisite category theory has been assimilated. The final two chapters are probably better suited to first year graduates. In summary, as well as serving as a textbook for (graduate) students, I hope "Categories for Types" will provide a useful reference for those conducting research into areas involving categorical type theory and program semantics. I have included a comprehensive index which will provide a quick route to definitions. It is difficult to say what

prerequisites

are

necessary to read the book.

front, a solid understanding of basic algebra and set theory will be needed. Technically a bright student should be able to follow the material knowing little else, but in practice it will help to have some acquaintance with elementary mathematics such as group theory and vector spaces. Anyone reading this advice who knows little or nothing of these things should not be deterred from trying to get to grips with categorical type theory; understanding such topics is not essential. One of the difficulties of learning category theory is having a sufficient stock of examples of categories and this problem is accentuated in ,the case of computer scientists. I have tried to On the mathematical

Advice

for

make the

included

the Reader

xv

majority of examples appeal

some

to

mainstream mathematical

computer scientists, but I have also

examples

appeal to will help if the programming,

to make the book

logicians. On the computer science front, it reader is familiar with elementary logic, A-calculus, functional type inference systems and the principles of polymorphism to the level found in good British undergraduate courses. The most essential topic is A-calculus, especially the notion of variable binding. However, this book contains all mathematicians and

necessary formal definitions and the mature reader should find the text very much self-contained

the computer science front.

on

Interdependence of Chapters picture below gives an indication of how material in later chapters of "Categories for Types" depends on earlier material.

The

Chapter



Chapter









H-irm^ Sec./llUIlo



9 1 IU 9 fi Z.l tn Z.O



PVinr?ter v^IlcLJ^







Chapter





° 9 H-inn ̄ ° ^. 7 Sec./llUIlo 1 in IU £.0



J H

PVinr>ter v^llcLJ^

41





Chapter





Sec tinn^ LlUIlo

9 0 tn 9 19|\ IU £i.±£i

£.J





PVinr ^IlcLJ^>ter 5





Chapter



theory respectively might be readable in themselves if the reader has a little knowledge of the other topic. For a reader with knowledge of category theory, the remaining Chapters 3 to 6 concerning type theory are technically self-contained, but in practice it would be almost impossible to follow their contents without understanding the preceding material. Note that it is not necessary to understand all of the category theory in Chapter 2 in order to follow the chapters on type theory. I have (within reason) only included material in earlier chapters which will be put to use in later chapters.

Chapters

1 and 2

on

domain

theory

and category

Advice

xvi

the Reader

for

Notational Conventions computer scientists. In essence, the message is that apart from the formal syntactical systems which appear, mathematical notation will be informal. For example, given sets X and Y, we This section is aimed

define



function



particularly

at



to be a subset

(where

C X x Y





Y is the set of

pairs of elements of X and Y) for which given any x G X there is y EY with (x, y) G /. Formally we have to give sets X and Y and

Informally

of the function between them.

then say that

has



source

we

will

X and target Y to

can



unique

then talk

just talk of a function /, and that

mean



C X x Y. Other

theory will appear throughout the text, but of course in practice this aids understanding of the essential details; things can always be formalised once one knows what is going on. abuses of formal set



We will write

(for example) [#i,..., xn]

for



list of



objects,

and will allow

length of the list; thus commonly used as a symbol

the context of discussion to indicate the nature of the

the previous list will for



finite natural number. Of

appropriate points ?

usually be finite because course



is

such conventions will be made clear at

in the text.

Vector notation will be used to abbreviate lists.

denoted x,

leaving

Sometimes

Thus

[xi,..., xn]

the context of discussion to indicate the

length

will be

of the list.

superscripts and subscripts off symbols. For example, the identity function idx on the set X will be written id providing we can ?

deduce the ?

we

source

and target of id from the current discussion.

We will often say "let

sets and

h\Z

—*■

f:X

Z'

—?

are

We may also

h(gf): X ?

leave

—?

/, g: X

Y and g: X

functions, use

we

brackets

—?

—?



Y be functions" to are

functions. If

write either

"("

and

")"

gf

or

go



mean

/: X

—?

to indicate order of

Z' is the function whose value at

mean

Y,



g: Y

—>

are

Z and

for functional

G X is

composition. composition, so

h(gf(x))



Z'.

only if" to iff. We also use the phrase "just in iff. We will often write implications and bi-implications using

We will abbreviate "if and

case" to

that X and Y

proofrules. So if

we

have



mathematical sentence

(Statementl) this will often be written

implies

(Statement2)

(Statementl) (Statement2)

and

(Statementl)

iff

(Statement2)

Advice

for

xvii

the Reader

will be written

(Statement 1) (Statement2)

Throughout "Categories for Types" we will use the informal notion of a commutative diagram. We will not give any formal definition of such diagrams, but leave the reader to understand the ideas from a few examples. ?

Suppose

that

given set-theoretic functions

we are

f:A—>

g:B —>D



h:A—>C for which

gf



kh: A

—?

k:C



that is the

D,

composition of h and k. We

—?

can

composition of / and g equals the illustrate this with a diagram



and

we

refer to the

diagram indicated composition) are equal. If



G A is

an

diagram as commutative to mean that by arrows (in this case the paths mean

element of A,

we

could also draw

h{a) ?

order to

^_

fc(/i(a))



compositions gf and kh

We will sometimes

the

paths round the

functional

diagram

f{a)

a i

to indicate that the



the

are

equal.

and 4- to indicate "blank

space" in give definitions of functions. This is best illustrated by example. Let use

symbols

g{f{a))



N be the set of natural numbers. Then

(-)*(+): is the function which maps any

multiplication. Also,

if no is





£ N to no

* m.



(n,m)





(+)



—?



N x N to

fixed natural

n0 maps any





n * m

where

number, the function N



indicates

Order,



1.1

Lattices and Domains

Introduction

DISCUSSION 1.1.1

We shall

of the topics which appear ordered set.

Roughly,

deemed to be greater numbers

as an

an

or

begin by giving an informal description of some in Chapter 1. The central concept is that of an

ordered set is



collection of items

smaller than others. We

ordered set,

where, for example,

can

5 is

some

of which

are

think of the set of natural

greater than 2, 0 is less than

100, 1234 is less than 12687 and so on. We shall see later that one way in which the concept of order arises in computer science is by regarding items of data as ordered

according

gives us. Very have two programs P and P' which perform identical

to how much information

crudely, suppose that we tasks, but that program P

is denned

of inputs than does P'. Then

we

(halts



certain data item

with

success)

on a

greater number

could record this observation

by saying

that

P is greater than P'. These ideas will be made clearer in Discussion 1.5.1. We

perform certain operations on ordered sets, for example we have simple operations such as maxima and minima (the maximum of 5 and 2 in the ordered set of natural numbers is 5), as well as more complicated ones such as taking suprema and inflma. If the reader has not met the idea of suprema and infima, then he will find the definitions in Discussion 1.2.7. We shall meet examples of ordered sets with given properties; for example, the set of real numbers can

has the property that the infimum and supremum of any bounded non-empty

always exist (bounded means that every element of the subset is less than a given fixed real and greater than another fixed real). As well as discussing ordered sets in themselves, we shall want to talk about relations between ordered sets and in particular this will include different varieties of subset of reals

function. We will also need to understand the idea that functions themselves can

be ordered. As

which sends



the result of g

an

example,

consider the function



on

the natural numbers

1, and g which sends n to n+4. Then on every argument, greater than that of /, and so we can regard g as greater than

to n-f

is

/. This completes the informal description of the

summarise, Chapter

chapter. To properties they may have,

contents of this

1 deals with ordered sets, the

and relations and functions between ordered sets. Before of the

beginning in earnest, we shall give a slightly more formal description contents of Chapter 1. The account begins with Discussion 1.2.1, which 1



Chapter

contains

Order, Lattices and Domains

1.

short and terse summary of



material

background notation and ideas,

on

sets and

and the summary is not a simply to fix leisurely exposition. We will not introduce every basic mathematical concept that we will be using, but simply give some basic definitions just to give the reader some familiarity with notation and style. For example, while "function" is given a formal definition below (and fixes our notation for functions), it is certainly assumed that the reader has some knowledge of functions, and knows the meaning of injective and surjective function (for which we adopt no special notation). Once the summary is complete, we proceed with discussions of the functions. The idea is

basic definitions and

properties of ordered sets. Different kinds of order are discussed, and concepts such as maximum, greatest element, join and Hasse

diagram this,

defined. We also define the notion of monotone function. With

are

we are

able to consider

some

of the most

common

structures which arise

theory of ordered sets, such as lattices, Heyting lattices and Boolean lattices. Some basic examples are given, along with some very simple representation theorems which provide information about the way such ordered sets arise. In particular, we describe the idea of a closure system, which gives examples of ordered sets in which the order is given by subset inclusion. Finally we move on to domain theory, once again giving simple examples and proving representation theorems. We also give a number of technical results whose use will only be seen in the later chapters of this book, where domains will provide in the

mathematical models of type theories.

1.2

Ordered Sets

DISCUSSION 1.2.1 A and X

to

mean

set Y is

are

We

sets,

subset



y G Y such that





with



write AC. X to

we

that A is

begin

finite subset.

/. Given

A is

mean

X, and A C.f X

subset of



A total

function between a set X there is given any x

C X x Y for which

(x, y)





theory. If

summary of basic naive set

we

write

f(x)

for the

X and



unique



unique

y such

(x, y) /. It will often be convenient to write x *-* f(x) to indicate that (x, f{x)) /; for example, if R is the set of real numbers, then the function / between R and R, given by r i—? r2, is formally the subset

that

{{r,r2) |r ER} Often



we

shall say that



C X x Y. We shall say

of the function called

an

is



function X

(informally)

/. A function /: X endofunction on X. Given

CRxR.

—?

Y and write

that X and Y

—?

are

X with identical

functions

/: X the

—*■

source

source

f:X^Y

Y in

and

place of

and target

and target is

g:Y

—*■

Z,

we

1.2.

Ordered Sets



Z defined by x h-* g(f(x)). A partial gf or g o f for the function X function between X and Y is a subset /CIx7 such that given any elements y'. If (x, y) G /, we write /(x) for y. If (x, y) G / and (x, y') G f then y Y is a partial function, and given x £ X there is no y G Y for which /: X (xi y) /, then we say that / is undefined at x, or sometimes simply say that V is a function and 5 C X is a subset of X, then /(x) is undefined. If /: X write

—?



—?

—?

we

shall sometimes

If X and y

difference of X. A

then

are

use

the notation

f(S)

to

represent the

binary



set, then

{/(s) |



5}.



\Y {x G X \ x 0 Y} is the se£ \X\ will denote the cardinality (size)

any two sets, then the set X

of y from X. If X is

set



relation i?ona set X is any subset RC X



X. If x, y G

X,

xRy for (x, y) £ R. R is reflexive if for any x G X we have xRx; symmetric if whenever x,y £ X then xify implies yi?x; transitive if for any x, y, z G X, whenever we have xRy and y-Rz then xRz; and anti- symmetric if whenever x, y G X, xRy and yi?x imply x and y are identical. .R is an equivalence relation if it is reflexive, symmetric and transitive. Given an equivalence relation R on X, the equivalence class of x G X is the set [x] {y | y G X,xRy}. We write X/R for the set of equivalence classes {[x] | x G X}. This completes the summary, and we now move on to the we

will write



definition of ordered sets. A

preorder

transitive.

x.

set X is



binary

relation <onX which is reflexive and

The relation < will sometimes be referred to

order relation for y <

on a

on

informally

the set X. It will sometimes be convenient to write

If at least

one

of





y and y <



holds, then

to be



and y

as x

are

the >



said

comparable. If neither relation holds, then x and y are incomparable. A preordered set (X, <) is a set equipped with a preorder, that is to say we are given a set (in this case X) along with a preorder < on the set X; the set X is sometimes called the underlying set of the preorder (X, <). Where confusion cannot result, we refer to the preordered set X, or sometimes just the preorder X. The preorder X is said to be discrete if any two distinct elements of X are incomparable. If x < y and y < x then we shall write x y and say that x and y are isomorphic elements. Note that we can regard as a relation on X, which is in fact an equivalence relation. If (X, <x) is a preorder, we shall write 5CXto mean that the set S is a subset of the underlying set of X. Of course, we can regard S as a preordered set (5, <s) by restricting the order relation on X to 5; more precisely, if s, s' G S, then s <5 s' iff s <x s'. We shall then say that S has the restriction order inherited from X. However, we shall limit the force of the judgement S C X to mean that S is simply a subset of the underlying set of X. The notation x < S will mean that for each s G S, =



x < s.



Chapter

Order, Lattices and Domains

1.

partial order on a set X is a binary relation < which is reflexive, transitive and anti-symmetric. A set X equipped with a partial order is called a partially ordered set, or sometimes a poset. Thus a poset is a preorder which is X, where X is a poset, then we shall write x < y to antisymmetric. If x, y mean that x < y and x ^ y. Given a preorder X then the set of equivalence classes X/ can be given a partial ordering by setting [x] < [y] iff x < y for all x, y X. The poset X/ is called the poset reflection of X. A





Remark 1.2.2

pictures, known as Hasse diagrams, to describe partially ordered sets. Roughly, in order to illustrate a finite poset pictorially, we select a distinct point P(x) of the Euclidean plane E2 for each x

there is

no z

is

at

P(z)

X with

P(x)

strictly

informal

use

of the poset X and draw

element circle at

We shall

x < z <

to the circle at





we

P(y),

small circle at draw

consider the poset X with

l(x, y)

if



underlying

can

draw the Hasse

represent X. Finally,

note that while

b < b and

c < c.

We

P(y).

x <

y in X and

l(x, y) joining the coordinate of P(x)

Ensure also that the circle

is different from

{a, b, c}

set

If

line segment

such that the second

less than the second coordinate of

does not intersect



P(x).



where

and y. For

example,

c, b < c,

a <

a <

a,

diagram

we can

only

this

procedure sensibly for finite posets, in practice we shall draw "Hasse diagrams" of infinite posets, making the exact meaning of the picture clear with accompanying to

use

mathematics. Examples 1.2.3

(1)

The set of natural

We will refer an

to this

infinite poset,

we

increasing order is a poset. poset as the vertical natural numbers. Although this is can draw a diagram to represent it:

numbers, N,

with the usual

2 1 0

(2)

See

Figure

1.1.

Examples (a)

shows that the order in



and

finite poset

(b) can

are

be

both finite posets.

Example (c)

quite involved, (d) is the poset

1.2.



Ordered Sets

(b)

(a)

oo

2 1 0

(c) Figure

(d) 1.1: Some

Examples of Posets.

which is "a copy of the natural numbers

(as

added." We will refer

the

The

(3)

underlying

The set

to this

set of the

{A \

A C

poset

poset is

X}

as

example (1)) with a top element topped vertical natural numbers.

in

{0,1,2,3,..., oo}.

of subsets of

set X is often written



and is called the powerset of X. The powerset is

inclusion of subsets, A and A' and

(4)

are

The order is

subsets of X where AC. A! and

transitivity

Given

C B.

are

preorders



as

V(X)

poset with order given by

certainly anti-symmetric, for if A A! C A, then A A'. Reflexivity =

clear. X and

Y, their cartesian product has underlying

set

XxY^{(x,y)\xeX,yeY} with order



(x',y')

iff

x <

x' and y <

y'.

preorder, then X0? is the preorder with underlying set X and order given by a: <^ y iff y < x where x, y G X. We usually call X0? the opposite preorder of X. Of course any poset is certainly also a preorder. The following Hasse diagram is a picture of the opposite of the poset (b):

(5)

If X is

given pointwise, that is {x,y) a



Chapter



Discussion 1.2.4

for every



notation

given

if

x <

vy



Figure

and A is

Order, Lattices and Domains



V preorder

1.



We

Illustrating

1.2:

now

give

some

X is

an

that X is



upper bound for A if

(or we can just write A < x, using the informal 1.2.1). An element x G X is a lower bound for A

X is





Suppose

a < x

in Discussion

A. An element

Definitions.

definitions.

some more

subset of X. An element

£ Awe have





greatest element of A if it is

an

upper bound

belongs to A; x is a ^easi element of A if it is a lower bound of A A we have and belongs to A. An element a G A is maximal if for every 6 a < b implies that a b. An element a G A is minimal if for every b £ A we have 6 < a implies that b a. We can prove a useful little result about of j4 which





greatest and least elements:

preordered set and A a subset of X. Then greatest and least elements of A are unique up to isomorphism if they exist. Proposition 1.2.5

Let X be



and a' be greatest elements of A. By definition, a is an upper and also a' A. Hence a' < a. Similarly a < a'. Hence a a'.

Proof

Let

bound of

A,





The proof for least elements is essentially the



same.

Examples 1.2.6

(1)

Consider the posets illustrated in

certainly



preorder, and

X the elements 1 and

Figure 1.2. Of course, any poset is we consider examples of the above definitions. In poset 2 are maximal. In poset Y, the element 3 is a maximal

element which is the greatest element of Y. In poset

Z, element 4 is greatest

and maximal in Z and 5 is maximal in the subset of Z indicated circles.

by

the

light

1.2.

(2)



Ordered Sets

Consider the poset of natural numbers N with its usual increasing order

and the subset S and



{25,65,100}. Examples

25, and examples of upper bounds

are

of lower bounds for S

are

0, 10

100, 105, 1253 and 245.

bound, maximal element and so on give us mathematical tools for the description of the structure of preordered sets. The reader is probably familiar with the everyday notions of maximum and minimum, and our definitions of greatest and least elements correspond to such notions. Unfortunately, such ideas are not quite general enough for DISCUSSION 1.2.7

our

We shall

purposes.

generalisation Let X be

The notions of upper

define the concept of meet and join which is

now



of the notion of maximum and minimum.

join of A, if such exists, is a least element in the set of upper bounds for A. A join is sometimes called the least upper bound or a supremum. A meet of A, if it exists, is a greatest element in the



preordered

set and A C X. A

set of lower bounds for A.

lower bound

or

infimum.

and least elements;

A meet is sometimes called the

Note that meets and joins

are

defined

as

greatest greatest

from

Proposition 1.2.5 we know that meets and joins are determined up to isomorphism if they exist. If the subset A has at least one join, then we will write V A for a choice of one of the joins of A. Similarly, so

if the subset A has at least one

of the meets of A. If

respect to which

one

we

meet, then

will write A A for



choice of

wish to draw attention to the ordered set with

join and meet



we

are

being

taken

(in

this

case

X)

we

shall

respectively. Note that the join is characterised by the property that for every x G X we have V^^^iff^^^; this amounts to a formal statement that a join is by definition a least element in a set of upper bounds. Using the notation described on page xvi, we could also say that V A is a join for the subset A C X if for every x G X we have write \J x A and

Ax



\/A<x A<x

Similarly, A A

is



meet of



subset A of X if for every x<



£ X we have

/\A

x<A Some

special points deserve attention.

non-empty discrete preorder X, and iCXa non-empty subset. Then A only has a meet or join if A is a singleton set. Clearly, for any x E X, ?

Let X be

we

have



A{#}





and

\/{x}



x.





Chapter

Order,

Lattices and Domains

Consider the empty set, 0 C X. Then \f 0, if such exists, is written _L and

is called for any

bottom of X. Note that





x £

have J_ <

we

is called the top of X; it ?

1.

Consider

this

If



we

by



unravel the

of

and b.



definitions,

it

the property that for every

and

binary

meets

is written T and

Similarly, f\0,ii such exists, satisfies x G X implies x < T. x.

two element subset

(binary) join

bottom element satisfies the property that



by asking

{a, 6}

Similarly can x

be

\J{a, b}

C X. Write a V 6 for a A

seen

6 is

that



(binary)

binary joins

£ X we have aV b <

that for any





iff

meet of are

and call

and 6.



characterised

a < x

and b < x;

£ X we have x<aAbiffx<a

and x < b.

EXERCISE a

preorder

Make

1.2.8

X. Think of

sure

some

simple finite preordered

sets in which meets and

joins do not exist. Now suppose that X is a poset (and thus also Show that meets and joins in a poset are unique if they exist. Discussion 1.2.9

A subset C of

x, y G C



we

C is called say C iff an

an

y.

x <

or

y <

x.







N}.

C is

an

preorder

X is called





preorder).

chain if for every

simply refer to a chain in X. indexed by the natural numbers,

We shall often

u)-chain if its elements

{xn |



x >

have

join in

you understand the definition of meet and

can

be

anti-chain if for every x,y G C then







A subset D of X is called directed if every finite subset of D has

upper bound in D. Note that

we

regard

the empty set

as

finite; thus any

by definition. We say the poset X is directed if any finite subset of X has an upper bound in X. A subset / of a preorder X is inductive if given a directed subset D C X for which D C. I then \fx D I. We shall say that a preorder X is a chain or anti-chain if the underlying set X is such. Given a subset A of a preorder X, then the up-set of A is defined to be At {x G X | x > A} and the down-set is A| {x G X \ x < A}. So the up-set of A is the set of all upper bounds of A, and the down-set of A is the set of all lower bounds of A. We shall write xi for {x}[ and x] for {#}T, directed subset is non-empty



where





G X.

example shows why we take care with definitions involving subsets of preorders and posets. Let X {1,2,..., n, n-f 1,..., oo, T} be the poset with partial order "generated" by Remark 1.2.10

This



!<2<3<4<5...<oo<T. Let I



preorder



\ {oo}

and let D

J with the restriction

\ {oo, T}, and refer order from X (so that J is =



to a

Figure

1.3.

copy of the

If

we

topped

1.2.



Ordered Sets







































Figure

respect to this

which is not at



subset such

See also

1.3: A Subset of

numbers)

then

order; but I is not

an

oo





vertical natural





\fjD an

Poset which is not Inductive. exists in the

J and is T with

inductive subset of X because \fx D

element of /. It is sometimes

tempting for beginners

to



°°

glance

J and think it must be inductive with the restriction order.

as

Example

preorder

1.3.3.

Exercise 1.2.11

Let C and C be chains. Show that the set of

pairs (c, c'), where c C and d G C", is also a chain when ordered lexicographically. Show that the set of pairs with the pointwise order is a chain just in case at most one

of C

or

C has

more

than

one

element.

The existence of meets and

joins for certain kinds of subsets of preordered sets is known as completeness and cocompleteness respectively. If P is a property of a subset A of the preorder X, and meets exist for all such subsets A, then we say that X is P-complete; dually X is P- Discussion 1.2.12

joins exist for subsets A with property P. For example, suppose that X has binary meets and a top element. Then by induction it is easy to see that X has meets of all finite subsets, and we say that X is finitely complete. If X has joins of all directed subsets then it is said to be directed cocomplete,

cocomplete

if

cj-cocomplete. If X has meets be complete or cocomplete respectively. states that a preorder X is complete if

and if X has joins of cj-chains it is said to be

joins of all subsets then it is said to We can give a very useful result which and only if it is cocomplete: or

Lemma 1.2.13



preorder

X has all meets

just

in

case

it has all

joins.

10

Chapter

/\ A

that A is any subset of X. Note that

Suppose

Proof



\/{x |

Order, Lattices and Domains

1.

x e

X and

A}

x <

and

=f

VA

one

f\{x \



has X and A <

x}. □

Examples 1.2.14

(1)

Given

X, the powerset poset V(X) is both complete and cocomplete. given by intersections and joins by unions. The top element is of



set

Meets

are

course

X and the bottom element 0.

(2) Suppose

that

say X has meets as

preorder X is finitely complete and cocomplete, that is to and joins of all finite subsets. We regard the empty subset



being finite and thus X has top and bottom elements. We

Discussion 1.2.15

now

turn

our

attention to notions of relations

preordered sets, and in particular to functional relations. If we talk of a function between the preordered sets X and Y we shall simply mean that we are given a function between the underlying sets. Such a function is said to be monotone if for x,y X we have x < y implies f(x) < /(y); and antitone if x < y implies f(y) < f{x). We often refer to such a monotone function as a homomorphism of preorders. Roughly one thinks of a homomorphism as a function which preserves structure; in the case of a preorder, this structure is just the order relation. A monotone function may alternatively be called an order preserving function. / is said to reflect order if given any x,y X, f(x) < f{y) implies x < y. The posets X and Y are isomorphic if there are monotone functions f:X X for which gf Y and g:Y idx and idy. The monotone function g is an inverse for /; and likewise / is an fg inverse for g. We say that / is an isomorphism if such an inverse g exists. The

between

—*■

—?





set X

=>

Y is defined to have elements the monotone functions with

and target

Y, that is functions X

—*■

Y. This set

by defining a relation / < g iff given any x Y. This ordering is often referred f,g:X have the following proposition: —*■

Proposition 1.2.16

The

identity

function

can

be

regarded

X we have

to

on

as

the

any

f(x)

source

as a





preorder

g{x),

where

pointwise order. We

preordered

set is

monotone, and the composition of two monotone functions is another monotone function. Now let

X, Y and Z be preordered o:

(Y

=>

Z)



(X

=?

Y)

sets. The

->

(X

=?

composition function

Z)

1.2.

11

Ordered Sets

the

sending

pair (p, /)



(Y

Z)

=>?

(X



preordered

monotone function between

y'

any x, x' G X and y,

given



to

p/

X =>■ Z is itself



Finally, any function f:XxY variable separately, which is to say

sets.

Z is monotone iff it is monotone in each that

V)

=>■

—*■

y, then

x <

x' implies

y <

y' implies /(x,y)

/(x, y)

f(x', y)



and

Proof

Follows

by



routine

f(x,y').



of the definitions.

manipulation



Examples 1.2.17

(1)

Let

/: X

—*■

Y be



set-theoretic function between sets X and Y.

f ̄l: V(Y) d=lf r1^) {xex\ f(x) g5}.

there is

(2)



monotone function

"P(X)

—*■

where

Take R to be the set of reals with their usual

/:E

—?

K. defined

by f(x)



Then

given BCFwe define Then the function

ordering.

x3 is monotone.

Exercises 1.2.18

(1) Complete

(2)

the

proof

of

Proposition

1.2.16.

product. Check that there are monotone functions nx'-XxY X, {x,y) i—? x and 7Ty: X x Y y, (x, y) I—? y where (x, y) G X x Y. Now verify that given monotone functions X and p: Z y where Z is any given preorder, there is a unique f:Z monotone function m: Z X x Y for which f 7rxm and g rKym. Let X and Y be

preorders

and X xY their cartesian —?

—?

—*■

—?-

—?

(3)

Find



counterexample

y between f:X isomorphism. —?



to the

ordered

statement.

posets X and y which is

(4) Let X be a poset and define just in case x < y and there is be any set and Y be

following





relation

no z



poset. Let X

pointwise. Show that /

-< g



on



A monotone function

bijection

the set X

X for which



is

necessarily

by saying <





y.

that

(where /, g

G X =>

Y)

x -<



Now let X

Y be the poset of functions X

=¥■

an

—>



iff

(a) There is x G X for which /(x) -< g(x) (b) /(x) g(x) for each x G X \ {x}.

in

Now let X be

Y the poset of monotone functions

Y, and





—*

of x



finite poset, and X

Y. Show that =?

y.



-< g

iff

(a)

and

=¥■

(b)

remains true, with this

new

definition

12

Chapter

Basic Lattice

1.3

Theory

In this section

Discussion 1.3.1

Order, Lattices and Domains

1.

we

shall describe

which have additional structure and which feature in

categorical poset

we

structures which model functional

shall



formal

poset which has finite meets and joins. A complete lattice poset which has arbitrary meets and joins. A poset X which has finite

A lattice is is

type theories. For each kind of

definition, some examples, and certain elementary give further examples.

give its

theorems which will

examples of posets concrete examples of

some

meets is called





meet-semilattice;



join-semilattice is

defined

We

analogously.

shall want to consider functional relations between such structures; those

we

consider will

usually preserve structure and are known in general as homomor- phisms. Thus a homomorphism of lattices is a function f:X —>Y (with X and Y lattices) which preserves finite meets and joins, that is f(xAy) f{x)Af(y) =

and a

is

f(x V y)

function is a

f(x)



function



f(y)

and also

/(T)

automatically monotone. Y (with X and f:X —*■







/(_L)

T and



_L. Note that such

homomorphism of complete lattices complete lattices) which preserves

joins (and hence is monotone). A sublattice A of a lattice X is a subset A C X for which given any finite subset F C* A we have Vx F £ A and /\x F G A. Note that this definition is tantamount to saying that if A meets and

regarded as Vx F Va F.

is





poset by restricting order from X, then /\x F

Given



sublattice A of



lattice X, if

we

regard

f\AF





as a

and

lattice

with the restriction order from

X, then the inclusion function i: A —? X is a homomorphism of lattices. If A and X are lattices, A C X as sets, and the inclusion i: A —? X is a homomorphism of lattices, then A is a sublattice of X. Remark 1.3.2

poset X,

one

Because

and iV y

just only needs to check the existence of binary x A











in

case x



meets and

y in



joins of

non-comparable pairs of elements of X to see that X is a lattice (as well as checking that X has top and bottom elements). Note also that a complete lattice has top and bottom elements (being the join and meet of the empty

subset). Remark 1.3.3 for A to be



Note that if A C X and X is



lattice, then it is possible

lattice with respect to the restriction

ordering from Hasse diagram of

being a sublattice. An example is given by the Figure 1.4, where the black discs indicate a subset restriction order, but not a sublattice.

which is



X without a

lattice in

lattice under the

1.3.

Basic Lattice

13

Theory

Figure

1.4: A Subset which is not



Sublattice.

Examples 1.3.4

(1) N, Z, Q,



lattices with their usual

order, where binary meets maxima; for example in N, 3 A

are

given by taking minima and 3. If we adjoin a top and bottom min{3,5}

joins

are

R* is



{—oo}, <)

where for every

G R we have



complete lattice due to the completeness

and

oo





oo are

C R is a





oo

axiom for R.

the top and bottom elements of R

[r1? r2]

closed interval



to the set R to obtain R*



(R U {oo}

and







< oo, then

Here, of course,

respectively. Similarly

any

complete lattice when its order is inherited from



(2)

The power set

V(X)

of



set X is

order, with meets and joins given by



complete

lattice with the inclusion

intersection and union. The top element

is X and the bottom element is 0.

(3)

The down sets

{A[ \

A C

X}

of



poset X form



complete

lattice via

intersection and union.

(4)

The

(5)

The poset





vertical natural numbers form

topped

(N, |) (where

km and km

meet of



and

by greatest



we

put









lattice.

iff there is

some

multiplication of k and m) is a least common multiple lcm{m, n}

means

is the

common

divisor

gcd{m, n}.

In fact

(N, |)

is



k G N for which

lattice in which the and the

join is given complete lattice: see

page 18.

(6)

Let G be

by inclusion, H AK





group. Then

is



lattice in

(Sub(G), C),

the union of the





(H



K),

underlying

of normal subgroups

by H V K

subgroups

of G ordered

which, given subgroups H and K of G,

H OK and H V K

generated by

the poset of

where the latter is the

sets of H and K.

we

have

subgroup

Also the

poset

(NSub(G), C) is a lattice where in this case join is given HK, where HK {hk \ h G H, k K} is well known to be a =

14

Chapter

Figure

1.5:

of the Dihedral

Subgroups

Order, Lattices and Domains

1.

Group

of Order 8.

normal

subgroup of G. For example, the Hasse diagram in Figure 1.5 shows the lattice of subgroups of the dihedral group of order 8, in which we have used black discs to indicate the normal subgroups. If X and Y

(complete) lattices,

their

binary cartesian product is the set X x Y of pairs of elements, ordered pointwise. Then X x Y is a (complete) lattice with meets and joins calculated pointwise. In a similar way we can x consider the cartesian product of a finite number (say n) of lattices X\ x (7)

are

...

Xn.

(8)

Let S be any set and X

poset. Then the

(the underlying set of) X is a (complete) lattice whenever (complete) lattice, with S => X ordered pointwise. It is easy to see that



meets and for any



joins

are

pointwise. For example, if /, g

calculated

£ X we have

(/



g){x) useful

f(x)



some

Lemma 1.3.5

lattice X satisfies the







A y





y A

(iii)





(y A z)

(iv)

x A

(x V y)

(v) (vi)

elementary

facts about lattices.

following laws,

where x, y and

taken to be any elements of X.

(i)xAx (ii)

Any

G S =>■ X then

g(x).



The next lemma lists

are

set of functions S => X with

S and target

source

X is



x <

x\/x x





and

(x A y) x V



then

x A

(vii) (xAy)V(xAz) x

x V





implies



y A



t/V





(x A y)

y iff either xAy

If y <

(viii)

(idempotency). and =

x A z









(y A z)



(yV z)



(x



y)





(associativity).

(absorption).

and

(y



a:

(commutativity).

xVy

x or

y <







z) (x



x V

and V

y)

y. y < xV x







(y A z)

z.

(monotonicity). <

(x



y)



(x



z).



1.3.

Basic Lattice

Proof

The

For

example,

and

x <

proof is

{A-i \



fl



XeT. we

i G

1}

be



(x

x <

properties of meets and joins. y implies y A z < (x V y) A z\

y)



set and let J7 be





z.

set of subsets of X. T is



X if

on

set of subsets

non-empty

{A{ \

i G

/}



T, and

have

regarded

Proof

and

hypothesis imply

G J7 ioi every

A set of subsets T of

Proposition 1.3.7 can

note that y < xV

Let X be

system

of the

application

easy

(viii),

xW y and the

Discussion 1.3.6

Then

an

to prove

called a closure

15

Theory

as a



set X which is

poset via inclusion, and this poset is





closure system

complete

top element non-empty subset

From Lemma 1.2.13 it is sufficient to prove that T has

meets of

of T. As f| S

non-empty subsets. Let S



G T and for each



{A{ \

G / we have



f]S





/}

be

Aj

it follows that



lattice.

f| ?S is



bound, then clearly B C f| S. Hence complete lattice with meets given by intersections, where of course we

lower bound for <S. If B is another lower T is can



deduce from Lemma 1.2.13 that

\JS



f]{B

G T

| At

C B

each i G

/}.

X is the top element of F. DISCUSSION 1.3.8



Let X be



set and AC. X



closure operator

on

X if for all

subset. A function

A^A,

C:V(X)->V(X), is called

a,

A, B C X,

?AC ̄A, ?

AC B







implies

A C

B, and

A.

A subset A of X is called closed if A

Proposition 1.3.9

Let C be





A.

closure operator

set

Fc



{ACX\A



A}

on a

poset X. Then the

16

Chapter

of closed subsets of A" is

given

any

(non-empty)

closure system and hence is



subset

A{^|t

{Ai \

/}

if T is



we

complete lattice,

where

have and

\J{Ai\ieI}.



closure system

Tc





f){Ai\ieI},



\f{Ai\ieI} Conversely,

1}



Lattices and Domains

Order,

1.

on

X and AC

X,

then

Ad^f]{BeT\ACB} defines



closure operator

mutually inverse, Let

Proof



Tc?

check that if C is

Given



Moreover, these assignments

the set X.

on

that is to say T

us

closure system.

C?



and C



Cpc.

closure operator

non-empty subset S



are

{Ai \i

X, then Tc is a 1} C Tc-, we have

on



f| S C A{ for every i £ I and thus

f]Scf](Ai\ieI} which is to say f] S

Tc is



complete

Next exist

as

specified

{Ai |



/}



specified

is trivial.

S. If B G

an

least.

is the

formulae for meets and

We check the existence of G

upper bound

join of 5,

The converse, and that the task in set

Tc- Thus from Proposition 1.3.7

lattice.

Tc, certainly \JS

Tc is Hence (J ?S

f]{Ai\iel}=f]S

Tc- It is clear that X

check the

we



Tc, and this is clearly for <S, then \JS C B

joins. That meets joins. Given S =

an



as

upper bound for

B, showing \JS

is

asserted.

assignments

are

mutually inverse,

is



simple □

theory. Fill in the details of the

EXERCISE 1.3.10

proof

of

Proposition

1.3.9.

Examples 1.3.11

(1)

(the underlying sets of) subgroups and normal subgroups, NSub(G), of a group G are closure systems on (the underlying set

The families of

Sub(G)

and

of)

G.

(2)

The set





| ̄

C X x

system. It is easy to

equivalence relation.

see

X}

that

of

an

equivalence

relations

on a

set A" is



closure

intersection of equivalence relations is another



Basic Lattice

(3)

The linear and

systems

convex



Let X be



(Strictly system).

poset and

of



we

should take

subspaces

the vector space.

on

the definition of closure

(4)

17

Theory

1.3.

X(X)

Cx(x)'- *P(X)

(the underlying

of)

set

V(X)

—*■

each closure

are

underlying

the set of inductive subsets of

closure system. The closure operator

A of

real vector space

sets to match

X\ then T(X) is takes any subset

X to the smallest inductive subset of X which

contains A.

(5)

The

(6)

Let X be

on

(the underlying set of)





topological

system is



if

no

given

X. Of

topological

course

there is



length n if \C\ infinite chains.

closure operator





poset. If C is



X satisfies the

some

results which

(xn \

n0 G N for which xno

going to gloss too many people.

we are

Lemma 1.3.13 X has





N)



over

the axiom of choice and I

(ACC)

A poset X satisfies



closure

we

hope

say

then

length,

(ACC)

The dual



formal set

some

taking

in X for which

xno+i We shall



descending chain condition (DCC). show how completeness can be characterised

The astute reader who knows



chain condition

ascending

statement is the

(DCC).

on

finite chain in X



+1. If every chain in X is of finite

any sequence of elements of the form

%n < #n+i > then there is

and

closure system

are a

closure.

Let X be

DISCUSSION 1.3.12 that C has

space. The closed subsets of X

By Proposition 1.3.9, such complete lattice with joins given by closure of unions.

subset of X to its

X has

R and also the set of ideals of R form closure systems.

subrings of a ring

now

give

in terms of

theory

will



few

(ACC)

see

that

this will not offend

iff every non-empty subset A of

maximal element.

Proof

(=>) no

Let A C X be non-empty and suppose for

maximal element.

We

can

argue

informally

hypothesis,

there is X2 G A such that X\

in A

find x3 G A for which X\ < x2 < xz.

we can

choice) (ACC).

the axiom of contradicts

(<=) no

If there is

this



gives

us an

< #2-



as

follows.

But

as X2

Let x\ G A.

is also not maximal

< X2 < Xz.

satisfy (ACC),

then it

?.

in A which

certainly

maximal element.

Theorem 1.3.14

and

(DCC).

By

Inductively (strictly, invoking

infinite chain Xi

chain that does not

contradiction that A has

has □

A poset X has

no

infinite chains iff it satisfies both

(ACC)

Chapter

18

Order, Lattices and Domains

1.

Proof

(=>)

This way is clear.

(<£=) Conversely

suppose that X satisfies

infinite chain, say C.

(ACC)

(DCC)

and

and has

non-empty, with maximal element

Then C is

chain it is easy to

using Lemma 1.3.13. As C is



element for C. Now let

\ {xi}

that x\ is

see

an

Xi G C

greatest



(we can do this for C \ {xi} is a non-empty chain; thus Lemma 1.3.13 applies) and in general let xn+i be C \ {#i,... ,xn}. Then we can deduce (strictly, invoking greatest in Cn+i the axiom of choice) that (xn | n G N) is an infinite (descending) sequence of □ elements in X, which contradicts the (DCC). x^ G C

be greatest



Theorem 1.3.15

(i)

If X satisfies

Let X be

(ACC),



lattice. Then

then for every non-empty subset A of

finite subset F C X for which \JA



X, there is



\/F.

(ii) If X satisfies (ACC) then it is complete. Dually X is complete if it satisfies

(DCC). (iii)

If X has

no

infinite chains then it is

complete.

Proof

(i)

Consider B



{V F \

A, F is finite} where A is

F C



given non-empty

subset of X; note that B is well defined and non-empty. So by Lemma 1.3.13

there is



maximal element

note that if





A, then V ^o

maximality and hence completing the proof.

(ii)

Note that



<m.



(i) implies

that

of B, say





V i*o- Claim

V(iro U {a}) implying



Suppose

now

(the lattice)

that

A < x; then

X has











\J A. To =

see

this,

\f(F0 U {a}) by

\J Fq <\J A < x,

joins of all non-empty subsets

complete. Dually, we would have that X has meets of all nonempty subsets and is therefore complete. and is therefore

(iii) Immediate from Theorem 1.3.14. □

Example 1.3.16

It also satisfies of elements in

(N, |) (n* | i

The lattice

(DCC). For if (N, |) then we must

where < is the vertical

is

complete.



N)

have

an

It has

infinite



top element OeN.

descending infinite descending chain is

an

ordering. Contradiction.

sequence

in

(N, <)

1.3.

Basic Lattice

19

Theory

simple results concerning the distributive and modular lattices. These lattices have pleasant properties which aid the manipulation of meets and joins. Let X be a lattice. Then X is distributive if it satisfies x A (y V z) (x A y) V (x A z) for all x, y, z in X. X is called modular if x < z implies x V (y A z) (x V y) A z. Discussion 1.3.17

by giving

We end this section

some





From Lemma 1.3.5, parts (vii) and (viii), we see that in order to check that a lattice is distributive or modular it is only necessary to Remark 1.3.18

check that

an

LEMMA 1.3.19

(i)

For any lattice X the

For every x,y,z £ X

(ii)

For every x, y,

PROOF



which is

(iii).

If

the

(y

have

(y



z)



z)



(y

x V

(y

(x



z)





z)



y)



(x



(xAy)V(xAz)

then

< x A

we

y)



(x



(x



y)



z),



(x



[(x A y)

(*),



equivalent:

are

z),



2.

(i)

holds then

(xAy)Vz

have V

To

see

hypothesis (iii)

we

obtain the first

half of

z)



(i).

one

conditions

following

the results of Lemma 1.3.5. If

we use

(iii) holds,

x A

namely

we

(y

x A

G X we have x A

Throughout x A

have

we

For every x,y,z £ X

(iii)

on

holds.

inequality

z]



(x



z)

(x



y),



(*)

by using monotonicity of x A (—) inequality. We can also use (iii) to

note that

deduce that

For every x,y,z G X

we

have





(y

and then use this deduction to obtain the second

half of

(i)

holds via Lemma 1.3.5. That

(ii)

iff



z)



(x



inequality

(iii)

is



z)

of

V y.

(*).

The other

similar argument.



Examples 1.3.20

(1)

The poset

follows from

V(X)

simple

is distributive. naive set

(2) Any poset which is

(3)

The



theory

For if

A, B and C

that A f)

chain is distributive.

complete lattice (N, |)

is distributive.

(B



C)



are

subsets of

(A f) B)



X,

(A Pi C).

it

20

Chapter

(4) For any group G, NSub(G) is modular.

the set of normal

Order, Lattices and Domains

1.

subgroups

with the inclusion order

if, K, N be normal subgroups of G.

For let

enough to prove that if TV C H then H A (K Suppose that g G H A (if V N) and thus g G H and g

Lemma 1.3.5, it is

(H A K)

V N.

k G K and

(5)



£ N. Note A:

The lattice of

<?n-1



subspaces of a

If X is

the

pointwise order,



vector space is also

distributive lattice then S is



DISCUSSION 1.4.1

=>



Heyting

In this section



modular; the proof of this

subgroups.

we

Lattices introduce the notions of Boolean and

distributive lattice for which



the notion of

complementation complement of A in V(X) is

V(X) then the from X). Readers

powerset (recall that if A G

the set difference X

kn for

X, the functions from S to X with

Heyting lattices. A Boolean lattice is, roughly, there is an operation on elements which mimics in



distributive lattice.

Boolean and

1.4



N)

if and so we are done.

fact is similar to that for the lattice of normal

(6)



By

A of A

may have met the notion of

undergraduate or even school circuit theory, but this will not concern us here. A Heyting lattice can be viewed as a primitive model of functional type theory, as we shall see in Chapter 4. In this section we simply concentrate on the basic theory of Boolean and Heyting lattices. Boolean lattice from

Take and in





lattice X and let

x G

X. An element





satisfying

complement of x. The next proposition distributive lattice, such complements are unique.

a V x



T is called

Proposition 1.4.2



Let X be



distributive lattice and x, y,

there is at most one a G X for which x A

PROOF

Suppose

that a'









f\z



oA(xVa')



and y < a! and

y and xW

so a







hypotheses.



±

shows

that,

G X.

Then

z.

We have

(a V x)









X also satisfies the a

But y <





a Ax

(aAx)V(aA a')

yV(aAo'). aAa'.

Similarly a'







a' and

so a



a'.



Boolean and Heyting Lattices

1.4-

21

lattice, which also has complements of all elements. We write ->x for the complement of x where x G X. Note that it makes sense to talk of the complement of x, because Proposition 1.4.2 implies that complements are unique if they exist. The next lemma states some laws which are true of all Boolean lattices, and are A Boolean lattice X is

Discussion 1.4.3

of the well known De

analogues

Lemma 1.4.4

(i)

-i-ijc







(hi) ->(x V y)

->x V



->x

we

have for all x, y G

X,

A ->y.

Proposition

use

->:

and

->-ix

x are

complements

(i)

1.4.2 to deduce that



this function is antitone. =

X,

-*y, and

well defined function

->y

rules which hold for powersets.

Morgan

Boolean lattice

Note that both

X. Then

distributive

x,

(ii) ->(x A y)

Proof

In



—?

(and (i)



To prove

this,

of the element

holds. There is of

shows that it is one



shows that if

course a

bijection). x



in

->x

In fact

y in X then

by showing that ->y A -*x is a complement of y and thus equals ->yA -ix implies ->y < ->x, as required. Then (ii) and (iii) follow □ that is an antitone bijective endofunction on X.

->y A ->x,

->?/. But ->y



from the fact

->

Examples 1.4.5 a

set and

define,

for A C

Boolean lattice.

(Recall

that X

\A

(1)

Let X be

(2)



A is finite

Boolean lattice in which ->A



(3)

C X

The subsets of



topological

Boolean lattice in which -?A





or

\A





\ A,



is

both open and closed is



set

X).

X,

finite}

\ A.

space X which





is

is the set difference of A from

The collection of finite and cofinite subsets of

{A is

d= X \ A. Then V(X)

 ̄>A

X,

are

where A is



closed and open subset of

X.

(4)

Let

us

poset with

write Q for the

point underlying

two



which _L < T. We call this the of



(5)

finite number of copies of

The set of



A s



rs,

the reader.

r V s





element =

4-

r.



...

of any commutative

idempotents

idempotent of R is an by setting r < s iff rs

Sierpinski poset. Then the x Q, is a Boolean Q, Q, x





for which r2

ring J? is



r.

and

->r







r.

{J-,T}

cartesian

for

product

lattice.

Boolean lattice. An

We order the

Then the Boolean lattice rs



set

idempotents operations are given by

We leave the verification to

22

Chapter

Discussion 1.4.6

Heyting



elements y,z G X there is

We call y

the

=> z

Lemma 1.4.7

element y

an

<y



lattice X is

X such that

=> z £



Heyting implication of y and

In

Heyting



lattice

pair of

lattice in which for each



iff

=> z

Lattices and Domains

Order,

1.

Ay



z.

z.

X, the Heyting implication of y and



is

unique. PROOF Then

a <

Suppose that a and a' are two a implies a Ay < z implies a

Proposition 1.4.8

Let X be

PROOF Then

< ->x V y



Boolean

lattice,

Ax

x, y G



G X.



is similar.

converse

lattice.

Heyting

X, and define

(->x V y)

A x



(->£







_L V

(y A x)



Ax





the



x =>

def





-?x

V y.

implies z

and

a';



Boolean lattice is

Every a

candidates for the element y =>

<y implies

->x

V y >

x)

(y A x)

y,

->x



(z A x)



(->x V 2)



(->x



x)





z.

Proposition 1.4.9

(i)



Heyting

(ii) Any (iii) we



lattice X is distributive.

finite distributive lattice X is

Heyting

define

->x

lattice X is



x =>





Heyting

lattice.

Boolean lattice iff for all

x e

X,

->->x



x, where

J_.

Proof

(i)

Recall Lemma 1.3.5 which tells

us

that

(x A y)

(x A z)









(y V z).

Then

note that

x=>((xAy)V(xA z)) which amounts to

(x A y)





(x

(x A z)

=>

(x Ay))\/ (x

> x A

(y



z),

=>

and

(x so



z)) >yV



X is distributive.

(ii)

23

Boolean and Heyting Lattices

1.4-

Take

implies

and y and define







x =>

(iii) (=>)

Ax <

This way is part

have

we

(i) just

There is





a: =>

seen

lattice

rules

X).

(ii)

and

Hence T



y}.

Then



Ax

<y

->x

and

X).



distributive, and

that X is x A

(x

=>

_L)

->:

it is easy to check that it is antitone and

Morgan's



y then

the finiteness of

well defined function



\u Ax

G. X

of Lemma 1.4.4.

x A ->x

is trivial.

V{^



\J{u Ax\uAx<y}<y

distributivity (and

(<=) Conversely,



y is immediate. If z

follows from

x =*?





J_



—*■

given by

x 1—?

Thus it follows that De

bijective.

(iii) of Proposition 1.4.4 hold (but ->(x A ->x) ->x V x as required.

here in the

Heyting



□ Examples 1.4.10

(1)

Let X be

meet and



join

chain with top and bottom are

elements;

so

X is



lattice in which

given by greatest and least elements. Then X is Heyting

with

{T

if

x <



y otherwise

where x, y G X. x

G X:

(2)

Note that X is not

Proposition

see

Take X

an



Boolean

lattice, for



T for all

1.4.9.

infinite set and let J7 be the set of finite subsets of X

with X itself. Then T is



sublattice of

V(X)

and

Heyting. For if F C X is a finite subset then no largest member and so F => 0 cannot exist.

is not

has

-r->x

so

along

is distributive. But F

the set

{Y \

Y C\ F



0}

Exercises 1.4.11

(1)

Let X be any poset with finite meets. Prove that X is

for all

x G

X, there isxGX such that for all y G X x

some

(2)

Let X be



Heyting lattice,

and for each

_L. Prove that for any x,y G

-i->x A



Ay



Boolean lattice iff

have



fixed b G X.

for

x =>

iff

<y

we



-i-iy.

X, ->(x

x G



y)

X make the definition =

->x

A ->y and

->x

->-?(x Ay)

def =



24

Chapter

Elementary

1.5

Discussion 1.5.1 semantics of

Domain

The concept of



domain.

Order,

Lattices and Domains

Theory



pervades the theory of unfortunately no (fixed)

domain

programming languages, yet there is

definition of

1.

A domain in computer science has

come

to

formal mean a

cocompleteness property, that is, joins of various kinds are required to exist. For example, wcpos and dcpos may be referred to as domains. Domains arose from attempts to give semantics to recursively defined procedures, and we now give a summary of (some of) the key ideas. poset which has

some

kind of

Suppose that we have a recursive procedure P which takes elements of a datatype D and returns elements of a datatype D'. Now let us model this procedure P as a function [P], from a set [D] which models D to a set \D'\ which models D'. Suppose that we have a sequence of data items {di | i G N} each of which yields more information about another data item d—we can think of the approximations as successive recursions of the procedure P. We might then model this by taking [D] to be a poset, in which the poset order is representation of the notion of data approximation. In this case, if we have a chain, say {[di] | i /} in [D], modelling the approximations to the data item d, then the join of the chain should exist and be thought of as modelling the a

given by the approximations. In this case, [D] would then be o;-cocomplete. If we perform more iterations of P, we might hope to get a more accurate output. In our model, this would be tantamount to asking the function [P] to be monotone. Further, if the chain {[di] | i N} is thought of as modelling the series of approximations (datatypes) {di | i N} to the data item d modelled by V{[^t] | i G N}, we could ask that the data item given by the output approximations {P(di) | i G N} (resulting from applying P to the input approximations) is the same as the data item P(d) (given by applying P to the data item given by all of the input approximations). In our model, this would mean that [P] should preserve joins of o;-chains. total information

V{[p](WD I The



N}



[P]{\f{[di] |

i e

N}).

of domain

theory in computer science arose from these very tentative and tenuous thoughts; but it has proved to be a very powerful tool. Let us now move on to some more theory. use

cocomplete partial orders as dcpos and to enchain cocomplete partial orders as ucpos. A homomorphism of dcpos X and y, /: X Y, is a function which preserves the structure of X, which is to say / is monotone and if D C X is directed, then f(\f D) =\f f(D) where the join on the right hand side exists for / is monotone. A homomorphism of u epos is We shall refer to directed

—?

Elementary

1.5.

Domain



25

Theory

dcpos (wcpos) will also be referred to as a continuous (uj-continuous) function between dcpos (u;cpos). If X and Y both have least elements then any function /: X Y is said to be strict if _L If X is a dcpo then the set A is a sub-dcpo of X if A C X, and /(_L) given any subset D C A where D is directed in X, then \fx D e A. Thus if A is a sub-dcpo of X and A is given the restriction order from X, then the analogously.

defined

homomorphism

of

—?



inclusion i: A

dcpos,

A C

X is

—*■

X, and i: A



Note also that if A and X

continuous, then the set A is

X is

—?

Let X be

Remark 1.5.2

D in X exists

continuous function.



poset and D



sub-dcpo

are

of X.

directed subset of X. If the join of



\JxD f°r it, rather than \fx D. This notation will be useful in later chapters when directed sets will play a crucial role, and it will be convenient to distinguish directed joins form other kinds of join. Note that part of the force of the judgement \JxD 1S that the set D is directed. we

shall write

Examples 1.5.3

(1) Any complete (2) Any

lattice is

anti-chain is



certainly

dcpo



and

dcpo

and any poset

an

o;cpo.

satisfying (ACC)

is



dcpo.

subgroups Sub(G) of any group G is a dcpo. For let H C Sub(G) be a directed subset of subgroups of G, say H {Hi \ i G /}. If (J W is a subgroup of G then it is clearly the join of 7{. But if g, h G U W then g G Hi and h G Hj for some i, j G /, implying that p/i_1 G #* for some fc G / because (3)

The poset of



7i is directed. So of

(4)

Given



poset X and

(i,j)

i—?

X(ij)



Let / be

they

are

so





U^

on

is indeed in

X,

Sub(G).

the set of closed subsets

dcpo.

directed poset, X



poset, and /:/





—?

X,

monotone function. Put

Show that if the join and

and

closure operator C



of X with the inclusion order is

Exercise 1.5.4

|JW,

g/i-1

course

all





x'



x"





\/{\/{x{i,j)\jel}\iel} \/{\/{x(ij)\i l}\j l} V(x(m) I (?,?)

(x') exists,

then

so

/ x

do the

/} joins x' and x" (x and x"),

equal. Let X and Y be

dcpos (wcpos). Then the set X => Y of continuous functions X V with the pointwise order (which is to say that / < <7 iff for every i6lwe have /(jc) < g(x) in Y) is a dcpo (wcpo). Proposition 1.5.5

—?

26

Chapter

Proof

Let

{fa \

i G

/}

be

Y by setting f{x) /: X Certainly the function / is —?



directed subset of X

U{/i(#) |?



Order, Lattices and Domains

1.



/},

=>

for all directed subsets D of X. This

function a

dcpo.

that it is continuous; but

required join provided fa is. More precisely, /

|_KLK/<(?0 \deD}\iei}



well defined because V is

the

/ is continuous because each

Y. Define

is continuous if

UUMM \iel}\deD)



follows from Exercise 1.5.4.

equality



Exercises 1.5.6

(1) Suppose a

that D is

an

continuous function. A

A least

o;cpo with



fixpoint of /

bottom is

element, and that f:D—>Dis

element

an

x G

D for which





f(x).

/ is such an x for which given any other fixpoint d of /, x < d. Prove that / always has a least fixpoint and find an explicit definition of it; recognise that any such least fixpoint is unique. Hint: think about the action of f on the bottom element _L of D.

(2)

fixpoint

Let D be

of

previous exercise there is a well defined function Y: (D =>■ D) —? D for which given / G D => D, Y(f) is the (unique) least fixpoint of /. Using Proposition 1.5.5 we see that D => D is

an

an

o;cpo with least element. From the

u;cpo. Prove that the function Y is continuous.

It is time to

DISCUSSION 1.5.7

give

some

definitions which will be crucial

to the formulation of domain-theoretic models of X is is





poset. An element e

directed suoset and the

d G D for whijh

e <

X. A subset B of



lis said

join \_\D

this with the notion of

is said to be in

X,

its

bounded

has

an

algebraic

if for each

join exists, and

cocomplete

upper

if

bound)

the

all non-empty meets.

compact if whenever D C X

to be

exists with

U-^) then there is

e <

some



join of



finite number of elements of B.

basis of



topological space).



moreover x

given S then the

X, the set {e =

\J{e

G X°

G X°







| e x}.

C X and x G X such that



The poset X

x}

is directed

The poset X is

S < x

(that is,



join of S in X exists. It will be useful to have

following alternative characterisation should help to make the definition a little Proposition 1.5.8

that

d. We shall write X° for the set of compact elements of poset X is a basis of compact elements if B C X° and

every compact element of X is the

(Compare

polymorphism. Suppose

of bounded more

A poset X is bounded

cocompleteness,

which

tractable.

cocomplete just

in

case

it has

Elementary

1.5.

Domain

27

Theory

Proof

Take S C X non-empty. Then

(=>)

/\S by



\/{xeX \x<S}

Lemma 1.2.13, which exists because the set

bound

{x

G X







S}

has upper

S.



(<=) Suppose

that SCI and S has

\/s exists because it is



meet of





an

upper bound. Then

/\{xex\s<x}

non-empty



set.

Examples 1.5.9

(1) is

topped vertical natural numbers X certainly algebraic. The

N U



(2) For any set X, the compact elements of the finite cardinality. Also V(X) is algebraic.

(3)

If G is



elements of

(4)

group, the

has X°

V(X)

poset

are

of G

finitely generated subgroups

are



N, and X

the subsets of

the compact

Sub(G).

If V is any vector space, the finite dimensional

compact elements of

(5)

{oo}

Sub( V),

the poset of

subspaces

subspaces

of V

are

the

of V.

The set of real numbers R with its usual order does not have any compact

elements.

(6)

Let X be



poset with finite cardinality.

Then every element of X is

compact. Let X be

DISCUSSION 1.5.10 said to be ?

it is



given



an

algebraic



set and F



set of subsets of X. Then T is

closure system if

closure system, and any directed subset V C T

(where

we

regard

.Fasa poset via

inclusion), thenU^e^7. A closure operator C

on a





is the

algebraic

\J(B \BCA, \B\

cardinality of B. This examples of algebraic posets.

where more

\B\

set X is said to be

is

if for all subsets A C

X,

finite}

definition will allow

us

to

produce

some

28

Chapter

Proposition 1.5.11

Let C be

an

algebraic

1.

Order,

closure operator

Tc for the set of closed subsets of X. Then Tc is

write

lattice in which A G T is compact iff A

Y for



Lattices and Domains

some

an

on a

set X and

algebraic complete

Y C. X with

\Y\

finite.

Appealing to Proposition 1.3.9, we already have Tc is a complete lattice. We begin by showing that joins of directed subsets of Tc are given U<S. by unions. From Proposition 1.3.9, we know that if S C Tc then \j S Proof



Suppose that S [J5 U<S. For if

{A{ \



i G

1}

is

directed subset of Tc-



We show that



\JS \J(B \BC\JS,\B\



then

x G

B C

Aj

B C

for

Next

we

Aj

some



is

(J?S, because for any B C \JS j£L C

finite}, |i?|

have

we

prove the stated characterisation of compact

finite

implies

elements. Let Y



X,

\JS. Then yc(J5andso7C Aj for some \Y\ be finite and Y C \JS j /, implying Y" C Aj Aj and thus showing that Y is compact. Conversely, =



take A G ^c compact. It is immediate from the definition of Y. operator that AC.Y with Y C A and \Y\ finite. So A

algebraic

closure



Finally, if

look at the definition of

we

clear that to prove Tc is

{E for any of

given

Tc |

E C

A)

(B |



Tc- That these sets

A G

Tc, follows by



an

algebraic closure system, it is now algebraic complete lattice, it is sufficient to prove



B C

are

A, \B\ finite}

equal,

and indeed directed subsets □

routine argument.

Theorem 1.5.12

(i)

Let T be

complete

(ii)

algebraic

closure system

on a

set X. Then T is

an

algebraic

lattice.

Let X be

Then T

an



algebraic complete lattice and define Xx {Xx \ x G X} is an algebraic closure system an

poset is isomorphic



{e

which

£ X°



e <

regarded

x}.

as a

to X.

Proof

(i)

Proposition 1.3.9 we know that T is a complete lattice, and that T Tcjr- So appealing to Proposition 1.5.11, all we need is that Cj? is an algebraic closure operator. This amounts to proving that From



f]{L

G T



A C

L}



\J{f]{L

G T



B C

L} \

B C

A, \B\ finite}

Domain

Elementary

1.5.

for every A C. X. Note that the a

29

Theory

right

hand side is well

directed union of elements of T which

algebraic

(ii)

closure system;

we

denned, because it is

certainly belongs

to T for T is

an

omit the details.

simple calculation to see that T is a closure system. Denning a function Xx it is then quite easy to verify that / preserves and f:X —> T by f(x) reflects order, and is bijective. Hence X and T are isomorphic. It is



We shall

1}

be



verify

that T is

an

algebraic

directed subset of T. Because

directed subset of X. Set e £

Xx



/ reflects order, D [_]£*? Note that, as D is directed,



iff



X° and

iff



Xx(j).

These last observations

{X^ \ i G {x(i) | i G /} is a

closure system; to do this let =

x(i)

e <

for

U{^x(t) \i

imply



some



1}

Xx





(e compact

J1",

as

in

X)

required. □

remaining results of this chapter are rather technical in nature, and by themselves serve little purpose. However, they will be crucial in Chapters 5 and 6 where they will be used to verify that certain domain-theoretic structures form models of polymorphic type theories. The reader can safely move on to the next chapter at this point, returning to this chapter as required. DISCUSSION 1.5.13

The

Let X and Y be

Lemma 1.5.14

that monotone functions I: X

Y and

r:



—*



are

lattices and suppose

such that for all





V,

and y

Then

—*

algebraic complete



l(x)

< y

x <

r(y)

is continuous iff I preserves the compactness of elements of X.

Proof

(=¥>) Suppose that r is continuous. Take e X° and suppose that 1(e) U{yi I i G /}. It is simple to see that e < rl(e) < U{f{yi) I * G /} and c < r(yi0) for some zo G /, that is /(e) < yi0. Thus 1(e) is compact. (<=) Certainly r(y)



y{x

G X

\ l(x)



y}.

In fact

slightly

more

namely r(y)



LK*

X°







r(y)}



\J{x



X°

\ l(x)



y}.

< so

is true,

30

Chapter

Take



{yi \

directed subset

i G

/}

of

Y\

Order, Lattices and Domains

1.

in order to

continuity of

the

verity



need to check that

we

\J{x

X°



| l(x)

\J{Vi |





For any

G X° and



|_|{*

X°

/}}





LKLK*

X°

| l(s)







G / with

Z(x)

Vi}

\J{x

X°

X°

| l(s)

| J(s)





/}



l(x)

< yf then

| l(x)





A z

y{} |











U{Vj I J

U(2/i I 3

-0- /}}



Hence

|>

and thus

U5 Thus to show that a



LKLK*



\JA



\JB,

A, there is b G B with

Then

\J{x

Lemma 1.5.15

Let

lattices.



G X°

enough

now





/}



\ l(x)

preserves

y f:X all joins just

A routine

manipulation



be

—?

in

Y, and

yi0} a

U^.

to show that for any element

6. Take £ G X° for which

is compact in

by hypothesis /(#)

Thus we have x <

a <

it is

yi} |



so

l(x)

G B. Thus



Z(x)



\J{yi I

< yio for some



io

G /.



is continuous.

monotone function between

case

/}.



preserves finite

complete

joins and directed

joins. PROOF

Exercise 1.5.16

Work

DISCUSSION 1.5.17

through

the details of the

We shall need the

proof of Lemma 1.5.15.

following definition. Suppose

join-semilattice. Then a subset / C X joins and is down closed. More precisely, is



of the definitions.



is

an

that X

ideal if J is closed under finite

J,



±x



x,y e I



x'

implies xVy

< x G /

We have the

implies x'



/, and

G /.

following proposition:

PROPOSITION 1.5.18

Suppose X

that X is

=f {/C X | J is

Then the set X of ideals of X is



join-semilattice

an

and let

us

write

ideal}.

algebraic complete lattice when regarded A is as a poset via inclusion. If A is an algebraic complete lattice and /: X a monotone function which preserves finite joins, then the function an

—*■

j:X->A





[}A{f{x)



x G

/}

Elementary

1.5.

Domain

preserves all joins in X.

31

Theory

Moreover, if Y is also

is monotone and preserves finite

joins

join-semilattice, and /: X

joins, then there is

 ̄f:X^Y which preserves all









—*■



function

|J{/(*H I



7}

compactness of elements of

in X and preserves the

X. We shall call / the ideal lifting. To show that X is

PROOF

The bottom element is



complete lattice,

{J-x}-

If

{h I





show that X has all meets.

we

S}

C X is



nonempty subset of

X, then

f]{Is | s G S} G X, as we now check. J_x G Is for each s G S, and if x,y G f|{7s I s G 5}, then x and y are in each ideal 7S, implying that x Ay is in each ideal; thus f|{7s | s G 5} is closed under finite joins. It is equally trivial to verify that f){Is \ s G S} is down closed. Finally, it is simple to check that this intersection has to be the We remark that if

{Is |





required

S}

C X is

\J{IS | implying that directed joins

meet.







S}

directed G

subset, then

X,

given by set-theoretic union. The only thing to comment on is the closure of the union under binary join. If x, y G \j{Is | s G 5}, then x G I¥ and y G 7S> for some s, s' G 5. By directedness, {Is, Isf} C 7S// for some s" G 5. It follows easily that xVyG \J{h I 5 G 5}. We

use

in X

are

In fact the compact the ideals of the form (V-F)l where F CJ X is a

this remark to check the

elements of X

are

precisely

algebraicity

of X.

finite subset of X\ if F cJ X then sense. us see

certainly \l F exists in X, so this makes If this is the case, then the algebraicity of X is virtually immediate; let

that this characterisation of the compact elements is correct:

(=>) Let F Cf X and suppose that

{/, | is s



directed subset.

with F Cf

Clearly

5 G

(V F)l

S}



\J{I¥ \





S}

where



F cJ

I¥. Thus it follows



(V F)[, and by that (V F)[ C Js,

directedness there is and

so

(V-F)l

some

is compact

inX.

(<=) Certainly

if E G X is



compact element, then

EC(J{(\jF)l\FcfE}, implying required.

there is

some

F C* E for which E C

(V F)[.

Hence E



(V-F)l,

as

32

Chapter

part of the proof, it will be helpful

For the next

join

of ideals / and J in X is K

To

x, x' G / and y,

some

y'

binary joins,

{z, z'}

G J. Then

that we



that





(x

and z' < x' V

< x V y



x') V(yV y')



an

y'

for

from which

we

binary joins.

ideal and is / V J

are

The

omitted.

joins, we appeal to Lemma 1.5.15. First we check joins. Take a directed subset D {Is \ s G S} C X;

preserves all

preserves directed

have to

take

/ and J both have

binary joins exist in K because remaining details which show that K is see

binary

given by

deduce

To

to show that the

IVJd^{J{(xS/y)l\xeI,yeJ}.



that K is closed under

see

Order, Lattices and Domains

1.



that

verify

LK/(*)l*elM y







LKLK/to I



i.} I



> e

s}



U{/(*)lseS,xG/s}.











To show that V < Then



e\JD



\JU, take /(x) for any s £ S and x G 7S (that is /(x) G V). {JD,so /(x) G t/ < |_l^- To show that U < \JV is equally

easy. Now

we

check that



preserves finite

joins. First note that

f({±x})=\J{f^x)}=f(±x) It remains

to see that



preserves

above construction of / V J,

LK/M Iz



we



±A.

binary joins. Given ideals / and J, and the

need

UK* vy)i\xeI,yeJ}} \J{f(x) I 6 /} V |_|{/(?) I =



This

is easy to

equality

verify

and

we



J}.

omit the details.

[:Y —? Y, where y *-* y|, is well defined, mono- def | o /. It only joins; from this we can define /

Note that the function

—'



tone and preserves finite



compactness of elements of X. Using the characterisation of compact elements of X given in the proof, we have remains to check that



7((\jF)l) and

so we are

done.

preserves



{J{f(e)l |





(\JF)l}



(f(\fF))i □

1.6.

33

Further Exercises

that X and Y

Suppose

Corollary 1.5.19

algebraic complete lattices, joins and also compactness of

are

preserving all elements of X. Then there is an isomorphism 6: X° Y), and moreover the following diagram commutes and that

/: X

Y is

—>



function



(similarly

X: 6 ̄l

for

i°^^y° 1







e-1 f



where

we

e <





compact elements of X is

note that the set X° of



join-semilattice.

verify that X° (similarly Y°) is a join-semilattice; hence / restricts to a function /: X° —> Y° and there is an ideal lifting /: X° F°. We define 6: X° X by the assignment J ?-? V / and 0"1: X X° by the assignment £ i—? {e X° | e < x} where x G X. It is routine to verify that □ these functions are well defined, and that the above diagram commutes. It is

Proof

simple

to

—?

-?

Fill in the details of the

Exercise 1.5.20

We end this

DISCUSSION 1.5.21

throughout

-?

chapter

Think of as many draw pictures of your domains.

definition which will be used

dcpo



with



bottom

examples

of Scott domains

as

you

can—

Consider the poset D {(A,B) \ A C N,B C N, A n B 0} ordered a pointwise subset of V(N) x V(N). Describe both the finite elements and =

maximal elements of D.

underlying element. —*■

set

{_L,1,2}

Prove that D



Prove that D is where 1 and 2 =



=>

P,

dcpo. Let P be the poset with incomparable and _L is a bottom



are

where N

=>

P is the set of all functions

P ordered pointwise.

(2) Let X be any poset. A subset S C X is in X and also S A

1.5.19.

Further Exercises

1.6





Corollary

cocomplete and algebraic.

Exercise 1.5.22

as

with

of

the remainder of this book. A Scott domain is

element which is also bounded

(1)

proof

dcpo



F is called

\J{s[ I a





S}.



poset-ideal

of X if S is directed

Write X for the set of

free dcpo generated by

X if there is



poset-ideals

of X.

monotone function

34

Chapter

given any other monotone function <j>:X —*■ C where C is dcpo, then there is a unique continuous function (/>: F —> C such that <f> 4>l:

t:X a

Order, Lattices and Domains

1.

—*■

F for which



(a) If A" is the set of

(b)

Given

join-semilattice, poset-ideals of X. a

show that the set of ideals of X coincides with

poset X, show that any two free dcpos generated by X



are

isomorphic. (c) Show that the set of poset-ideals of A" is a dcpo when ordered by inclusion, and that the function 7: X X given by 7(2) x[ is {y G X \ y < x} well defined, and is both order preserving and order reflecting. Show that X is the smallest dcpo which contains as a subset the set 7(A). Hint: show that if I is any poset-ideal of X, then I \J{y G X \ 3x G I.y < x}. —*■







(d)

Show that A" is

(3)

Let D and E be o;cpos with least elements and





free

dcpo generated by

E continuous functions. Let h:D

—?

by (d, e) function



(f{d, e),g(d, e)) where (d, e) (and hence has a least fixpoint:



X.



—?

fiDxE^D



and

g:D



E be the function defined

Dx E. Show that h is a continuous

i-*-

see

1.5.6).

Exercises

(f>e: D —> D, d 1—? f(d, e), one for each e G E. Show that they are continuous, and hence that each has a least fixpoint Y(<f>e) G D. Show that the function ip: E —*■ E, e i-*- p(y(0e),e) is continuous, and hence Now consider the functions

has



least

Finally

(4)

fixpoint Y(tjj).

Let A" be

where

(y(<^>y(^)),y(^))

prove that

->£

def =



Heyting

x =>

lattice and call

(5)

Let A be

(2)

will be

algebraic complete lattice, algebraic.

Let A be

element



complete

lattice and

and Y

/: A

—?

x G



regular

of /i. if

elements of A is

regular useful.

an

that Y is also

(6) (a)

an

_L. Show that the set of

lattice. Hint: Exercise 1.4.11

fixpoint

G D x E is the least



—?—?a:







Boolean

complete sublattice. Prove

A be



monotone function.

Define x

Prove that

f(x)

that

fixpoint



is



is

an

for



\J{xeX\x<f(x)}.

upper bound for the set

/,

that is

f(x)



x.

{x

G A







f(x)}.

Deduce

Further Exercises

1.6.

(b)

Let X be

a G

A and

35

poset. A lower segment of X is



X, then









implies

Now suppose that X is

similarly.

Y, and that Y is isomorphic

to

isomorphic

an

An upper





subset A C X for which if



to



segment is defined

lower segment of

segment of X. Let /: X

upper

arising from the first isomorphism, and g:Y

the obvious function



poset

—*■

Y be

—?

X the

arising from the second isomorphism. By considering the set

obvious function

of lower segments of X

(say L(X))

and the function 6:

L(X)

—*■

L(X)

defined

Y of the by 0(A) d= X\g{Y\ /(A)), show that there is a bijection h:X underlying sets of X and V for which given any x,y £ X where x < y, then either /i(x) < /i(y) or else h(x) and /i(y) are incomparable. Hint: use Part (a), and be careful to check all the details. -+

(7) Suppose that We

can

define

X and Y

any

sets, and that /: X

f ̄l: V(Y)

function



are

—?

Y is any set function.

PfX) by setting

—*■

f-\B)^{xeX\f{x)eB} for B C Y and

function



3/: V{X)

7>(y) by setting

-?

3/(^4) fef {/(a) | for A C X. Now suppose that X and Y inductive subsets of X

f:X /*(/)

—>



Y between

{x





(similarly for Y).

dcpos,

| f(x)

there is

1}





A}



are

dcpos

and let

X(X)

denote the

Note that for any continuous function

function

which

can

f*:X(Y)

be viewed

f ̄l:V{Y) 'P(-X') to inductive subsets. Finally fr.X(X) J(y) which is defined by —*■

—?

as

X(X)

defined

by

the restriction of

note that there is



function

->

fiW where The

and

formally 3/(7)

is



C){JeZ(Y)\3f(I)CJ}.

3/ applied

Beck-Chevalley condition dcpo Z, the diagram

(idz



and n'

are



set of I.

Y) -^L X{Y) f

/)<

X(Z



underlying

says that for any continuous function

X(Z

commutes, where

to the



X)

coordinate

—-

X(X)

projections,

(a) Verity that the definitions of /-1 and 3/ make

sense.

f:X

—>



36

(b)

Chapter

Check that

/*

is well defined and

can

be

1.

Order, Lattices and Domains

seen as a

restriction of





to

inductive subsets.

(c) Verify (d)

that



is well defined.

Show that in fact the

Beck-Chevalley condition does not hold. Hint: write down the Beck-Chevalley condition for the case f: {*} Y, where (say) V- Unravel the definitions of the functions in the commutative square, /(*) and conclude a certain property (say (t)j of the function 3-ir: V(Z x Y) V(Y) when restricted to inclusive subsets. Consider the dcpos A and B with underlying set Nu{oo}? A discrete and B the topped vertical natural numbers. By considering a certain dcpo constructed from A and B and assuming (f), —*■



—?

obtain

1.1



contradiction.

Pointers to the Literature

Birkhoff's

[Bir67]

contains much of the basic

of very basic lattice

theory of lattices. A short account

theory

can

be found in

introduction to ordered sets

can

be found in

Chapter 1 and much more besides. The "Compendium Lattices," [GHK+80], gives a state-of-the-art account of the

the contents of

Continuous

our

theory of continuous lattices found

theory

[Coh79]. An excellent textbook [DP90]. This book covers most of

particularly

as

it stood up to about 1980.

of

This work will be

useful to those interested in the kind of lattice and domain

which is used in type

theory semantics. Gratzer aimed to give a survey of lattice theory in the 1960's, and his book [Gra71] was intended as the first part of this program. However, due in part to a rapid development of lattice theory shortly after the early 1960's, such a survey became a virtually impossible task. Gratzer published [Gra78] in 1978 which is a monograph of the core concepts of lattice theory. Johnstone's book [Joh82] gives a fast paced account of basic lattice theory and covers much, much more. The concept of locale, a lattice which mimics the defining properties of a topological space, pervades the book, in which a variety of representation theorems are proved. Dana Scott and Christopher Strachey pioneered the use of lattices for the denotational semantics of programming languages. The papers [Sco69a],

[Sco69b], [Sco70a], [Sco70b], [Sco71], [Sco76], [Sco82]

and

[SS71]

make

interesting historical reading. A simple account of locale theory, along with much of the material covered in our Chapter 1, can be found in [Vic89]. This book is aimed at computer scientists.





2.1

Category Theory

Primer

Introduction

A category consists of a pair of collections, namely a collection of "structures" together with a collection of "relations between the Discussion 2.1.1

structures." Let

us

illustrate this with

some

examples of categories.

informal

(thus each set is an example of one of the structures referred to above), together with the collection of all set-theoretic functions (the functions are the relations between the structures). ?

The collection of all sets



The collection of all posets

monotone functions

(the

(each poset

is

monotone functions



structure), together

with all

the relations between the

are

structures). ?

The collection of all finite dimensional vector spaces,

together

with all linear

maps. ?

(in

The set of real numbers R





M), together

structures r,

r'

case

each structure is

with the relation of order <

R, there is



this



All categories have this basic

on

the set E.

relation between them

form,

just

are

usually

fourth

example they

be functions

are

objects

real

of



numbers)

category do

are some

given

case r <

two

r'.

and that the

as

the

objects morphisms. It is as

not have to be sets

(in

the

morphisms do not have to

(in the fourth example they are instances

Of course, there

real number

Thus

referred to

of the category and the relations between the structures to note that the

in



that is, consist of structures and relations

between the structures: the structures

important

just

of the order relation

precise rules which define exactly what



<).

category is,

and

we

of

category given in Discussion 2.2.1 while also reading the remainder of this



shall

come

to these

shortly:

introduction. For the time

being

the reader may

we

care

continue with



to look at the definition

broad discussion of the

aims of category

theory, that is, the general study of categories. Category theory looks at properties which are common to different categories. It is often the case that the specification of a property of a category can be set out in very general terms, but that the implementation of this property in particular categories varies greatly. Let us look at an example. We have said that the collection of all sets and functions forms

following property of this "category:" 07



category; consider the

38

Chapter

Given any two sets A and

(Property CP)

2.



Category Theory

B, then there is



Primer

set P and

A, 7r':P —*■ B such that the following condition holds: given any functions f:C —> A, g:C —*■ B with C any set, then there is a unique function h:C —*■ P making the diagram functions

n:



—*■

C I

h I T



7f'

7T

commute. End of definition of

(Property CP).

investigate an instance of (Property CP) in the case of two given sets A and B. Suppose that A {a, 6} and B {c, d, e}. Let us take P to be Ax B {(x, y) \ x £ A,y £ B} and the functions n and tt' to be coordinate projection to A and B respectively, and see if (P, tt, 7r') makes the instance of (Property CP) for the given A and B hold. Let C be any other set and f:C —*■ A and g:C —*■ B be any two functions. Define the function h:C —> P 7rh and by zh (f(z),g(z)). We leave the reader to verify that indeed f ir'h, and that h is the only function for which these equations hold with the g given / and g. Now define P' {1,2,3,4,5,6} along with functions p:P' —> A Let

us













and

q:P'

—>

B where

p(l), p(4), In fact

(P',p, q)





G C and

p(3) p(6)

see

this,

unique function h: C

/(x)













and

<?(4) c q(5)=d 9(6) e

<?(1), q(2), 9(3),

also makes the instance of

P hold true. To

is

p(2), p(5),





(Property CP)

for the

given

A and

by enumerating six cases that there P' for which f ph and g qh (for example, if

one can —?

check





p(x)



d then

we

must have

h(x)



2, and this is

one

case). Now notice that there is



bijection

between P

(the

cartesian

product

{(a, c), (a, d)(a, e), (6, c), (6, d), (b, e)} of A and

i?)

bijective.

It is very often useful to determine sets up to

and P;.

In fact any choices for the set P

worry about their elements

"internal make

can

be shown to be

bijection rather than might consider taking

up," so we (Property CP) as a definition of cartesian product of two sets and think of the P and P' in the example above as two implementations of the notion of cartesian or

2.1.

Introduction

39

product of the sets A and B. Of

talking

course

about the collection of sets and

(Property Cp) only functions;

we can

makes

give



sense

when

definition of

cartesian

product for an arbitrary category which becomes (Property CP) for the "category" of sets and functions.

Category theory looks at properties enjoyed by categories which may be described using an abstract definition of a category and not particular examples of categories. Such a property is called a categorical property. Very roughly, such properties depend on the external behaviour of objects in categories, and not the internal make up of the objects. For example, if we take an instance of (Property CP) for sets A and B as the new definition of the cartesian product of A and

B, then

category

(sets)

we

have shifted

our

viewpoint

away from the structures of

and towards the relations between the structures

The traditional definition of cartesian

product

our

(functions).

given in terms of the elements of the sets A and B, and the new definition is given solely in terms of functions involving A and B. It is the emphasis of relations between objects in categories, rather than the objects themselves, which allows us to make definitions which do not

(explicitly) depend

on

is

the internal make up of the

objects.

painted an informal picture of a category, and described the idea of a categorical property, we can move on to an account of the contents of Chapter 2. We begin with a formal definition of a category and give a number of examples of the concept. Next, the notion of functor is given, which is a mapping between categories. We give examples of functors and introduce a little more notation. This is followed by the definition of natural transformation; such a gadget can be thought of as a mapping between Now that

functors.

we

have

The concepts of category, functor and natural transformation

the three most basic notions of category

are

theory. Using these three ideas, we give an account of ways of regarding two categories as being "essentially the same," namely isomorphism and equivalence. These notions of similarity are based on the idea that two bijective sets are similar, as are two isomorphic groups. We follow this with the Yoneda lemma, which will turn out to be a very useful tool indeed when discussing the semantics of type theories. We give an account of cartesian closed categories, which are particular kinds of categories not wholly dissimilar from the category of sets and functions, and which will give us categorical models of functional type theory. Next we define the idea of an adjunction between functors and give a number of results about adjoint functors. There is a discussion of the idea of a limit and colimit in a category. These are categorical generalisations of the notion of meets and joins in a preordered set. Finally, we give some basic definitions of strict indexed categories. Let us now move on to a formal definition of a category.

40

Chapter

DISCUSSION 2.2.1

specified by ?

the

We

with

begin

following



capital

letter such

A collection

denoted

by



mor

as

Primer

Examples definition of





category. A category C is

data:

A collection ob C of entities called

by ?

and

Categories

2.2

Category Theory



2.

objects.

An

object

will often be denoted

A, B, C...

C of entities called

small letter such

/,

as

morphisms.



morphism will often be

g, h...

morphism / its source src(f) which is We shall write an object of C and its target tar(f) also an object of C. /: src(f) —? tar(f) to indicate this, or perhaps f:A^>B where A src(f) and B tar(f). Sometimes we shall just say "let /: A —*■ B be a morphism ?

Two operations assigning to each





of C" to

mean



is



morphism of C with

source

A and

target B.

Morphisms / and g are composable if tar(f) src(g). There is an operation assigning to each pair of composable morphisms / and g their composition which is a morphism denoted by gof or just gf and such that src(gf) src(f) and tar(gf) B and g:B C, then there tar(g). So for example, if /: A is a morphism gf: A—>C. There is also an operation assigning to each object A of C an identity morphism ida'- -A A. These operations are required to be ?





—?



—>

—>

unitary

idt<lr(f) / and associative, that is







idsre(f)









given morphisms f:A—>B,g:B—>C and h:C

—*■



then

(hg)f



h(gf).

It is time to

give some examples of categories. We adopt the convention of using calligraphic letters to denote categories, using an abbreviation of the names of the objects of the category, or occasionally the morphisms of a category. This convention should become clear with the following examples. Examples 2.2.2

(1)

The category of sets and total

functions, Set. The objects of the category are sets and the morphisms are triples (A, /, B) where A and B are sets and / C A x B is a subset of the cartesian product of A and B giving rise to a total A function. The source and target operations are defined by src(A, f,B) =

Categories

2.2.

and

tar(A, f,B) Then tar(A,f,B) and

41

Examples

B.



src(B,g,C),



that

Suppose

have another

we

and the

composition

(B,g1C)o(AJ,B) where



is

morphism (B,g,C). given by

(A,gf1C)

composition of the functions / and g. Finally, if A is any set, the identity morphism assigned to A is given by (A, id a, A) where id a Q A x A is the identity function. We leave the reader to check that composition is an associative operation and that composition by identities is unitary. Informally, the morphisms of Set are functions in the usual set theoretic sense together with a specified source and target. From now on we shall not give such a formal account of our examples of categories.

gf

is the usual

(2) The category of sets and partial functions, Vart. The objects are sets and the morphisms are partial functions equipped with a specified source and target. The definition of composition is the expected one, namely given f:A—> B,g:B —> C, then for each element a of A, gf(a) is defined with value g(f(a)) if both f(a) and g(f(a)) are defined, and is otherwise not defined.

(3)

The category of wcpos, ujCPO. o;cpos and the

are

X and Y

are

of ujCPO

morphisms

o;cpos)

which

are

The

set functions

monotone and preserve

are

is the o;-continuous functions.

with

/: X

—?



(where

joins of o;-chains, that

Readers familiar with standard denotational

dcpos, VCPO. Its definition is essentially objects the dcpos and morphisms the continuous

The category of

uCPO,

of wCPO

objects

programming languages will recognise the category uCPO.

semantics of

(4)

Recall Section 1.5.

(5) Any preordered Section 1.2 that

(X, <)

set

may be viewed

as a

the

same as

for

functions.

category. Recall from

reflexive, transitive relation on X. The objects are the elements of the set X and the morphisms instances of the order relation; formally the collection of morphisms is the set of pairs of the a

preorder

< on a set X is a

(X, <) forms a category with identity morphisms (x, x) for each object x (because < is reflexive) and composition (y, z) o (x, y) (x,z) (because < is transitive). Note for x and y elements of form

(x, y)

X and

where x,y

x <

y.



X,

there is at most

one

morphism

from



to y

according

to whether

x <



or

not.

(6)

A discrete category is

(7)



only morphisms are identities. So a very simple example of a discrete category is given by regarding any set as a category in which the objects are the elements of the set, there is an identity morphism for each element, and there are no other morphisms. b:S



semigroup (5, b) S

—*■

S, (5, s')

is !-*?

one

for which the

together with an associative binary operation ss'. An identity element for a semigroup S is some



set S

42

Chapter

(necessarily unique)

element



A monoid

(M,b,e)

is

se



s.

2.



Category Theory

of S such that for all

Primer

S we have es





semigroup (M, b) with identity element e. the natural numbers, (N,+,0), is a monoid. For

For



example, addition on another example, if X is a set and X* is the set of lists of elements of X which have finite length, then any such X* gives rise to a monoid (X*, concat, []) with list concatenation as the binary operation and with the empty list [] as identity element. This monoid is sometimes called the Kleene closure of the set X. We can now describe the category of monoids, Mon. The category Mon has objects consisting of all monoids, and morphisms which are functions preserving the monoid multiplication. Thus a monoid morphism / between monoids M and M' is a function /: M M' between the underlying sets, for —*■

which

(8)

f(mn)

Given





f(m)f(n)

category C,

we

where



and

n are

may define the

elements of M.

opposite category C09. The collection

objects of C09 is the same as the collection of objects of C. The collection of morphisms of C09 is the same as the collection of morphisms of C. If / is a morphism of C09 (and thus by definition a morphism of C), then the source src(f) of / in C09 is defined to be the target tar(f) of / in C. Also, the target of / in C09 is the source of / in C. (Thus /: A B is a morphism in C09 just in case /: B A is a morphism in C). The identity on an object A in C09 is defined to be id a in C. Finally we need to define composition in C09. If A and g:C B f.A^B and g.B^C are morphisms in C09, then f:B are morphisms in C. Hence / and g are composable in C, with composition fog:C—>A. We define the composition of / and g in C09 to be the morphism f°9-

of

—?

—?

—?

—>

preorder X which we regard as a category, then the opposite category X09 is precisely the opposite preorder of X. (9)

If

(10)

we

are

given



The category VreSet has

functions;

the category VOSet

objects preorders and morphisms the has objects posets and morphisms the

monotone monotone

functions.

(11)

The category of lattices Cat has

objects

lattices and

morphisms

the lattice

homomorphisms—see Section 1.3.

(12)

The category CCat has

complete

(13)

lattice

objects the complete lattices homomorphisms—see Section 1.3.

The category BCat has

and

morphisms

the

objects Boolean lattices and morphisms Boolean lattice homomorphisms. By definition, a morphism of Boolean lattices is a function f:X —>Y between Boolean lattices which preserves finite meets and joins (that is / is a lattice homomorphism) and preserves complementation.

2.2.

and

Categories

However,

43

Examples

it is easy to

see

homomorphism between Boolean complements. Thus a Boolean lattice

that any lattice

automatically preserves Y is just a lattice homomorphism. homomorphism X lattices

—?

(14) The category TiCat has objects the Heyting lattices and morphisms Heyt- ing lattice homomorphisms. A Heyting lattice homomorphism f:X —? Y between Heyting lattices is a function preserving finite meets and joins and preserving Heyting implications. So if x, x' G X, then

f(x

(15) We

=*

x')



f(x)

f(x').

=?

shall write ACCat for the category whose

objects are algebraic complete lattices and whose morphisms are complete lattice homomorphisms; note that in this example, the morphisms are not required to preserve a certain part of the structure of the objects of the category, that is, compact elements are not necessarily mapped to compact elements.

(16)

The category of Scott domains SDom has

morphisms

(17)

objects Scott domains and

continuous functions.

The category CJSCat has

objects the complete join-semilattices and morphisms functions preserving all joins. Note that a complete join-semilattice is indeed a complete lattice, but that a function which preserves all joins need not preserve all meets. Thus CJSCjoX has the same objects as CCat but different morphisms. (18) Let C be a category and B an object of C. The slice of C by B, denoted B in C, and by C/B, is the category whose objects are morphisms /: A whose morphisms g: f /' are those morphisms g:src(f) —? src(f') in C for which / f'g. It is often helpful to view such objects and morphisms as a commutative diagram: —?

—?



/r B

Similarly we can define the coslice, B/C. This has objects which are morphisms A in C and morphisms g: f —? /' are morphisms g: tar(f) —? tar(f') in /: B C for which /' gf. —?



(19) Suppose that C and has objects pairs (C, D)



categories. Then the product of C and V,CxV, where C is an object of C and D an object of V. The are

44

Chapter

2.

Category Theory



Primer

morphisms (C, D) (C, D') are pairs of morphisms (/, g) where f:C and g:D D' with composition given (as expected) coordinatewise. —*■

—*



—>

(20) Any

(M, 6, e) yields

monoid

morphisms

elements of the

are



category where there is

monoid, and

object M, the composition and identity arise one

operations. So if m and m' are elements of M and hence morphisms ra, ra': M —? M, then their composition is 6(ra, ra'): M —*■ M. iV.B. Every monoid can be viewed as a category; do not confuse this fact with the from the monoid

definition of the

category Mon.

Exercise 2.2.3

categories given

Understand how each of the informal

Examples

in

2.2.2

can

descriptions

of

be formalised to fit the definition of



category given in Discussion 2.2.1. Discussion 2.2.4

notion of

Before

moving

on

to Section

2.3,

we

shall define the

subcategory. Very informally, we can think of a subcategory V of a category C as having classes of objects and morphisms which are subclasses of those of C, such that V is itself a category. An analogy is the definition of a subgroup H of G where the set H is & subset of G and H is closed under the group operations of G. Now let us make a formal definition of subcategory. A ?

subcategory

V of

A subclass of the

the ?



and these

objects

are



taken —*■

For every

object



If

B and

f:A—>

of V and is the

as

the

D of

the

the

objects

and target of

and target of



V, and



subclass of

subcollection of the



in C

are

objects

morphisms

V, the identity idr> of C is





morphism

—*■

rise to

defined in



of V.

in C is



morphism

The category TSet of finite sets and functions between finite

Understand that the definition of

category.

Think about the ways in

turn,

subcategory does indeed which the subcategories

arise, especially comparing the sets of functions A B for fixed A and B in each of TSet, Set and Vart.

Example

V,

B in C.

subcategory of the category of all sets and functions, Set. In subcategory of the category of sets and partial functions, Vart.

Exercise 2.2.6

of

in T>. Thus the collection of





of

morphisms of V.

source

source a

are

g:B^^CmV, then the composition gf composition of / and g in the category V.

Example 2.2.5

give

are

B in V is



Set is

of C which

morphism / of V, the

morphisms

sets is

category C is defined by specifying:

of C which

morphisms

For any



2.2.5

—?

2.3.

Functors and

Functors and

2.3

thought of as a relation can also think of the function / as specifying an element of X; from this point of view, / is rather like a program

between two sets. We

of Y for each element

outputs



Examples

A function

DISCUSSION 2.3.1

which

45

Examples

value

/(i)

f:X



—>

6 7 for each

can

be

e X. We could say that a functor



pair of sets. Roughly, a functor from a category C to a category V is an assignment which sends each object of C to an object of V, and each morphism of C to a morphism of V. This

is to a

pair of categories

function is to

as a



assignment has to satisfy some rules. For example, the identity on an object A of C is sent to the identity in T> on the object FA, where the functor sends the object A in C to FA in V. Further, if two morphisms in C compose, then their images under the functor must compose in V. Very informally, we might think of the functor as "preserving the structure" of C. Let us move to the formal definition of



functor F

functor.



between

categories C and P,

written

as

F: C

—?

V, is specified

by ?

an

operation taking objects

A in C to

operation sending morphisms /: A in£>, ?

an

for which

F(id^)

objects

—?

FA in

B in C to

X>, and

morphisms Ff:

FA

FB

—?

idpA, and whenever the composition of morphisms gf is denned in C we have F(gf) Fg o Ff. Note that Fg o Ff is defined in V whenever gf is defined in C, that is, Ff and Fg are composable in V whenever / and g are composable in C. =



Remark 2.3.2

Sometimes

we

shall

give the specification of



functor F

by

writing the operation on an object A as A \-+ FA and the operation on a B h-> Ff.FA FB. Provided B, as f:A morphism /, where f:A that everything is clear, we shall sometimes even say "the functor /: C V is defined by an assignment —?

—*■

—?

—*■

f:A—>B where

/: A

source

of the functor

—*■

FB

Ff.FA—?

h+

B is any

morphism of C." F, and to V as the

We shall refer

informally

to C

as

the

target of F.

Examples 2.3.3

(1)

Let C be

where A is



an

category. The identity functor idc is defined by idc(A)

object

of C and

idc(f)





where



is



morphism

of C.





46

Chapter

(2)

We have

(page 42)

seen

we

may define

by taking the operation on objects to be FA morphisms Ff map(f), where map(f):A* —?



map(/)([ai,..., an])

[oi,..., On]



=f

that

see

F(gf)



=f

our

first

example



functor,

functor. To

see

we

that



define

FgoFf([ai,...,an]).

A, recall that the powerset V(A) is the set of subsets of A. We functor V: Set —*■ Set which is given by

f:A^B —?-

B is

where A' G

'P(-A).

(4)

define

can

B -^ C note that

set



/: A

—?

map(g)(map(f)([ai,...,an]))





We call P: Set a

/:A f-l(B') =f {a

—?

G A

/*

—*■

functor V: Set09

B is





£'}

is defined

by /*(A')



{f(a') \

a'



A7}

5e^ the covariant powerset functor. —*

Set

by setting

f-i:v(B)^V{A),

h+

function in

| /(a)

fcV(A)^V{B),



function and

/:jB^A

Set,

and the function

where B' G

P(5).

the contravariant powerset functor.

/-1

is defined

Note that the

functor V is the opposite of the category of sets and as



of

?,ap{g)([f(ai),...,f{an)])



where

on

[9f{a<i),---,9f{a<n)]



We

operation by

map(gf)([all...,an])



where

Mon

—?

an

B* is defined



idFA([ai,...1an])1

where A

Fgo Ff

F(gf)([all...,an])

can

rise to

idA*([ai,...,an])



Given

functor F: Set

A* and



gives

map(idA)([ai,... ,an])



(3)

set A

id a* note that



F{idA){[al,...,an\)

and to



Primer

[/(ai),..., /(an)],

Being

any element of A*.



give explicit details of the verification that F is indeed

F(idA)

Category Theory

that the Kleene closure A* of

monoid via list concatenation. Hence

with



2.

functions;

source

we

by

of the

refer to V

2.3.

(5)

Functors and

47

Examples

Given functors F: C

C and G: V

—*■

£>',

—?

the

product functor

F xG.CxV^C xV is defined in the

(6)

The functors between two

preorders

manner.

A and B

regarded

as

categories

are

where

are

the monotone functions from A to B.

precisely

(7)

expected coordinatewise

A functor between monoids is

regarding



monoid

as a

monoid



category with

one

homomorphism, object.

we

3/: V(A) V(B) by setting Sf(A') {/(a) | a G A'} where A' G V(A). This gives rise to the existential image functor by regarding the posets V(A) and V(B) as categories (via the inclusion order) and noting that 3/ is then a monotone function. We can also (8) Given



set function

/: A

—*■

B,

we can

define

—?



Vf:V(A) A' G 'P(A).

define

each

V(B) by setting Vf(A') d= {y

-?

We call the functor

V/

| f ̄l({y})

G £

the universal



A'}

for

image functor.

(9) Given a slice category C/B, we may define a functor 17: C/B —*■ C as follows. Suppose that /: A —*■ B is an object of the slice category, and that h: f —*■ f is a morphism of the slice. We set Uf A and Uh h: =

h +



A' h: A

A'.



(10)

Let X and V be

there is



functor

dcpos

and

X(f):X(Y)

—*■

/: X

Y be

—*?

X(X)

where



continuous function.

X(X)

Then

is the set of inductive

X, regarded as a category with the inclusion order (and similarly for X(Y)). Let us specify J(/); if B G J(y) we define subsets of

X(f)(B) d^f /^(B) d^f {xeX\ f(x)



B}.

X; for if D C f ̄1(B) and Z) is a directed subset of X then the monotonicity of / implies f(D) C V is directed. But clearly f(D) C B and hence we can deduce f(\/D) G B from the fact that / is continuous, implying \J D G f ̄1(B). So X(/) is well defined It is easy to check that

X(f)(B)

see

that

X(f)

it is immediate that

X(f)

can

and it is easy to

(11)

Let F:C

->

X>°p which sends in C°p to

is

is

be

an



inductive subset of

regarded

V be any functor. Then an

Ff: FA'

object

->

as a

—*■

X(X).

Hence

functor.

we can

A of C°p to FA in

FA in P°p.

X(Y)

monotone function

define

X>°p, and





functor F^-.C*9

morphism /: A;

->

-?-



48

Chapter

(12) D:C

Given

idry.D

(13)



—>

2.



Category Theory

Primer

categories C and P and an object D of P, the constant functor B of C to sends any object A of C to D and any morphism /: A —?

D.

—?

Let F:C

—*■

P be

(D j F)



functor and D

object

an

of P. Then the under-cone

objects (/, A) where A is an object of C and /: D is a morphism of P. A morphism p: (/, A) (/', B) is a morphism g: A for which the following diagram commutes: category

has

—*■

—*■

FA

—*■





FA

The

over-cone

that F:C

(14) Suppose

(F [ D)

category

category (F j G)

is denned

P and G:C

—>

FB

Fg

—?-

similarly.



are

functors. Then

we

define the

objects which are triples (A, /, A') where A and A; are objects of C and C; respectively and /: FA GAX is a morphism B in of P. A morphism (A, /, A') (£, /', B') is a pair (p, h) where p: A C and /i: A' B' in C for which the following diagram commutes: comma

to have

—?

—*■

—?-

—??

Fg

FA—^FB f\

GA'

(15)

Let

Qrp

Gh

be the category of groups and group

?Sei sends a group forgetful functor U: Qrp homomorphism to its underlying function.

to its

—?

homomorphisms. The underlying set and a group

Exercises 2.3.4

(1)

Check that the definitions

given in Examples indeed define functors between categories. (2) Let

sense

and do

category C is tiny if the collection of objects forms a set discrete; prove that a category C is tiny iff given any category V with

us

and C is a

2.3.3 make

set of

say that

objects

uniquely

to

then FA







ob V and any set function

functor F:C

/(A)

o6P.)

—?

P.

(Extends

f:

P, then / extends that if A is an object of C,

obC

means

—*■

ob

49

Natural Transformations and Examples

2.4-

DISCUSSION 2.3.5

We shall end this section with



few definitions. A

mor-

A with equal source and target is called an endomorphism. A phism /: A pair of morphisms / and g for which src(f) src(g) and tar(f) tar(g) are said to be parallel and this will be written f,g:A^>B. A functor with V common source and target categories is called an endofunctor. Now let F: C be any functor. We say that F is faithful if given a parallel pair of morphisms B in C for which Ff Fg, then / f,g: A g. We say that F is full if FB in D, then there is given objects A and B in C and a morphism g: FA some /: A B in C for which F/ p. —?





—?

—*■





—*■

—*■



<Se£ which takes monoids example, consider the functor U: Mon and monoid homomorphisms to their underlying sets and set functions Mon which respectively. Then U is faithful but not full. The functor U:Qrp takes groups and group homomorphisms to their underlying monoids is both As

an

—?

—*■

full and faithful.

Suppose that V is full subcategory if the



subcategory

of the category C.

inclusion functor i: V

—*■

C is full

We say that V is

(the



definition of the

inclusion functor is the

expected one). Note that this is just saying that the B in T> are exactly the morphisms A B in C. We say that morphisms A V is a lluf subcategory of C if the collection of objects of V coincides with that —*■

—?

forC.

Natural

2.4

Transformations

and

Examples

Not content with just the notion of a relation between categories, consider the notion of a relation between functors.

we

now

categories and F,G:C —? V be functors. Then a natural transformation a from F to G, written a: F —? G, is specified by an operation which assigns to each object A in C a morphism a^iF-A —? G.A in 2>, such that for any morphism /: A —*■ B in C, we have G/ o a^ a# o Ff, that is, Let C and V be



the

following diagram

commutes:

FA

<*A

GA

Ff

Gf

FB

GB <*B

The

morphism

at A.

a^ is called the

We shall also write a:F

component of the natural transformation —?

G:C

—?

P to indicate that



is





natural

50

Chapter

transformation between the functors

natural

transformation,

we

V.

—*■

Category Theory



If

we

given

are

Primer

such

shall refer to the above commutative square of

saying "consider naturality

F, G: C

2.

in A at



/: A

—*■



by

B."

Examples 2.4.1

(1)

Recall the functor F:Set

Kleene closure. We

components

rev a-

define

can

A*

—*■

Mon

—*■



(see





which takes

natural transformation

A* defined





—*■

set to its

F which has

[an,..., oi]

A*. It is trivial to

set and

rev:



by

revA{[ai,..., an]) where A is

46)

page

see

that this does define

natural transformation:

Ff

(2)

revA([ai,..., an])





[/(an),..., /(oi)]

fixed set X and define

F/([ai,..., an]). Set

by the operation FX(A) d= (X =>A)xX on objects and the operation Fx(f) d= (/ o -) x idx on morphisms (see page xvii) where A is any set and / is any function. Here, X => A is the set of functions from X to A, (X =>? ^4) x X is a cartesian product of sets, and (/ o —) x id*- denotes a cartesian product of functions. Then we Take



define

can

g(x)



where

set



natural transformation ev:Fx

(g,x)

transformation a

functor



revB



ev

(X

=>

A)



X.

To

with components ev^-

function, (g,x)



(X

=>

A)



{X

—*■

idset by setting ev^(^, x)

—?

that =>

A)

we



have defined



—*■

A let



/: A



natural —*■

B be

X and note that

(^5rt(/)ocv^)(flf,ar)



f(evA{g,x))



f(g(*))







(3)

see

Fx:Set

evB(fg,x) evB(Fx(f)(g,x)) (evBoFx{f)){g,x).

Let Vec be the category of vector spaces

over a

(fixed)

the set of linear maps from V into K. Then there is



field K. Write V* for

functor

(—)*: Vec09

—?

Vec, which is defined by

f:U—>V where

/:

there is

^y*

/*:C7*

morphism of Vec^ and 0 G 17* is any linear map. Thus functor (—)**: Vec —? Vec which is defined by





i—?

—?-

f:

V is any











/**:

V**

(x^(0^ x(f*(0)))) —





U**

51

Natural Transformations and Examples

2.4-

where x £ ^** is anY linear map. For each vector space V there is map ay: V

V**

—?

given by av(v)(6)

#(?;)



where

V and 0



linear



V*.

It is

diagram

easy to check that the

ay





V**



/ U



**

av

commutes, where

V:



(6

v I

/(f)

(*.-> *(/(?)))

and hence that the ay define

Discussion 2.4.2



->

0(V))

(*-/?(*)(?))



natural transformation

It will be convenient to introduce

a:

id^ec

some

—?

(—)**.

notation for

"composing" functors and natural transformations. Let C and V be categories and let F, G, H be functors from C to V. Also let a:F G and /?:G if be natural transformations. We can define a natural transformation fia:F H by setting the components to be (Pa)a Pa&a- For clarity we will sometimes write (3oa instead of Pa. This yields a category [C, V] with objects functors from C to V, morphisms natural transformations between such functors, and composition as given above. [C,2>] is called the functor category of C and V. dealing

with methods of

—>

—*■

—*■



We end this discussion with

G:V

—*■

S is



functors. Then

setting components

define

to be

transformation Ja: JF where D is

an

object



(aj)c

—*■



Ev(A, F)

and /i: F functor.

—?

Fx.



notation. —>

Suppose

—*■

that

V and J\E —?

an

a:

—*

G7: C

object of C, and J7 by setting components (Ja)r)

o;/c where C is



—?

a =





—>

are

by

natural J (old)

of V. we

may define

Ev.Cx

where

more

natural transformation a/: FI

JG: P

Note that

Example 2.4.3

little

transformation, and that I:C

natural we can



FA and

Such



[C,Set]

Ev(g, /i)



functor Ev is



functor

—>Set

Fg F'g o \iA with g:A—>A' usually referred to as an evaluation

/iA'

°



52

Chapter

2.

Category Theory



Primer

Exercises 2.4.4

(1)

Given

categories

C and

V, verify that the functor category [C, V]

in Discussion 2.4.2 is indeed

(2) Verify



defined

as

category.

given in Discussion 2.4.2 do indeed yield natural transformations. Further, given a diagram of categories and functors that the definitions







and natural transformations J(3



(/?

J a and

categories the

a)j

F,G,H



?V

a:





—>

G and

ft o aj. i\fo£e: compositions are defined. o









/?: G

—*■



+F

if, show that J((5



a)



ma&e swre yow understand in which

Isomorphisms and Equivalences

2.5

Of course, the basic idea of

DISCUSSION 2.5.1

isomorphism is that isomorphic objects are "essentially the same." In the case of Set, two sets X and Y are isomorphic just in case there is a bijection between them. This means that either there is a function f:X —*■ Y which is injective and surjective, or, equivalently, there are functions f:X —*Y and g: Y —? X which are mutually inverse. We can use the idea that a pair of mutually inverse functions in the category Set gives rise to bijective sets to define the notion of isomorphism in

arbitrary category.

an



is

morphism /: A

some

g: B

—?

—*■

B in

A for which



category C is said

fg



i&& and gf

to be



an

isomorphism if there

ida- We shall say that g is

and that

/ is an inverse for g. Given objects A and B in C, we say that A is isomorphic to B and write A B if such a mutually inverse pair of morphisms exists, and we say that the pair of morphisms witnesses the fact that A B. Note that there may be many such pairs. In the category determined by a partially ordered set, the only isomorphisms are the identities, and in a preorder X with x, y G X we have x y iff x < y and y < x. Note that in this case there can be only one pair of mutually inverse morphisms witnessing the fact that x y. an

inverse for











An

isomorphism. we

isomorphism If there is



in



functor category is referred to

natural

shall say that F and G

isomorphism between the are naturally isomorphic.

as a

natural

functors F and

G,

then

Isomorphisms

2.5.

and

53

Equivalences

Exercises 2.5.2

(1)

Let C be



category and let /: A

id a show fh z^b and #/ unique inverse if such exists. =

(2) g



Let C be

are



that g

category and /: A

isomorphisms,

Lemma 2.5.3

Let

show that

a:



—*■

—>

—*■

gf

G: C



B and g, h: B

—*■

h. Deduce that any

B and g: B

—>

C be

morphisms. If morphism / has a

A be

If

morphisms.



and

is too. What is its inverse?

—>

V be



natural transformation. Then



is

natural

isomorphism just in case each component etc is an isomorphism in V. More precisely, if we are given a natural isomorphism a in [C, V] with inverse (3, then each (3c is an inverse for ac in £>; and if given a natural transformation a



the

of

[C, V]

in

/?c

the components of

are

in



for which each component ac has a

an

inverse

natural transformation

(say (3c)

in

X>, then

(3 which is the inverse

[C,V].

Proof



Direct calculations from the definitions.

Exercise 2.5.4

Do the

what the lemma is

saying.

Discussion 2.5.5

We

proof

of Lemma 2.5.3. Be careful to note

emphasised

at the start of this

interested in the way structures behaved and not

so

chapter

precisely

that

we were

much in their internal

make-up. To this end we might expect that the judgement "A and B are isomorphic in C" is more important than the judgement "A and B are equal in C" Indeed, the development of category theory has shown this to be the case. This leads us to the notion of equivalence of categories. If two categories are equivalent, then the rough idea is that we can write down a one to one correspondence between isomorphism classes of objects obtained from the categories. Let us give the precise definition. Two

categories C and V are equivalent if there are functors F.C —> V and G:V C together with natural isomorphisms e : FG GF. id?, and r): idc We say that F is an equivalence with an inverse equivalence G and denote the V: G. equivalence by F: C —>







Example 2.5.6

Let

us

look at

Vart, the category of sets and set.

Recall also the definition of

Vart is



example of equivalent categories. Recall partial functions, and write 1 for a singleton



set

an



coslice category. Then it is the

1/Set. Note that an object of 1/Set is a function /: 1 (and hence in particular A is non-empty); this amounts

—?

case

that

A where A

to



giving



54

Chapter

2.

pair (A, a) where a G A, and a is sometimes referred element of A. A morphism g: (A, a) —> (B, b) amounts for which 6



g(a),

that is g preserves the

(choose

/:A *



—?

be

can

such that

7(0













as

to



function

f?

f?





G A and

the

element of A.

equivalence. Any partial

regarded as a total and * ^ B) where if

Primer

distinguished function g:A—>B

to

distinguished

We pause to consider the intuition behind the function

Category Theory



f:Au{*}—>

BU

{*}

is defined

otherwise

(GiU {*}; and of course A U {*} (B U {*}) can be viewed as a set with a distinguished element. Conversely, any total function whose source is a set with a distinguished element can be seen to give rise to a partial function. for any

Now

formally at the equivalence of (X,xo) and (Y,yo) be objects of 1/Set, and /: (X,x0) Define a functor F: 1/Set Vart by setting F(X,xq) we

look

—>

Ff(x\ where of

Let g: X

setting

Y be

—?

GX d= (X U £ Pl^ (c\

where of

I{

\ {#o}



course x G



f(x) Provided f(x) #

and

(Y,yo) a morphism. X \ {xq} and

y0

Ff: X \ {xo} -?y\ {yo}- a

functor G: Vart

and

^K)

l/?Set by

G ^ is defined

Gg: X U {X} -^7U {Y} and f G X U {X}. does give rise to an equivalence of categories.

Then

course

check that this

—>

and

/ ^K) if f ^ ^ \ Y otherwise

dJ;f

Let

undefined otherwise

partial function. Define

{X}, X)

—?



<kf

1/Set.

Vart and

more

one can

Exercises 2.5.7

(1) Investigate Draw

some

equivalence of preorders regarded pictures of equivalent preorders.

(2) Complete

(3)

the notion of



detailed verification of the

The slice category

Set/B

equivalence given

is often referred to

as

function

family

/: X

of sets

—>

(Xb \

categories.

Example

2.5.6.

the category of B-indexed

preserving the indexing. To see this, note that B gives rise to the family of sets (/-1(&) | 6 £), and the

families of sets with functions a

in

as

b G

B) gives

rise to the function

f:{(x,b) \xeXb,beB}^B

Products and

2.6.

where

/(#, 6)



55

Coproducts

b. Note that

we can

regard the set B

as a

discrete category;

equivalence between the functor category [B, Set] and the slice Set/B. Formulate this equivalence carefully and prove that your definitions really do give an equivalence. then there is

an

Products and

2.6

Discussion 2.6.1

Coproducts

The notion of

seen, there is



"product

of two

objects in a category" can be viewed as an abstraction of the idea of a cartesian product of two sets. As we mentioned in Section 2.1, the definition of a cartesian product of sets is an "internal" one; we specify the elements of the product in terms of the elements of the sets from which the product is composed. However, as we have a

property of the cartesian product which characterises it up to

bisection. The internal make up of two bijective sets may be very different, but their properties may well be very similar. We can now give the formal definition of a binary product of two objects of a category. set-theoretic

A binary product of objects A and B in

object



an



two

Ax B of



category C is specified by

C, together with

projection morphisms

7r^: A x B

—>

A and

ttb'-AxB—^B,

for which given any object C and morphisms f:C —*■ A, g:C —*■ B, there is a unique morphism (f,g):C —? Ax B for which 7rA(f,g) f and 7Ts(/,p) g. =



simply to a binary product A x B instead of the triple (A x B, 7ra, ttb), without explicit mention of the projection morphisms, much as it is common practice to speak of a group G rather than (G, o, e). The data for a binary product is more readily understood as a commutative diagram, where we have written 3! to mean "there exists a unique": We shall refer



J/3\(f,g)\9 \

/ A*



Ax B



B, the binary product Ax B and morphisms /: C —> A and g: C Ax B (making the above diagram commute) is unique morphism (f,g):C called the mediating morphism for / and g. We shall say that the category C has binary products if there is a product in C of any two objects A and B, and that C has specified binary products if there is a given canonical choice of Given



—?

—?

56

Chapter

2.



Category Theory

Primer

binary product for each pair of objects. For example, Set has specified binary products by setting Ax B {(a, 6) | a G A, b G B} with projections given by the usual set-theoretic projection functions. Talking of specified binary products is a reasonable thing to do, by virtue of the next result. =

LEMMA 2.6.2



binary product

of A and B in



category C is unique

up to

isomorphism if it exists. Suppose that (P,Pa,Pb) and {P^Pa^Pb) are two candidates for the binary product. Then we have (jpa,Pb)'-P —> P' by applying the A, Pb'P B, and defining property of {P',p'aiPb) to the morphisms Pa'.P (jp'aiPb)'- P' —> P exists from a similar argument. So we have diagrams of the Proof

—>

—*■

form P

P'



* —





Pa

Pb

def

/ Pa {p'a,Pb)(Pa,Pb): P —> P and one can check that paJ and that psf Pb, that is / is a mediating morphism for the binary product (P,Pa,Pb)\ we can picture this as the following commutative diagram: But then







But it is trivial that idp is also such



mediating morphism,

idp. Similarly one proves that {paiPb){p'aiP'b) P' witnessed by the morphisms {pa,Pb} and {PaiPb)-

implies / P





The notion of

DISCUSSION 2.6.3 indexed families of

binary product

has



an



object Yi^iAi



uniqueness idp'i to deduce so



extension to set-

objects.

family of objects (Ai \ i G /) in a category product of the family of objects is specified by Given

an

and

in

C, and

C where / is



set,



2.6.



Products and

for every j G J,

57

Coproducts

morphism 7rj:IlieiAi



—>

Aj

in C called the

jth product

projection, Ai \ i G /), there object C and family of morphisms (ff.C is a unique morphism (/i | i G 7):C —*■ UieiAi for which given any j G J, we have iTj(fi | i G /) fj. We shall say that (fo \ i G /) is the mediating morphism for the family (fo | i G J). such that for any

—*■



In the definition of

product, for any family (Ai \ i G /) we speak of a product and not the product. This is because a product is unique only up to isomorphism, and the proof that this is the case mimics that for binary products (Lemma 2.6.2). We shall sometimes speak of a product U^iAi without explicit mention of the product projections. Remark 2.6.4

Examples 2.6.5

(1)

A terminal

object

1 of

category C has the property that for any object



C of the ambient category, there is

unique morphism \c'.C —? 1. Note that such an object is unique up to isomorphism. For suppose that both 1 and 1' are terminal objects of C. Then there is a unique morphism \i>: 1' —? 1, and a unique morphism !x: 1 —? V. Thus by composition there is a morphism a

1. But 1 is a terminal object, and so we must have \\>o\x !i/o!x: 1 idi, because there has to be a unique morphism !i: 1 1 and this must therefore be the identity. Similarly !io!x/ V as required. Note that this id\> and thus 1 —>



—?



kind of argument



using uniqueness properties

is

prevalent

in

category theory.

empty family of objects (that is a family indexed by the empty set) in a category C is given by a terminal object. The first clause of the definition of product says we are given an object of C, say 1, and the

(2)



product

of

an

remainder of the definition reduces

unique morphism C

—?

1. A

saying that for each object C there is a singleton set is an example of a terminal object to

in the category Set.

global element of an object A in a category C is What are global elements in the category Set?

(3)



(4)

Now let /



(5)

When / is



we

shall sometimes write Ai

{1,2}.



of

product

any

family (Ai, A2)

morphism



—?■

A.

of two

objects is just a binary product of A\ and A2 as defined on page 55. We usually denote the product Tiie{it2}Ai by A\ x A2 and write (/i,/2) for any mediating morphism (/*!? {1,2}). finite set

we

shall x

...



speak x

An

product. If / {1,..., n} II"Ai for the product of (Ai \ i G /).

of

or



finite



58

Chapter

We shall sometimes abuse notation and allow

TL^Ai

Thus

will indicate

of

product



2.

Category Theory Primer



to be 0 in the notation



objects, that is,

no

terminal



II"A{.

object.

products of set-indexed families of objects if there is always a product for any such family. C has specified products of set-indexed families of objects if it has products and there is always a specified canonical choice. We shall say that C has finite products if it has products of finite families of objects. We shall see that such categories with finite products arise naturally in the semantics of algebraic type theory. It will be useful to have a little additional notation for dealing with such categories. A category C has

DISCUSSION 2.6.6

Let C be

/': A'

->



category with finite products and take morphisms f:A-+B and

B'. We write

where tt:A

A'



where



idA>

g:B^C



and

means



-+

A'



that in

B' for the



(g

one



morphism {fir, fir'}

The uniqueness condition of

A'.

—?■

general

and

idAxA>

g'\B'

A'

f':Ax



A and it': A

—?■

mediating morphisms idA



has

g'){f



/')

gf





g'f,

C".

-??

Exercises 2.6.7

(1)

Show that

products and





category C has finite products just in

terminal

(2) Let C be



it has

binary

object.

category with finite products and let

I.X-+A

f:A^B h.C^E

h:B->D

g:A^C

be morphisms of C. Show that

(hxk)o(/,g)

(3) Investigate

binary product

the notion of

DISCUSSION 2.6.8 a

case

binary coproduct



A coproduct is of





pair of objects



(hf, kg) in





(/,g)ol



(fl, gl).

category C09.

dual notion of in

and

product.

For

example,

category C is given by the binary

product of the objects in the opposite category C09.

With this

definition, readers should provide a definition of binary coproduct for themselves, and check their conclusion with the following definition. A

binary coproduct

object

of

objects

A and B in



category C is specified by

A + B of C, together with



an



two insertion

morphisms

iA. A

—?■

A + B and t#: B

—?■

A+

B,

2.6.

Products and

59

Coproducts

pair of morphisms f:A^>C,g:B^C there exists

such that for each



C for which [/, g]tA morphism [/, g}: A + B f and [/, g]ts g- picture this definition through the following commutative diagram: —?



We



^A + B-^

extend this definition to the notion of

of



An



for every

in

object T,{ iAi j

/,





We

can



coproduct



objects. Given a family of objects (A{ \ i set, a coproduct is specified by the following

family / is

can





unique



/)

in



of



set-indexed

category C, where

data:

C, and

morphism if Aj

—?

T,i iA{ called the jth coproduct

insertion, object C and any family of morphisms (ft:Ai—*C\i C for which given any j unique morphism [/f | i G /]: H^jAi

such that for any there is we



have

—>

[ft |

i G

I]ij



coproducts there is always a unique satisfying ..." We of unique gadgets which satisfy

phrase "there exists will see that definitions involving the existence certain properties pervades category theory. Such properties universal properties.

unique



Prove that the

Exercise 2.6.10 is

/,

fj.

clause which contains

objects



In the definitions of products and

Remark 2.6.9 a

l)

up to

...

coproduct

are

of any set-indexed

known

as

family

of

isomorphism if it exists.

Examples 2.6.11

(1)

An

U: 0

object

0 of

category C is called initial if there is

unique morphism object is unique up to a

object A of C. Note that such an isomorphism. Then a coproduct of an empty family of objects of C (that is a family indexed by the empty set) is an initial object for C, and the reader should verify this.

(2)

—?

A for each



Set, the binary coproduct of sets A and B is given by their together with the obvious insertion functions. We can define

In the category

disjoint

union

60

Chapter 2.

disjoint

the

union A tfc) B of A and B

as

the union

A Category Theory Primer

(A

{A}) \J(B





{B})

with

the insertion functions la: A^ A\SB

where la is denned

byai-> (a, A) for all



B :lb





A, and £# is defined analogously.

(3) Suppose that X is a lattice viewed as a category. Then the top of X is a terminal object, the bottom of X an initial object, and finite meets and joins are finite products and coproducts respectively. (4)

The category VOSet has

binary products through

the

pointwise order

on

product of (the underlying sets of) posets X and Y, together with the monotone set-theoretic projection functions. Also, any one point poset is a terminal object.

the cartesian

In

DISCUSSION 2.6.12



category with finite products

show that for

we can

isomorphism Ax(BxC) (AxB)xC. Moreover, we can show that both the left hand side and the right hand side of this isomorphism are products of the triple (A, B,C). One might loosely say that Ax (BxC), (AxB) xC and AxBxC each satisfy the same specification, but are implemented differently. In concrete examples, the internal make up of these objects will be different, but they will each have similar external properties. any

objects A,

If C and V

B and C that there is

an



categories with finite products, then the functor F:C —> V preserves finite products if for any finite family of objects (A\,..., An) in C the morphism m

are

=f (F-ki |

i e

I): F(Ai



...



An)

->

isomorphism, where of course Fitf F(Ai x to the projection -Kj for each j e I. Note that than m to the above isomorphism; we refer to m is

an

In the

case

that







we

FAX

...





An)

...

—*



FAn

FAj

is F

applied

there may be witnesses other as

the canonical

say that F preserves terminal

isomorphism. objects, that is the

unique morphism F(lc) —? 1-d is an isomorphism where \q and lx? are the terminal objects of C and T> respectively. A finite product preserving functor F is strict if the above isomorphisms are identities. Exercise 2.6.13

Find

an

example

F{A



of



functor F:C

—?

V for which

B)^FAxFB

pairs of objects A and B in C, but such that F does not preserve binary products. Hint: think about countably infinite sets. in V for all

Note: All the

category theory required

to read

Chapter

3 has

now

been covered.

2.7.

The Yoneda Lemma

61

The Yoneda Lemma

2.7

DISCUSSION 2.7.1 of all sets cannot be

We learn in a

first



set but is in fact

have to deal with collections which of size

important, but

are

we

in set

course a

theory

proper class. In

that the collection

category theory

we

Questions do not delve into formal details here. We shall,

large

are

in



very real

sense.

however, make the following definition. A category C is small if its

morphisms can be indexed by a set; note that this implies the collection of objects of C is a set. C is locally small if for any pair of objects A and B the collection of morphisms from A to B can be indexed by a set. This set is usually written Homc(A, B) or C(A, B). For example, if X is a preorder viewed as a category, then

X{x,y)

{*}





<*>if*<2>



0 otherwise

categories that one meets in everyday use are indeed locally small. However, functor categories are not always so. If C is small and V is locally small, then [C, V] is locally small. This where x, y G X and

is

point

a one

set.

Most

is because the components of the natural transformations in

by

the

to

give

objects

Oic- FC a



of C and this collection is

natural transformation

—>

GC in V for each

natural transformation obC

and there is

[C, V]

need



object



locally



are

indexed

by hypothesis. More precisely, G, we have to give a morphism

set

—>■

C of C. Thus there is



candidate for such

for every function

—?

\J{V{FC,GC) |

certainly a set of such not be locally small.

Now it is time to introduce of

a:



[C, T>]

obC}

functions. If C and V

some more

small category C. We

C e

can

are

locally

small then

notation. Let A and B be

define

objects

functor



C(-,+):CopxC^5ei by taking any morphism (/, g): (A, B)

—?

(A', B')

in C*9



C to the set-theoretic

function

C(f,g):C(A,B)^C(A',B') where

C(f,g)(h)

morphism A'

—>



ghf

A in

C).

for each We

can

h:A

morphism

also define

C(A,+):C



—>

functor

-+Set.

B.

(Note

that



is



62

Chapter

expected,

As

g: B

B' is

—?■

the function

where h:A

this functor takes a

C(j4,0):C(A,£)

—?

£.

Similarly,

-??

C(j4,£')

defined

define

we can

Category Theory Primer



C(A, B), and if C(A, +) takes g:B-+B' to

B of C to the set

objects

of C then the functor

morphism

2.

functor



C(A,+)

by setting C(A,g){h) =f gh,

C(—,B):C°,p

—?

<Se£. We

Hb for the functor C(—,£), when the category to which we are referring is clear. If h: C —? C" is a morphism of C then tf^/i: tf^C -? £AC" will be written as HA: Ha -+ HA,, with a similar shall also write HA for the functor

notation

adopted

for Hb- Finally,

There is also

by

the



functor H:C

/: A

—?

A' is

Hf:HA

—*■

HA>. The functor H

[C,Set].

of C^ into the functor category

[C^, <Se£]

defined in

similar



fashion, that is

locally

small



—?

A'

Hf:HA —>HA,

h+

we are

given functors F: C

categories C and V. Then there p°p





pop





idxF -

G^xid -

are

V and G:V

—?

£>(-,+) v \

Set

rxC

C(-,+) ^ ;.

<Se*





as

-+

V(—,F+), C(G—,+)

See page 47 for the definition of G09: the omission of the

notation

C(G—,+)

essentially are

to

C between

functors

V^xV

compositions will usually be written

and the

respectively.



morphism of C.



Now suppose that

there

A to

—*■

—>

[C, Set]

assignment /

where

-?

f:A' embedding

for the functor which sends

is often called the Yoneda

shall write

we

H: C^

and

"op"

in the

arises from the fact that the action of the functor G*9 is

"apply G." If A is

obvious functors

an

object

V(A, F+): C

->

of V and B

Set and

an

object

C(G-, B): V°p

of

->

C, then

<Se*.

The reader should take time to familiarise himself with the notation which

just been introduced. All of the concepts involved are easy, and simply require a little familiarity to use them smoothly. Of course, the obvious question to ask is why such diverse notation has been introduced. The answer is simply that in various situations one of the above terminologies may be easier and clearer to manipulate. We urge the reader to read and understand the notation thoroughly, for the remainder of this section makes heavy use of it. has

Let Given

us a

finish this discussion with the definition of

functor F:C

representable if there is

an

—?

Set where C is

object

locally small,

A of C for which

we can



representable

we

find



functor.

say that F is

natural

isomorphism

The Yoneda Lemma

2.7.

HA

63

pair (a, A) where a G FA is a representation of F if the natural transformation \I>: ifA —? F which has components \I/b: C(A, £) —? FB F. We say that



given by ##(/) morphism of C.





Ff(a)

To

Example 2.7.2

is

give



natural

with the set of functions from X to

meaning

as

an

element





that

can see

true and 0

point

We

can

membership. V:Setop iff:

H^0,1}

set

can

Set is

natural

is

We

are now

in



bijection

we

think of



G X'. Thus

we

information about subset

functor to formalise

representable



The natural transformation

V{X)

function. It is easy to check that #

position

reading, this material is an indispensable tool

On first

discussing

use.

to state and prove the Yoneda

heavy. However,

may feel rather

the

which every category theorist should

We shall make

use

of the Yoneda lemma

the semantics of

Yoneda lemma says that for we

in

that the contravariant powerset functor

{0,1}

—?

carry in his kit and be able to

Set, if

concrete

isomorphism.

Yoneda lemma

when



subset X' of X and

*"P(X)({1})-X ̄1({1})

Set(X, {0,1})



DISCUSSION 2.7.3 lemma.





not that

or

(or code)

represented by ({1},{0,1}).

where X is any set and \: X a

represent

case

look at

B is any

V has components

—>

**

is

two

the idea of

use

—?■

given set X, V(X), is point set {0,1}. For if

ask whether it is true

In fact it is the

—?■



we

/:A



meaning false, then given

as

we can

two



these ideas.

X,

where

feel for the definition

some

Recall that the set of subsets of

example. 1

isomorphism,

choose any

object





datatypes in later chapters. Roughly, the locally small category C and a functor F: C of C, there is a bijection between the elements —*

of FA and natural transformations from HA to F.

Lemma 2.7.4 A

an

HA

Let C be



locally

object of C. Then the collection Nat(HA, F)

—>

F is



set and so

we can

define

Nat(H ̄,+) as

small category, F.C

follows. The









morphism (p, y): (A,F)

—?■

Set



functor and

of natural transformations

functor

[C,Set] —?

—?

(A', F')

Set in C



the function

Nat(H9,fi):Nat(HA,F)

->

Nat(HA>,F')

[C,Set]

is taken to

64

Chapter

which is denned

by Nat(H9,/J>)(a)

transformation. Recall also



(page 51)

Ev.Cx Then there is

object of C, bijection)



natural

fioaoH9

where

Primer

Category Theory



2.

a:

HA

—?

F is

natural



the evaluation functor

[C,Set]

—>Set.

Evi^f. If A is an isomorphism ¥:Nat(H ̄,+) to saying that there is an isomorphism (set-theoretic =

this amounts

*iAtF):Nat{HA,F)!*FA:*{Af) and this

isomorphism

Proof there is

In the first part of the a

bijective assignment

Nat(HA, F) an

is natural in

is indeed



(A, F). proof,

between

set and thus

we

show that for each A and F

Nat(HA, F)

Nat(H ̄, +)

and

FA, establishing that

is well defined. We

can

define

assignment

¥{A,F):Nat(HA,F)^FA by setting ¥(a,f){&) define an assignment



o^a^a)

for

a:

HA ->Fa natural transformation, and

*iAiF):FA-+Nat(HA,F) by setting ^(a,f)(o)b(/)

^(a,f)(o)b and

/: A

Ff(a)

where



FA,



B is

an

B is

one



morphism

in

C, where of course

has to check that

ty(A,F)(a)

is



of C,

object

ty(A,F){a) ^(a,f){^)b'' C(A, B)

is the component of the natural transformation

—?■

Note that



B,

at

—?

natural transformation.

FB.

We

urge the reader to do this. Now

check that

assignments ¥(a,f) are isomorphisms (bijections) with inverses given by the V(a,f)- One way round, we check that ^(a,f)^(a,f) V(A,F)(<XA{idA))- idNat(HA,F)' To see this, first note that V{a,f)¥(a,f)(<x) we





Then

we

have

*(A,F){<XA(idA))B{f) because



is natural





Ff{aA(idA))

a^if^zc^))



OiB(f o ida)



<*B{f).

*&(A,F)(&A(idA)) are the same the natural transformations ty(A,F)¥(A,F){&)

Thus the components of

as

to say that

and

required.

those of a are



which is

identical,

as

2.7.

For the other way we

65

The Yoneda Lemma

we

check that

¥(a,f)^(a,f)



idpA- Let





FA; then

have

¥(A,F)*(A,F){a)

¥(W*W)(fl))



^(A,F){a)A(idA) (F(idA))(a) a.



Hence

we

have established

Nat(HA, F), implying



bijection

between the set FA and the collection

that the latter is indeed

¥(a,f)

In fact the functions

and #. We shall check that ¥

V(a,f) give Nat(H ̄, +)

and :



set.

rise to natural

Fv is

—?



isomorphisms



natural

transformation, that is the diagram FA

Nat{HA,F)-

Nat(H9,fi)\

F'p

Nat{HA',F') commutes, where a

be



(g,fi):(A,F)

—?



morphism

natural transformation from HA to F. Then

(¥(^)otfa*(ff*,M))(aO





by definition of ¥ (A',F')







But

is

now

we

are

fj,A

F'A'

¥ (A',F>)

(A7, F')



we

in C

[C,?Se£].



have

¥(A'f)(Nat(Ha,ri(a)) ¥(A>,F>)(voa°H9) {l^oao Hg)A'(idA')

(fiA'o aA>



H%)(idAi)

(fjLA'o aA'){H%{idA'))



{fiA'oaA')(HA(idA))



(fjLA>



aA'

naturality of a



(/x^'



Fp

naturality of fi



(F'g o \iA



HA){idA)

o a



a) {ida)

¥(AtF))(a).

done, for Lemma 2.5.3 implies that \£ must be

transformation which is

an

inverse for ¥.

Let



natural □

66

Chapter

It is instructive to

Example 2.7.5

for groups arises

theorem

so

group; g-.-k



be

can

special

as a

regarded

as a

Category Theory



how the

see

case

2.

Cayley representation

one

object



for each element g G G. Consider the functor F:G

—> ?

g:

* —?

Tg\G

I—?



in which the function rg is denned that there is a subgroup

by rg(h) C

Nat(H*,F)

Let G be

of the Yoneda lemma.

category with

and



Set

—*■



morphism given by



—?■

hg for all h G G. Let



Primer

us

show

(1)

Perm{G)

Perm(G) is the group of permutations on the (underlying the set Nat(H*,F) is regarded as a group via composition

of) G,

where

set

and

of natural

transformations. To permutation

by



a:



on

G,

if h G

that every natural transformation H*

note that

function a*: —>

see

G(*,*)

natural transformation



—?■

F(*),

G. The naturality of

G, and if



G G is the



that is

tells

(overloading

that it is

us

identity element

a(a(e)_1 h)





H*

a:

the

—>

—?■

F is

F is determined

notation)

bijection



on



function

G; for example

have

we

a(e) a(e)"1







surjective; injectivity is proved similarly. Applying the Yoneda lemma to the functor F, we find that there is a bijection of sets and

so a

is

G-=+Nat(H*, F)

(2)

g^Tg

isomorphism of groups. Putting (1) and (2) together we see that G is isomorphic to a subgroup of permutations on G, which is Cayley's representation theorem. which is in fact

an

Exercises 2.7.6

(1) Verify

that # in

(2) Verify

that the Yoneda

functor for any

(3)

Example

2.7.2 is



embedding

natural

isomorphism.

H.C

[a**, Set]

-+



—*

(a) If Fx is the empty set 0, what

(b) an

Let



X. Show that to

give

element ex G Fx for each

whenever y G X and

(c) Investigate



full and faithful

locally small category C.

Set be preorder and let F: X x *-+ Fx for the operation on objects and x < y operation on morphisms.

Let X be

is







can we



functor where

/X)J/: Fx

i->

say about



satisfying



—>

a:

Ha

—?■

< x, such that

< y.

the Yoneda lemma in this situation.

will write

Fy

for the

G X?

natural transformation

G X

we

F is to

/X)y(ez)

give =

ey

2.8.

Cartesian Closed

2.8

67

Categories

Categories

Cartesian Closed

DISCUSSION 2.8.1

We

begin by giving some intuition behind the idea of cartesian closed categories. Consider the category Set. Given sets A and B, the collection of functions A B is again a set, written Set(A, B) using the notation of the previous section. Thus Set(A, B) is actually an object of the ambient category Set. In a cartesian closed category C, for any objects A and B, there is an object A =¥> B of C which has properties making it "resemble" the collection of morphisms A B in C. Also, in the category Set, for every B defined by pair of sets A and B, there is a function ev: (A => B) x A ev(f,a) f(a), for any f.A^B and a G A, which "evaluates a function at an argument." Bearing this in mind, let us now give the formal definition. —>

—>

—*■



A category C is

objects

any

cartesian closed



B and C there is

an

ev:

category if it has finite products, and for

object

(B

=?

C)



=>





C and ->

morphism



f:AxB-+C there is a unique morphism A(/): A (B => C) such that / evo(\(f)xidB). This is another example of a universal property. In this definition, the object B =¥> C is called the exponential of B and C and ev o (g x zc^) for A(/) is the exponential mate of /. We shall also write g* any morphism g: A (J? =>? C). such that for any

—?■





—?

Examples 2.8.2

(1)

We shall

see

later

on

that cartesian closed

categories arise being we simply

of functional type

For the time

with

cartesian closed category.

our

theory. first example of a

cartesian closed

as

natural models

hint at this fact

The category Set is

{0}

and

given by set-theoretic cartesian product.

The

category. A specified choice of terminal object is

(specified) binary products

are



exponential of A and B is the set of functions from A to B. The function ev: (A => B) x A B is given by ev(f, a) f(a), where a G A and f:A-+B is a function. Then given any /:Xxi->Bwe may define A(/): X (A => B) —?■



—>

by letting X(f)(x)(a) f(x, a) for each x that / ev(\(f) x id) and that A(/) is =



this

equation. Now theory. In Set, X(f)

(2)

we can

may be

another small

the



A. It is easy to check

unique function which satisfies

begin to see the connection with functional type regarded as a "curried" version of the function /.

The category Cat of small

exponential of C and V

X and

categories is cartesian closed, being given by the functor category [C, V\.

category.

with the Note that

[C, V]

is

68

Chapter

(3)



lattice viewed

Heyting

Heyting implications

as



Category Theory Primer



category is indeed cartesian closed, with

exponentials.

as

2.

In fact such



lattice also has finite

coproducts. The category of Scott domains and continuous

(4)

closed. This is

tricky

to prove, and

Finite

products

are

given



the pointwise order

as a

proposition.

would be

as

product of Scott domains is the the order is given pointwise. Now let B exponential of B and C is given by the set set of

example

state the

is cartesian

The category SDom is cartesian closed.

Proposition 2.8.3 Proof

so we

functions, SDom,

(so given f,g:B

—?

expected. The underlying product of the underlying sets, and and C be two Scott domains. The

of continuous functions B

C then



< g iff

/(&)



C with

—?

holds in

g(b)

C. The

morphism ev: (B => C is given by the continuous function defined by ev(f,b) C) x B /(&). Given any continuous function f:AxB-+Cwe define X(f):A (B => C) by setting A(/) (a)(6) f(a,b). It is easy to verify that these definitions make sense. The only thing which is not clear is that B => C is indeed a Scott domain. If F C B => C is a directed subset, then \_\B^CF is given by (LWF)(&) Uc{f(b) \ f eF} for each 6 G B. One can check bounded cocompleteness similarly. It remains to verify that B =¥> C is algebraic. Let us define a continuous function C for each b G B° and c G C° by [b,c]:B setting (for x G B) C for each b G

B),

which

shall denote

we



by

=>

—?■



—?■





—?





M(X) Note: As



b G B° and

convenient c G









if b<x

± otherwise

notation, whenever

we

write

[b, c]

it will be

implicit

C°. We shall characterise the compact elements of B

algebraicity at the same time; in fact the compact elements precisely those continuous functions of the form / [61} cx] V

prove are



for finite B

=>



G N where c* <

C is bounded

function. First

we

/(&;)

cocomplete,

check that





=¥>



[6n, cj

exists because

is indeed



continuous

show that



{\f[bi,Ci] | f=i

one can

join

C and

of B

...

for each 1 < i < n; the

and

=>

that







N,Cj



Vfe>cj](&i)> 1







n}



(B

=>

C)°.

(1)

f=i

Suppose that V?=i [&*.<*] < U^ for F C I? => C. Then for any j where 1 < j < n we have c,- < V?=i[&?,<*](6,-) < U{/(&;) I / F} implying that c? < /j(&j) f°r some /j G F, because Cj is compact. Hence [bj,Cj] < fj for

2.8.

Cartesian Closed

any

j,

so

V?=i[^,q]

/? Thus V?=i[&i,Ci]



=>

C)°



In order to do this,

f x

{i



| bi

we





claim that

N,Ci

so

(1)



G F for which

holds. Now

Vfe>*]&)> 1





??' ^

Vj jc{i,...,n} cj



/(x)

i <

show

we

(2)

n>-

/: B

any continuous function

given

LK Vfe.*] I^N^< f(bi)A<

V?=i[^?q](^) x}. So



is compact and

{\flbi,*] |

G I? then

G N

implies that there is /

that the directedness of F

(B

If

69

Categories

—>

C,

(3)

n}.

where

have set J

we





To show that





LKVM I

following. Take x algebraicity of B. By continuity

N,c*



consider the



/(6f),l

B where

of













|J{6



n} B°



6 <

x} by

it is sufficient to show that whenever

beB° with 6 < x, then

/(&)



LK Vfe. <*](*) I





N,cf



/(6f),l

< i <

n}.

Certainly V{M|&G£°,cgC°,c </(&)}<

and

so

it is sufficient to prove that

f(b) But all

using

we

the



\J{{b,c}(x) \beB°,ceC°,c< f(b)}.

algebraicity

of C

need to show is that if c <

But this is

c <

and

that SDom is

/(&)

have

f(b)



U{c

for compact



then





G C°



c <

f{b)}

and

so

and b then

[6, c](x), showing (3). Hence if V?=i[&i,cf], showing (2). Note that —

(3) we must have / (3) together prove algebraicity. from



\f{[b, c](x) \beB°,ceC°,c< /(&)}.

immediate, for if b <

f e(B=> C)°,

(1), (2)

we



cartesian closed category.

This

completes

the verification □

70

Chapter

that C is

2.

Category Theory



Primer

locally small category we can give Let us a slightly different definition of the notion of being cartesian closed. introduce some more notation, and then present the equivalent definition as Proposition 2.8.5. Let C be a locally small category with finite products, let A, A', B and C be objects of C and ^i'-^Aa morphism. Define a functor F: C*9 Set as follows, where /: A x B C is any morphism in C: In the

DISCUSSION 2.8.4

case

—?

—?

g:A'-+A Note that

we

Fg:C(A

k^

shall often write



C(—

C(—



B, C)

C09 for which there is



natural

that the functor

is

we

have the

ff,C)







B, CYC*9

=?

/(P

id*\



C(A'



B,C).

Set for this functor. Recall

—?

if there is

representable isomorphism

C(- xB,C)^ C*(B Now



C, -) d= C(-, B

an

=?

object



=>

C in

C).

proposition

Proposition 2.8.5

Suppose

that C is



locally

small category with finite

products and that B and C are objects of C. If the functor C(— x B, C) is representable by some object B => C for all such B and C, then C is a cartesian closed category with exponentials given by B => C. Conversely, if C is a locally small cartesian closed category, the functor C(— x B, C) is well defined and represented by the exponential B => C for all such B and C. Proof

(=>) Suppose objects

B and C

C(— x B,C) is represented by .B => C (for every pair of of C), where, say, we have a natural isomorphism denoted by

that





C(-



B, C)



C(-, £

C)

=?



#.

We write

A(-) : C(A xB,C)^i C(A, B

=?

C) : (-)*

for the components of the natural

isomorphisms at A, that is we write A(—) for ¥a and (—)* for ^a- Thus given a morphism /: A x B C in C there is a morphism A(/): A (I? =>? C) in C. Unravelling the definition of naturality —?

—>

in A at

A(/)

we

get the following commutative diagram:

C(B

=?

C,£

=?

C) -^ C((B

=?

C)

C(A(/),B=^C) C(A, £



B,C)

C(A(/)xB,C) =>

C)



C(A



£, C)

2.8.

Cartesian Closed

Setting

ev

(idB=>c)*,



and

[C(A(/),B

A(/)*

that is

provided A(/)

ids)





71

Categories

using commutativity,

C)(^c)]*

=?

ev(X(f)



id#).



Thus C is

unique morphism A

is the

C(A(/)



(i?

—?■

get

we

B,C)(ev)



cartesian closed category



C) satisfying /

=>?

ev(X(f)





for each

f:AxB^C. To see that this is the case, first note that for any morphism g: A (B => C) we have g* ev(g x ids), which follows from naturality of A(—). Now suppose also h: A (B => C) is another candidate —?



—?

for

(^=) we a

Then h

A(/).

A(/i*)



Now suppose that C is

claim that

natural

C(—



C(-



B, C) isomorphism ¥



by appealing

B, C)

are

mate in



is

£*

(^{B

C, -) d= C(-, J5

=>

shall define

we

C(A xB,C)^=?: C(A, B

of

closed category. Then

C. Let



=>

=?

C) : ¥_1

us

define

isomorphisms (bijections)

C) : (-)*

=?

A(—) is given by exponential ev(g x idB). From the universal

the components of ¥ and ¥_1. In fact

C, and if g: A

—*■

(B

=>

exponential mates, of sets, for example note that

g*

implying that X(g*) We also need to =

X(f) showing uniqueness



locally small cartesian represented by the object

property of

A(—)

ids))





2.5.3, that is,

to Lemma

A(-) which

X(ev(h



¥A

amounts





idB)



B, C)



see

where g: A'

—?■



that

ev(X(g*)





—?

we



have defined



bijection

idB)

we can

show

is natural in

A(/)*



/ similarly.

A, which in the

case

of

—^ C(A, B^C)

B, C)

C{A! commuting,

#*

it is easy to

g, and if

C(A

C{g

then

/: A x B that the bijection to the diagram



see

ev(g



C)

C(g, B^C)

B, C)

—-*

A(—)

A in C. To

C(A', B^C)

see

this, take f:AxB^C and note

that

C(g



B, C){f) d= f(g

implying

idB)



ev(X(f)



idB){g



idB)



ev(X(f)g

X(f)g X(f(g x idB)) from the universal property. C(g, B => C)(X{f)) X{C(g x B, C)(f)) as required.

that

have shown









idB)

Thus

we



72

Chapter

Prove that the

Exercise 2.8.6

to check all of the details

useful when

giving

category. We

(f,g) where

can

(A,B)



(/, #): (A, B)



sure

carefully.

functor



(4,0)

(—)

=>?





(A', £')

notation which will prove

some

semantics to type theories.

define

Category Theory Primer



category VCPO is cartesian closed. Be

We end this section with

Discussion 2.8.7

2.

Let C be

(+):Cop



(A

=* g :





—>

B)

=?



cartesian closed

by

—>

the

(A'

assignment

B')

=?

morphism oiC^xC, A=> B and A' => B' are exponentials in C, and we define f => g A(poevo (z'd^-^ ></))? Given an object A of C we can similarly define functors A => (—):C C and —?

is of course





—>

(-)=^A:C°p^C. Let F: C preserves

V be

functor between cartesian closed

categories which finite products. We say that F preserves exponentials if the exponential —?■



mate of

F(A is

^B)xFA-^ F((A =? B)

isomorphism \(F(ev)o =): F(A witness the canonical isomorphism.

=>

an

B)



A) ^

(FA

—>

FB

FB)

=>?

and

We shall also refer to such

cartesian closed functor. A cartesian closed functor F is strict if

and

product preserving functor)

we

X(F(ev)o =)



call this

an

(it

is

F a

as



finite

idpA=>FB-

Exercises 2.8.8

(1) Formulate precisely the definitions of the functors C, where A is an object of a cartesian (—) => A: C*9 —?

(2)

Let C be

be

morphisms of C. Show that (#/)*

(3)

Let

f:A







—?■

category. Show that

(4)

Let A be

X(gf)

object of products.

an

preserves finite

(5)

C and =



Formulate the notion of

that A



(—):C

—?

C is such

Note: All the category

j:C

(ids

D be

->

=>

</*(/



{—)'?

=>

closed

f:A^B

cartesian closed category and =



—?

category C.

and g: B

—?

(C



=>?

£>)

idc)-

morphisms

of



cartesian closed

g)X(f).

cartesian closed category C. Show that A



C and

=>

(—)

finite

coproduct preserving functor and show functor provided that C is cartesian closed.

theory required

to read

Chapter 4

has

now

been covered.

Monies, Equalisers, Pullbacks and their Duals

2.9.

73

Monies, Equalisers, Pullbacks and their Duals

2.9

DISCUSSION 2.9.1

We

begin by considering the notion of monic and epic morphisms. Roughly, a monic morphism is the categorical analogue of an injective function, and an epic morphism is the categorical analogue of a sur- jective function. However, the reader should note that this comparison is not as strict as one might hope, as we shall see in later examples. Let us now give the formal definitions. B in a category C is monic if given any morphisms morphism /: A A for which fg h. We denote a monic morphism by g,h:C fh, then g f:A>-^B. In the categories Set, Mon, uCPO, and Qrp, the monic morphisms are precisely the morphisms whose underlying set functions are injective. In a preorder X regarded as a category, all morphisms are monic. A morphism B in a category C is epic if given any morphisms g,h:B C such /: A that gf h. We denote an epic morphism by /: A B. An hf, then g epic morphism is the dual notion of a monic morphism in the sense that a B in a category C is epic just in case e: B A is a monic morphism e: A morphism in C09.



—>

—?





—>

—?■



-?



—*■

—?

morphism is epic just in case it is surjective. It is clear that a surjective function is epic. Conversely, suppose that / is not surjective and In

Set,



consider 9



A—J-^B

h where for b G

B,

by

g is defined



0, and h is defined by

t->

([



T{0,1}

o if b e

f(A)

1 otherwise

p^/i, but gf hf implying that / is not epic. One can also check that a morphism in Set is injective just in case it is monic. Unfortunately, such a correspondence does not always hold, as we now see. In the category Ihig of commutative rings and ring homomorphisms, the canonical inclusion i: Z Q is epic but is clearly not surjective. To see the former, suppose that Then



—?





>Q



: R



ring homomorphism h: Q have for q m/n G Q:

is commutative. Recall that any

by

its effect

h(q)



on

Z;

to wit

we

h(mll)h(n/iyl



—?

R is determined



^(^m))^^^))"1



^(m^Wn))"1



g(q).

Chapter 2.

74

Hence g





Category Theory

Primer

h.

of

categorical notion of an equationally denned subset. Given the functions /,^:Kxt->K given by (x,y) \-> x2 + y2 and (x, y) i-> 1 for each (x, y) G I x I, the equaliser for / and g is the subset ofRxR given by Equalisers

can

be

thought

as



{(x,y) eMxM|x2 Now for the definition of



y2



equaliser for a pair of morphisms /, g: A A such that morphism e: E

—>

B in

category C is given



—?



fe



given

/i

l}.

equalisers.

An

by





ge and any h:C



A with

//i



there is

#/i,

unique k:C



-+

E for which

efc.



It may be

helpful

diagrammatic

to view this data in

^—?





form:

ztB





K I

c The notion of

coequaliser is dual to that of an equaliser in the following B in a category C is sense. A coequaliser for a pair of morphisms f,g:A A in the category given by an equaliser for the pair of morphisms f,g:B a

—>

—?

Example 2.9.2

{a

G A

| /(a)



In <Se£

0(a)}

an

equaliser

for

/, g: A

—?

i? is

given by the inclusion

A.

->

Exercises 2.9.3

(1)

Show how to construct the

equaliser of any two continuous functions in the

category VCPO. Prove that your construction works.

(2)

Write down



full definition of



coequaliser

similar to that

given for

an

equaliser. (3)

We construct

coequalisers

ideas. Let 5bea set, and R The  ̄

equivalence

relation

C Bx B such that R C

Then there is



relation

in the a

category Set.

relation

generated by  ̄.

on

on

B, that is



some

background

subset R C B



B.

equivalence relation f,g:A^>B are two functions.

R is the smallest

Now suppose that



First,

given by S



{(/(a), </(a))

B x B





A}.

Monies, Equalisers, Pullbacks and their Duals

2.9.

(a)

Let J? be



relation

{(&,6) |

^ {(b',b)eBxB\ (b, b')

Ri+1



3b'

(b) By thinking

(6,6')

e B.

Show that the set

generated by



R},

R0 d= R U A U #*, and set

Now set

{(&, b")eBxB\

for each i G N. relation

B}.

6 G

set B. Define

on a

R°p

and A d=

75



Ri and



\J{Ri |



(&', b")

N}

i G



is the

Ri}

equivalence

R.

coequaliser in Set, the relation 5, quotients by equivalence relations, construct a coequaliser for / and g in

and

about the definition of



Set.

(4)

objects and morphisms which appear in this exercise lie in C. Let /: A B be any morphism. We say that / is a split A for which gf id a, and that / is a monic if there is a morphism g: B regular monic if it occurs as an equaliser, that is, one can find an equaliser in Let C be any category and let all —?■

—?



C of the form





A—-—* B

: C k

let A

For the

following problems, morphisms. (a)

Show that both

(b)

Show that if

/ and g

(c)

Show that if

gf

is monic

(d)

Show that if

gf

is

split

monies and are

monic

—?

B -^ C be

regular

(split monic)

(split monic)

regular

monies

then

monic and g

then



composable pair



are

monies.

gf

is monic

is monic

of

(split monic).

(split monic).

monic, then / is regular monic.

Finally we define the notion of a pullback. A pullback for C in a category C is given by morphisms f:A—*C and g: B

DISCUSSION 2.9.4 a

pair of



an



morphisms

object

—?

A Xc B of Pa'

C, together with

Axq B two

foh





A and ps'- A Xc B

morphisms h:D unique morphism m:

such that

given any gok, there is

—>

—>

—?■

B for which

A and k: D



—?■



—*

/ opA



gopB,

B in C for which

xcB for which pA°rn





Chapter 2.

76

and pb

om



k. We

can

picture these data in



A Category Theory Primer

diagram:



We say that pa is

pullback of g along f and that pb is a pullback of f along B in a category A and g: C g. A pushout for a pair of morphisms /: C C is given by a pullback of /: A C and g: B C in the category C09. a

—>

—?

—?

Example 2.9.5 and

We look at

j:B->Ca pullback

7r2: P

—?

—?■

is

pullbacks in Set. Given functions f:A A given by the pair of morphisms iC\.P

—>

—?



and

B where

Pd^{(a,b)eAxB\f(a)=g(b)}, 7Ti(a, 6)





and

7r2(a, 6)



6.

gives us a pullback, take functions h:D —*■ A and k:D -+ B such that fh gk. Then there is certainly a unique well defined function e:D -+ P for which ^e h and 7r2e k, given by e(d) (h(d), k(d)) where To

see

that this =







deD.

Exercise 2.9.6

Suppose that Y



is



binary coproduct diagram

We finish this section with



-x + y

in Set. What is the

lemma that

we

pullback?

shall need later

on.

2.10.

77

Adjunctions

LEMMA 2.9.7

precisely, given pullback



of

morphism. More C, and a category C, morphisms f:A—*C and m: B



pullback



monic

morphism

is



monic

>—?



then m' is monic.

m'k. morphisms for which m'h Then both h and A: factor ra'A; through m', and because m is monic both h and k factor gh through g, implying that h k from the uniqueness property of pullbacks. □

Suppose

PROOF

that

h,k:D

—?



are





Adjunctions

2.10

We shall illustrate the concept of

Discussion 2.10.1

adjunction

in the

categories are preorders and the functors are monotone functions. preorders X and Y, then the monotone function /: X —> Y has a left

situation where Given

adjoint if there exists

X for which

given any i6l and y Y then y < f(x) iff l(y) < x. The function / has a right adjoint if there exists a monotone function r:Y —? X for which given any x G X and ?/ G y we have /(x) < y iff x < r(y). An adjunction between preorders X and y is a pair of monotone functions / and g for which / is a left adjoint to g (or a

monotone function I: Y

—>

equivalently g is a right adjoint to /), written (/ H ^). propositions which illustrate the properties of adjoints; for the set of monotone functions X

—>

Y, regarded

We have the

following

shall write X

we as a

preorder

=>



with the

pointwise ordering. Proposition 2.10.2 and Y

are

Suppose

preorders. Then (/



that

f e p) iff idx

X =>Y and g eY => X where X <

S'/

in X

=>

X and

fg

have

/(x)



idy in

Y^Y. Proof

(=>) Suppose that (/ H #). implying that x < g(f(x)), that

Then for all is

idx







X,

we

gf- Proving fg





/(x)

idy is similar.

(<¥=) Conversely, suppose that the inequalities of the proposition hold. Suppose that /(x) < y. Then x < g(f(x)) < g(y) using monotonicity of g, that is □ x < g(y)- That x < g(y) implies /(x) < y is equally easy.

78

Chapter

A monotone function

Proposition 2.10.3

iff there is



function



for all y G Y



for all



have

we

G X and

Each value

r(y)

r:



Category Theory



2.

f:X

—>

Y has



Primer

right adjoint

X such that

—?

f{r(y))

j/GFwe

< y,

have

and

/(x)

uniquely

is determined

implies

< y

x <

r(?/).

isomorphism by

up to

the stated

conditions.

Proof

(=>) Suppose the



has



right adjoint

It is clear that this

r.



will do for

of the proposition.



(<=) Suppose

now

that

given such

we are

an r.

The

is monotone, for if this is so, the conditions of the

that



(/

r).



that

Take y <

y'

only thing to prove is proposition imply that

f(r(y)) <y<y' implying

in Y. Then

that

r(y)



r(y'). D

Let X and Y be

preorders. Suppose that f,f'eX=> Y and g,g' G Y =? X with (/ H p) and (/' H p')- Then / < /' iff g' < g and similarly /' < / iff g < g'. Thus we have / /' iff g g'. This implies that an adjoint to a monotone function is unique up to isomorphism; and if X and Y are in fact posets, then the adjoints are unique. Proposition 2.10.4





Suppose that g' < g. Then foidx< f{g'f) implying / < /'. The other facts are proved similarly. PROOF

Proposition 2.10.5

Suppose

that

we are



(fg)f



idY



f □

given preorders and monotone

functions X











' .



g for which

(/

PROOF

For all

x <



g)

and



(h



k).

G X and

Then





g(k(z)).



Z,

(hf we



gk).

have

h(f(x))





iff

/(x)



k(z)

iff



Y be a monotone function between preorders /: X X and Y. If / has a right adjoint then / preserves all joins which exist in X. Dually, if / has a left adjoint then / preserves all meets which exist in X.

Theorem 2.10.6

Let

—>

2.10.

Let A C

Proof

every y e Y

X,

Y, and suppose that V A exists in X. Then for

/(V A)

have

we

y G

< y

iff V A <

V f(A) exists and is isomorphic

Hence

is

79

Adjunctions

to

r(y) iff A < r{y) iff f(A) < y. /(V A) as asserted. The dual result □

proved similarly. The theorem which follows is known

Discussion 2.10.7

as

the

adjoint

for preorders. It is a very useful result, giving conditions for the existence of left and right adjoints to monotone functions. functor theorem

Theorem 2.10.8

and suppose that X them.

Define



function

for each y G Y, and

the

—?

hypotheses

of

Proposition

f(x)

< V-

f(r(y))

that

Then

r:



—*■





monotone function between

Then



is well defined



f(r(y)) implying

be

if X has all meets then

Dually,

PROOF

Y /: X has all joins.

Let

2.10.3.



has



has





left

preorders

right adjoint if it preserves adjoint if it preserves them.

by setting r(y) \/{x G X | f(x) < y} by hypothesis. We show that r satisfies Now, / preserves joins, and so =

\/{f(x)\xeX,f(x)<y} given, and suppose that right adjoint. If / preserves

< y. Let x G X and y G Y be

certainly





all meets, the construction of

r(y), a

left

and

so r

adjoint

is

for







is similar.

Examples 2.10.9

(1)

Let 1

{*}

preorder with * < *, a terminal object in VreSet. Given a preorder X, the unique function lx'-X 1 (which is trivially monotone) has a left adjoint iff X has a bottom element and a right adjoint iff X has a top element. As this is the first example, we spell out the easy details. Suppose X. Then for all x G X we have * <\x(x) implying \x has a left adjoint 1:1 /(*) < x. Hence l(*) is a bottom element of in X. Conversely, if ± is a bottom ± gives a left adjoint to \x- element of X, defining /(*) =

be the

—?

—?



(2) Let X be

binary meets and joins. There is a monotone function A:I->IxI given by A(x) (x, x). Then we have (V H A H A) where A: X x X X takes a pair of elements to their meet (and similarly for preorder



with



—>

v). (3)

Let

/: X

—>

Y be

Z"1: V(Y)

(see Examples For

example,

->



function. Recall the functors

V(X)

1.2.17 and

let A C X

3f: V(X)

->

V{Y)

(monotone functions)

V/: V(X)

->

V(Y)

Examples 2.3.3). Then we have (3/ H f ̄l H V/). and B C.Y. Suppose B C "if {A). Then for each

80

2.

Chapter

Category Theory



Primer

A, implying that f ̄l(B) C A. Also, f ̄l(B) C A implies B C V/(A) is immediate, and so (/_1 H V/). That (3/ H /_1) is b e B

we

/_1({&})

have



similar.

(4)

T(D) the set of inductive subsets. One can check that meets are calculated in T(D) by taking intersections in V(D). It follows that the inclusion 1(D) —*V(D) preserves all meets and so has a left adjoint using Theorem 2.10.8. Indeed, the left adjoint l:V(D) 1(D) is given by 1(A) f|{/ 1(D) \ACI} for every A e V(D). Let D be



and

dcpo

—?



E in £>CTO. Then the function f ̄l:V(E) (5) Take a morphism f:D 7^(1)) restricts to give a monotone function f*:l(E) 1(D). This has a left adjoint l:X(D) X(.E') where given / G 2"(D), ->

-??

—?

—?



((/) /*

does not in

have

general

fK-> e l(£) | /(/) right adjoint—can





J}.

you prove this?

adjoint functor. The forgetful functor U: Mon Set taking a monoid to its underlying set, and the functor (—)*:Set Mon taking a set to its Kleene closure, are related in We

Discussion 2.10.10

to the definition of

now move on —?

—?



certain way which

Given



describe.

we now

monoid M and

unique monoid morphism

(-)





set A any function g: A

g: A*

—?■

Indeed, there is

M.

Mon(A\ M)

—>



Set(A, UM)





UM

corresponds bijection

to



(-)

given by



f:A*^M and

one can

check that this



where at any



Set(-, U(+)) object (A, M)

(—)? (¥-1)(>i)Af) (-)* and U. =

Exercise 2.10.11

This is



i—





bijection gives =

an

rise to

Mon((-)*, +)

of Set01?



example

Check the

Mon of

an

an



f(\a}) J-^i UM. a

Set09

we

natural x

have

Mon

¥(a,m)

adjunction

isomorphism ->



Set

(—)

an(^

(say)

between the functors

naturality of the isomorphism.

81

Adjunctions

2.10.

Now

DISCUSSION 2.10.12

Let F: C to G

or

V and G: V

—?

that G is

we

—?

ngfa adjoint

give

formal definition of



adjunction.

C be two functors. We say that F is to F if

given

A of C and J5 of X>

objects

any

Ze/fc adjoint we

have ?



bijection

shall illustrate

and

morphisms FA diagrammatically as

between

5 in V and A

GB in

—?

f:FA^B

g.A^GB

J-.A-+GB

g:FA-+B

C, which

we

moreover

this

bijection is morphisms a: A' ?

—?

natural in A and

—>

bo It may be



A in C and 6: B

Fa



helpful

to



Gbo



B, which by definition B' in V

—>

and

oa

we

means

that

given

have

(Gbog o a)A



6op



Fa.

picture the naturality thus:

/i

bo





-7

Fa

i—-

bo





Fa



Gbo



o a

and 01

Gbo g

?9

oa i—*

(G6 o g o a)A



bo go Fa

If F is left

adjoint to G then we write (F H G). An adjunction consists of a pair of adjoint functors F and G together with a choice of natural bijection. We shall refer to / as the mate of / across the adjunction; similarly g is the mate of g.

Suppose

Remark 2.10.13

Discussion 2.10.12 and that C and V G

(that is, there

and this

is



bijection

that functors F and G are

locally

are

adjoint

as

small. To say that F is left

between the

in

adjoint to A G.B,

B and morphisms FA B) is equivalent to saying that —?■

bijection is natural in A and a natural isomorphism between the functors

C(-,G(+)), V(F{-),+):CopxV^Set

—?

there is

82

Chapter

which

are

2.



well defined because of local smallness. In

of the word "natural" should not

cause

Category Theory Primer

practise, this overloading

problems.

Examples 2.10.14 Set has a right adjoint (1) For a fixed set A, the functor A x (—):Set Set. For given sets B and C, functions f:B Set(A, ):Set Set(A,C) correspond bijectively to functions g.AxB^C (what is the bijection?) and —?

—?



the

(2)

bijection We have

is

—*■

natural in B and C.

certainly

((—)*



U)

A* is the free monoid

described above in Discussion 2.10.10. Recall that

as

A, for each set A.

on

through the creation of freely generated mathematical structures possess right adjoints which forget about the additional structure. Another example of this phenomenon is the construction of a vector space generated by a set X. Let F: Set Vec# be the functor which takes a set X to the vector space generated by X. Recall that a vector in FX is a formal finite linear combination T,i nkiXi where the X{ are

(3)

It is often the

case

that functors which arise

—>

elements of X and the

ki

are

scalars in the field

multiplication defined in the usual way. Given FY is defined by linear map Ff: FX



K, with addition and scalar function f:X —> Y then the

—*■

There is also



functor U: VecK

Set which sends

—?■



vector space V to its

UV is a function. Then it is Suppose that g: X V. not difficult to see that g has a unique extension to a linear map g: FX The assignment g *-> g has an inverse: given a linear map f:FX V, f restricts to a function /: X UV. Thus we have a bijection

underlying

set of vectors.

—*■

—?

—?

—?

H which

we can



Set(X, UV)



check is natural in the

(4)

The

to

(/,/): (A, A)

diagonal functor —?

A: Set

(B,B)

has

—>

VecK{FX, U)

required Set

right



Set

and left

->

taking a function f:A-+B adjoints II and E taking any B x B' and to / x g: Ax A'

—?

->

is the function defined to be

where

LB-B-+ B + B' This

(-)

sense.

morphism (/, g): (A, A') (£, B') of Set x Set B + B' respectively. Here, / + g / + g: A + A'

[*b/, lb>9]



example

remains valid if we

the reader to define the

diagonal

<-

£':

replace Set by

tB/.

any

category C, where

functor A:C^CxC.

we

leave

2.10.

(5)

83

Adjunctions

The category Cat has

objects all small categories and morphisms functors

between them. Then the functor ob: Cat

Set which sends

—?

small category



underlying set of objects has a left adjoint dis, where dis sends a set A to its corresponding discrete category (a discrete category is one in which the only morphisms are the identities), ob also has a right adjoint ind which to its

maps



set A to the indiscrete

precisely dis: Set

—>

to the set

where a

morphism

one

Cat also has con

morphism



b for each

left

adjoint

follows.

C and

/:



—?■

B. We make this

Suppose

conC

—?

that C is

B. Then

then

F{[C})

natural in the

(6)

If

required

FC. sense.

-<

Cat{C,



/(C) id: f[C]



—?

Summarising

B just in a

u:



—?



case

obC/



there is

bijection

C is

f[C] where [C] f[C']. If now we



con

B): (-)

check that

can

-<

Define

dis

of C, and

object

One

where A

explicit.

more

set =

By definition,

we

F:C

have

(con

have

is

morphism of the equivalence a

dwB is

—?

given





bijection,

H dis H ob ̄\

ind).

equivalence F:C  ̄V:G then it is the case that each functor is both left and right adjoint to the other. For example, to see that (F H G), we define a bijection between morphisms FA B and morphisms A Gi? by £ /: FA we

have



an

we

f(u)

class of C under =, and

functor,

which maps each small category C

con

equivalence generated by

(-):Set(con C, B) as

pair (a, b) of elements of A. The functor

C of connected components of C.

is the



a —?

category with objects the elements of A and

an

—?

—?■

->

G(/)ot7i4:ASGFi4->GB and

eBoF(/):FA->FGB^B where

(7)

e:

FG



idx> and

77:

idc



GF. It is

an

easy exercise to

Recall the definition of cartesian closed category

given

In fact there is another formulation of cartesian closed to be

equivalent

category which

Let C be



as a

turns out

proposition:

category with finite products. The

C for each object B of C, right adjoint R to the functor (—)xB:C equivalent to the definition of cartesian closed category in Discussion 2.8.1.

existence of

is

in Discussion 2.8.1.

to the earlier definition. We shall state this

Proposition 2.10.15

verify naturality.



—?

Proof

(=>) Suppose B of

proposition. Given an object B, and set B => C =f R(C) for any

that C satisfies the data of the

C, let R be the right adjoint of (-)



84

Chapter

object

Category Theory Primer



morphism f:AxB-+Cwe define A(/): A / across the given adjunction. The morphism

C of C. Given

to be the mate of

2.



{B

ev:

C)

=*





{ids^cT °f tne identity ids=>c: (B => C) (B =¥> C). Next, show that ev(X(f) x ids) /? This follows directly from the

need to

the

->

adjunction;

(B

C)

=?

/ ev(X(f) morphism satisfying

that is

defined. Let B be we

denote

c:C

—>

ids)-

naturality

C:

-^

A(/)

°





i—-

A(/)*



of C. We shall define



h-



=?



X(c o ev): (B

(B p*

It remains to

required

sense.

B' be

ev o

implying

verify a

that

=>?



we

is the

right adjoint

C)

ev(g

C)

=?

->

as

idB)



unique

originally

(—)

to

(B

—?

C to be



->

A(/): A





zdB): A



have defined

A(6 o / o (a



id)

id))

C"),

—?

rise to

(B

=>?

an

C)

to be



C.

bijection



which is natural in the

only check one part of naturality. Let morphism of C. Then x

=?

bijection giving

We

((A(6 o ev)X(f)a)

that





—>

—?

A(/)

cartesian closed category

C" of C. We define morphism c: C adjunction by declaring the mate of /: A x B and the mate of g: A

(A(/)

o ev o

(—), by setting

=>?

for each

idc



equation.

suppose that C is

object

morphisms

in A and C at the

We let the reader show that

the latter

an

by

^s=>c

°





(<£=) Conversely,

consider

we

and idc: C

H(tdc)

—?

we

^>



naturality of A(/): A

6: B

C)

=>





is the mate

which

(B

—?

(X(b o ev)



ev o



bo

ev o



bo





(B

=>



b)

(X(f)a

(a







id)



id)



a:

A'

(X(f)a

—>



A and

id)

id)

A(/)

o a.



2.10.

85

A djunctions

Exercises 2.10.16

(1)

Fill in all of the

(2)

Is it

missing details of Examples 2.10.14. Verify in detail the proof of Proposition 2.10.15 working out all the missing stages. In particular verify that a bijection was indeed defined in the final part of the proof and the other naturality equation.

possible

to extend the chain of

adjunctions

Example

in

5 at either

end?

Proposition 2.10.17

(i)

Let G: V

of C there is

(ii)

Let F: C

C be

—?■

an

BofT> there is

Proof

For

initial V be

—?■

functor. Then G has





object



object

in the

adjoint iff for each object

left

in the under-cone

functor. Then F has

terminal







category (A j G).

right adjoint

over-cone

iff for each

object

category (F j B).

(i):

(=>) Suppose



left

F: C

adjoint

Define the

—>

V exists and let A be

an

object

of C.

GFA corresponding to idpA under the idpA- A morphism tja GB in C. Let this adjunction. Suppose that we are given a morphism g: A B under the adjunction. Then from naturality we have correspond to g: FA —*■



—*■

—?

idfa



It follows from the





idFA

bijection

*■







idfa

GgorjA

that g is the unique morphism for which

we

have



y \ GFA

that is t]A is initial in

(<=) Suppose

Gg

GB

(A I G).

that for each

object

A of

C, there is

an

object

B of V for

tia'.A —? GB is initial in (A | G). We define the functor F by taking FA to be B, and given a morphism /: A —? A' in C we set Ff to be the unique

which

86

Chapter

morphism Ff: FA

—>

FA'

making

the

2.

Category Theory



Primer

diagram A'



ylA' GFA commute. Of

We

can see

course we

this is the

GFf

GFA'

need to check that this definition does

case

from the commutative

yield



functor.

diagrams

A-f

A!



A!'

^a Va'



Va

Va

GFA

GF(idA)

GFA'

Va

Va"

GFA GFA

G(Fg



GFA"

Ff)

together with the universal property of the initial objects 77^, t)a> and tja"- —

Now

define

Given

for the

def

/ bijection adjunction. /: B using the GB and given g: A GB we define g: FA Gf o 77^: A initiality of t\a- It is simple to see that this is a bijection by directly unravelling the definitions. It remains to verify naturality. Suppose that we are given B'. Let g: A GB. We have to see that morphisms a:A'—*A and b: B we



—?■

—?■



we





Fa



(Gb o g o a)A. By

just need to

see

that the

—?



we

set



—?■

—?

—?



FA

the universal property of the initial

object

77^/,

diagram A' vG6 o go

GFA'

G(bogo Fa)



-GB'

commutes. We have Gb

where other the

we



Gg o

GFa



t\a<



Gbo

Gg

or)Aoa

have used the definition of Fa followed

naturality equation proof of (i).

is

by



Gbogoa

the definition of g. The

proved similarly, and the proof of (ii)

is dual to



2.10.

87

A djunctions

If the left adjoint of

Corollary 2.10.18

unique PROOF

that

given

we are



adjoint. For (F'A, rfA) (as defined in the proof

functor G:T> any

and

of

cxa'.

(FA,7]a)

—?■

(F'A,r/A).

(A j G)

C and let

—?■

F, F': C

—?



object A of C the objects (FA, t]a) Proposition 2.10.17) are both initial

be two choices for the left

in the under-cone category

functor exists then it is

given

isomorphism.

up to canonical natural

Suppose



and

so

there is

It follows that ola'-FA

—>

unique isomorphism



F'A is

an

isomorphism

morphisms a^ gives rise to a natural A' in F'. To see the naturality, take a morphism /: A isomorphism a: F C and consider the following diagram: in V and in fact such



collection of

—?

—?



Va

VW

Va'

L GFA'

\1a>



GF'f

Note that the left and right triangles square

(*)

GFA

GF'A

-A'

commute

GF'A!

using the definition of a, and the

(*) along with the outer trapezium both commute from the naturality of

bijection arising from the adjoints F and F' to G along with the definition of the t)a- This implies that both Ga^/oGF/ and GF'foGaA are factorisations of rfA,f through r)A- The initiality of t)a in (A [ G) implies that au' o Ff □ F'f o a a, as required.

the



Examples 2.10.19

(1)

Let T> be



subcategory

of



category C and write

t:



—?

C for the inclusion

reflective subcategory of C if the functor i has a left adjoint L: C V. We refer to L as a reflection functor and to the values of L as reflections. Note that using Proposition 2.10.17, it follows that V is a reflective subcategory of C if it is a subcategory, and moreover for each object C of C there is a morphism rfc'.C LC in C with the following universal D in C, there exists property: given any object D of V and morphism /: C functor. Then

we

say that V is



—*

—>

—?

88



Chapter

unique morphism /: LC

—?

D in V

2.

the

making



Category Theory Primer

following triangle

C Vc LC







f commute.

(2)

We say that V is

the inclusion functor

(3)

coreflective subcategory of C t: V C has a right adjoint.



(it

is



subcategory and)

—>

The category Jb of Abelian groups is

category

if

full reflective



subcategory

of the

Qrp of groups. What is the reflection functor? Recall that Cat is the category of lattices and lattice

Exercise 2.10.20

complete lattices together with preserve finite meets and arbitrary joins. Show that V is a (non-full) reflective subcategory of Cat. Hint: consider Proposition 1.5.18; in fact the reflection of a lattice X inT> is the poset of ideals of X.

homomorphisms. morphisms which

Let V be the category of

Proposition 2.10.21

Suppose

that

we are

F C

H HV



G)

(F

Proof

Morphisms



and

(H



HFA

K).

-LS



G for which

given functors



Then

we

have

(HF



GK).

B in S

correspond bijectively to morphisms FA KB in V and the latter correspond bijectively to morphisms A GKB in C. Both of these bijections are natural in A and B. □ —*

—y

—?■

Corollary 2.10.22

diagram of categories and functors, and that all of the functors have left adjoints. Then the corresponding diagram of left adjoints commutes up to natural isomorphism. Proof

Suppose

we

Suppose

have



that

we are

commutative



given



diagram

commutative

of functors

2.10.

89

A djunctions

which have left

Proposition 2.10.21

natural

(G'F'

have

we

isomorphism G'F'

commutative

diagram

into

Discussion 2.10.23

pair of functors F: C

for the

adjunction,

Thus for each A in

(A I G),

and

F), (G'



adjoints (F'

-\ GF

H'.





commutative

that

T> and G.V

given C. Writing

we are

—>

an

adjunction between

g:A->GB

J:A->GB

g: FA->B

C,

put tja

t)a is







id,FA'- A

—*■

GFA and e#

choice of initial

check that e# is

object



triangles.

f.FA^B

we

is

The result follows by splitting the given

appropriate

Suppose —?

G) and (#' H if). Then by H). By Corollary 2.10.18 there





idcB'- FGB

—?



B.

in the under-cone category

choice of terminal

object in the over- cone category (F j B) for each B in V. For each morphism f:A-+BofC one can check, using the naturality of the bijection arising from the adjunction, that the diagram we can



GFA



\GFf GFB Vb

commutes, and

so

the t\a

give

and this is called the unit of the transformation

e:

FG

—?

rise to



natural transformation r\: H

adjunction (F

G). Dually,

we

idc

have

(i)

C. Then to

There is

A in

—>

natural transformation 77: idc



Proof

GFA is

natural transformation

X>, the morphism

category

—>

—>

an

GF such that

initial

object

given

any

and

object

in the under-cone

(A | G).

There is

B in

V Suppose that we are given functors F:C give an adjunction (F H G) is equivalent to either of

C, the morphism r)A:A

category

(ii)



natural

following propositions:

Proposition 2.10.24 —?

GF,

id-p and this is called the counit of the adjunction.

This discussion leads to the

G: V



—*■

e#: FGB

—?

e:

FG

£ is

—>

id?, such that given

terminal

object

any

object

in the

over-cone

2.10.17 and Discussion 2.10.23.





(F | £). Follows from

Proposition

90

Chapter

2.



Category Theory Primer

V and Suppose that we are given functors F:C C. Then to give an adjunction (F H G) is equivalent to specifying transformations 77: idc GF and e: FG idx> such that the diagrams

Proposition 2.10.25

G:V

—?

—y

natural

—>

—?



—^

—^



GFG

FGF

Ge G

Proof

(=>) Suppose

we

have

an

G).



adjunction (F

Discussion 2.10.23.

It remains to prove that the

commute. For

object

an

icIfa

and

so we are



as

an

idpA



r)A



eFA

idcB



of the

diagrams

B of V

object

FrjA

we

e as

in

proposition

have



idcB



^b



GeB



r)GB

done.

(<¥=) Suppose morphisms

A of C and

Define 77 and

that

we are

given such 77 and

e.

Define



correspondence of

follows:

f:FA->B

g:A->GB

fd^GfoT)A:A^ GFA



GB



It is easy to check that this definition



yields



eB



Fg: FA

natural



FGB

->

bijection giving

Proposition 2.10.26

(i) (ii)

e:

an



adjunction.

counit



FG

Suppose

that G:V

->

C has



left

adjoint

F with

id-p. Then

—*■

G is faithful iff eB is

epic for each object

G is full and faithful iff es is

an

B of V.

isomorphism for each object

B of V.

Proof

(i) (=>) Suppose

G is faithful.

Let

C be two morphisms in /, g:B which feB g^B- Under the adjunction, /e^ corresponds to Gf: GB and similarly # £ to Gg implying that Gf Gg and hence / g. —*

—?



b is

epic; showing G faithful is

GC





(<=) Suppose in (=?).

V for

a reverse

of the argument used

2.11.

91

Limits and Colimits

(ii) (=>) Suppose some

h:B

—>

G is full and faithful. We have r)GB

FGB and hence idpGB

idstB and

so

ids



(<=) Suppose full.

Suppose

^sheB





Gh: GB

-?

GFGB for

hes- Therefore

(cBh)eB



sh because es is epic using (i).

isomorphism.

b is an

that



implying

Gh





/: GB =

—>

Gfo

that G is full

as

(i)

Prom

GC in C. Then

riGB



we

we

G( b1)

Gfo

just

need to show that G is

have



G(fo e^1),

claimed. □

2.11

Limits and Colimits

Discussion 2.11.1

Throughout this section, we shall refer to functors I C in which I is certainly small and possibly even finite as diagrams of shape I. The constant diagram on A (where A is an object of C) is just the constant functor A: I C which sends all objects of I to A and all morphisms of I to idA. Let A:C [I,C] be the functor which sends an object A of C to the constant diagram A on A and a morphism f:A^>B of C to the natural transformation A/: A B with components (A/)/ / where / is an object of I. First,

some

definitions.

—?■

—?

—?

—?



Products, equalisers and pullbacks are all examples of the notion of limit. We could do without explicit mention of the former examples, just talking of limits of certain kinds, but it is best to get used to the ideas involved by looking first at simple examples. Let us have a look at the definition of a limit. Suppose that D: I C is any diagram. Then we say that a limit for the diagram D is given by a terminal object in the over-cone category (A j D). Note that this formal definition will become clearer in the following discussion. By carefully unravelling the definition, we see that an object in (A J, D) is D, given by an object C of C together with a natural transformation k: AC which amounts to giving a family of morphisms (fcj: C DI \ I G I) in C (here we write just / G I for / G obi: note that I is small) such that for each J in I the following triangle commutes: morphism a: I —>

—?

—?

—>

92

Chapter

Such

called



cone



Category Theory

Primer

morphisms which satisfies the above commuting triangle

over

D and C is the vertex of the

cone.

So

now we can

hands-on

picture of a limit. A limit of the diagram D: I object lim D of C together with a family of morphisms

more an

of

family



2.

—?

C is

get

is a

given by

(kr.UmD-* DI\I el) which form

(hj:C m:C

DI

—?



D with vertex lim

a cone over

lim D





I)

over

the

making

D, such that given any other cone D with vertex C there is a unique morphism

following triangle

commute for each I el: DI



We sometimes refer to

We said that

m as a

products

category I

the discrete



mediating morphism. instance of the notion of limit.

are an

{0,1}

with two

objects,

and



diagram

Consider

D:I

—?

C.

D\ of C. Then a DO and B objects A limit of D in C consists of an object lim D P of C together with morphisms A and k\: P A and ko: P B, such that given any two morphisms h0: C P for which kom h\iC /i0 and B, there is a unique morphism m:C kim h\. This is certainly a binary product of the objects A and B. So D

essentially picks

out two







—>

—*■

—*■

—>

—*■





As well

as

considering

the notion of

category has all limits of



limit,

it is useful to be able to say

example, a lattice has all finite meets and joins and both meets and joins are examples of limits. We say that C has limits of shape I if the functor A has a right adjoint, and we sliall write lim: [I, C] C for such a right adjoint if one exists (recall that an adjoint functor is determined up to isomorphism if it exists). If we know that for each diagram D: I C there is a specified choice of limit in C, this leads to a canonical choice of the functor lim. If D is any object of [I, C] then lim D is the object of C arising from the specified limit (kj: lim D DI | J e I) of D in C. Now we shall define lim on morphisms of [I, C]; let a: D D' be any such morphism. Then there is a cone over D' with vertex lim D given by

when



certain form.



For

—?■

—?

—>

—>

[oli okr.limD and m:

so

-??

DI

->

D'l

\I el)

from the universal property of limits there is

lim D

k'j arising

—*

lim D' for which

from the

specified

k'j

o m



a/

limit of D' in



ki

C).



unique morphism

(the morphisms m. lim(a)

at every I el

We define



2.11.

93

Limits and Colimits

definition, let C be some category, 2 {0,1} be the discrete category with two objects and so A: C —> [2, C] is the functor which sends an object A of C to the constant diagram A on A of shape 2 and sends morphisms /: A —? A' of C to the natural transformation Af:A —? A' with components (A/)# /: A —? A' for each object B of C. Then C has binary To illustrate this





in

products just

the

case

For suppose that R:

functor

[2,C]

A has C is

—?■

right adjoint.



right adjoint



to A.

Take

objects



and C in

C, and define the functor F: 2

Then the

adjunction says we have a bijection between natural transformations F and morphisms h:A—* RF

a:

AA

—?■

a:

AA

C which takes 0 to B and 1 to C

—?



->

h:A-+RF and that the

is natural in A and F.

bijection

transformation A A

But to

give



natural

B and A C, and morphisms A so we see that the data amounts to a bijection between pairs of morphisms RF and the bijection is natural (/, g): (A, A) (B, C) and morphisms /i: A —y

F is to

give

two

—?

—?

in A and

—*

(B,C): h.A^RF

(f,g):(A,A)^(B,C)



h-.A^RF

Suppose

—?■

that



idRF corresponds

bijection:

to

U,g):{A,A)^(B,C) (kb^c)'- {RF, RF)

idRF: RF

(ttb, 7TC) (RF,7Tb,7Tc)



._.

->

(B,C)

—?

under the

RF

(idRF)A: (RF, RF)

(B, C)



binary product of B and C. To see this we need to show that if we are given f:A-+B and g: A C, there is a unique morphism h: A RF for which nsh / and nch g. Define h corresponding to (/, g) under the bijection, that is h {f,g). Then applying naturality in A at the RF we have morphism h: A Then

is



—?

—y







—>

idjip

idRF

°









**





id,RF

idRF

°

A/i

that is

(/, 9)



(fi 9)



(ttb, nc)



A/i



(ttb, ttc)



(/i, /i)

94

Chapter

h is

and

so

and

nch'

(/, g)

to





mediating morphism.

g for

an

To

see



uniqueness,

Category Theory Primer

nsh'

f correspond

suppose also

appropriate morphism h. Then both h and h!



bijection, implying h h'. We leave it to the reader to see binary products in C implies the existence of a right adjoint

under the

that existence of

2.



to A. Exercise 2.11.2

Work

the details of Discussion 2.11.1.

carefully through

category with specified limits for all diagrams D, verify that the canonical definition of lim: [I, C] —*■ C is a good one and that Urn is

particular, if C is

In

indeed



functor.



Examples 2.11.3

(1)

If I is



(small)

discrete category, then limits of shape I amount to

of set-indexed families of

product

in the

case

objects,

that I has two

and

correspond objects.

to the definition

products of binary

(2) Let I be the category 0

^1

which has

just two objects and two parallel non-identity morphisms. So a diagram of shape I in C is just a parallel pair of morphisms in C, say /, p: A —? B, and a cone over this diagram is a pair of morphisms

for which e:



—?

fe



e'

A for which



ge.

fe



But this is

just equivalent

ge; the e' is redundant. We

diagram: e







to

can

giving

draw





morphism

commutative

: B

9 Now suppose that this

cone

is



diagram f,g:A-+B. If we are which fh gh, then there must be

limit for the

given any other cone, say h: C —? A for a unique morphism k:C —> E such that h equaliser.

(3) Let I be the category









-2

ek.

So this limit is in fact

an

2.11.

95

Limits and Colimits

diagram of shape I in C is given by a pair of morphisms f:A-+C and g.B^C. A cone for this diagram is given by a triple of morphisms h, k and

so a

and



where



9 in which a

fh c gk; so specifying the morphism diagram of shape I is of course a pullback. =





is redundant. A limit for

(4) Suppose that I is the empty category. Then [I, C] is the category 1 which has one object (say D) and one morphism. In this case A:C [I,C] is the functor taking all objects of C to the unique object of 1 and all morphisms of C to the identity in 1. One can check that (A j D) is isomorphic to C and hence that a limit for D is a terminal object for C. —?

Exercise 2.11.4

Let I be the category : 1



-2

non-identity morphisms as shown in the diagram. Describe a limit for a diagram D:I—* Cat where Cat is the category of lattices and lattice homomorphisms. Prove that your description is indeed a limit. with three

objects

and three

The category C has colimits

DISCUSSION 2.11.5 A: C

[I, C]

has

adjoint, and we write Urn for A colimit for a diagram D: I C is an initial object in the under-cone category (D I A). Note that an object in the category (D J, A) is given by an object C in C together with a natural transformation k:D AC, that is a family of J in I C | I morphisms (kj: DI I) such that for each morphism a: I the following diagram commutes: —?



left

of shape I if the functor the left adjoint if it exists.

—*■

—?

—>

—?

DI

Da ?

DJ

C Such



family of morphisms is called

the definition

object

we see

Urn D of C

that



a cone

under D with vertex C.

diagram D:\ a family of morphisms (fcj: DI

colimit for the

together with

—>

C is —?

Unravelling given by an

Urn D



I G

I)

96

Chapter



2.

Category Theory

Primer

given any cone (hi: DI —> C \ I G I) under D with vertex C, there is a unique morphism m: lim D —? C satisfying mo ki hi for each object J of I. We sometimes refer to m as a mediating morphism. for which



Examples 2.11.6

(1)

If I is empty, then

(2)

If I is the discrete two



colimit of

I in C is

shape

object category,



an

initial

colimit of

object

shape

in C.

I is



binary

coproduct. (3)

A colimit

over

the category 0

is



coequaliser;

(4) Colimits

XI

compare this with the

over

original

definition of

coequaliser.

the category 2

-1

0 are

pushouts; again,

DISCUSSION 2.11.7

compare with the

Let C be



definition.

category and let D:I

by definition I is a small (left) adjoint in each of the following

recall that

and make

original

category. Let A: C cases;

we

C be

diagram; [I, C] have a right previous definitions

—?■



—>

summarise

some new ones:



If I is the empty category then C has



If I is the discrete two



object category,

terminal

(initial) object

then C has

binary products (coprod-

ucts). ?

If I has two

then ?

say that C has all

parallel pair of distinct non-identity morphisms, equalisers (coequalisers).



If I has three

common ?

we

objects and

objects, and two distinct non-identity morphisms target, then we say C has all pullbacks (pushouts).

If I is any finite discrete category, then

we

say that C has all

with

finite products

(coproducts). ?

If I is any small discrete category,

(coproducts).

we

say C has all small



products

2.11.



Limits and Colimits

If I is any finite category,

has all ?

97

finite

has all small limits

D:I

—?



say that C is small

we

(colimit)

specified

say that C has

we

or

complete (cocomplete)

or

(colimits).

canonical choice of limit

C then

finitely complete (cocomplete)

(colimits).

limits

If I is any small category,

If there is

say that C is

we

in

limits



category C for any diagram

(colimits).

Note also that the

having all small products as defined above is exactly the same as having products of set-indexed families of objects. The next theorem shows how limits can be built up from simpler categorical constructs: property of

Theorem 2.11.8

(i)

If



category C has all small products and equalisers then C has all small

limits.

(ii)

If C has all finite

(iii)

If C has

products

pullbacks and



and

equalisers

terminal

object

then C has all finite limits.

then C has all finite limits.

Proof

(i)

Let D: I

C be

—?



where I is

diagram



small category.

Consider the

products A * We define





and then

we



Ul oblDI

pair of morphisms

=f (vtarif) | / form the

morphisms (fcj



Df oki



see

I) —?■

e:









DI

7rioe





—*■



—*

by setting =f (Df

A of

El).

this, take f:I

Df

—?

and

equaliser

-Kje-.E

with vertex E. To

s, t: A

d^f UfemorlD(tar(f)).





7r5rc(/)

| /

I) family

of

a cone over



and t. Consider the

Then this

family

is

J in I and note that

7rfOtoe



7TfOsoe



7rjoe



kj

where ny: B —> D(tar(f)). This cone is in fact a limit for D. For suppose that (hi: C —?■ DI | J e I) is any other cone over D with vertex C. Then there is A and one can check morphism h (hi \ I G I): C using the existence property of an equaliser, there is k: C a

—>







e ?





h C

: B '

that sh —?



th. Thus

E for which

98

A Category Theory Primer

Chapter 2.

commutes.

Hence ek



implying that 717 o uniqueness of k follows from =

ek

required. The A. equaliser e: E as



hj that is kj







hj

the universal property of the

—?

(ii)

Proof

(iii)

We

exactly

as

for

(i)

with I finite.

products inductively from a terminal object (say 1) and binary products. But the binary product of A and B is given as the 1 and !#: B 1 where ! denotes a unique morphism. The pullback of \a- A B is given by the pullback equaliser of a pair of morphisms /, g: A can

define finite

—?

—>

—?



{ids, ids) -

(f,9)







(ii).

The result follows from

□ Lemma 2.11.9

limits of

I then

shape

Let D:I—*

Proof

the functor D is

Let

as a

C, I and 8 be three categories where I is small. If C has so

[8, C]

functor

be

[£,C]. a

D(—,E):I C D(I, +):£

—?



—?

C defined in

for each

—?



object

(k(E)r. Urn £>(-, E) be



limit of

then the

D(—, E)

family

(£>(/, e) forms

of



for each E. If

/ of I. Let

£>(/, E) \



we are

given



I G

I)

morphism

e:



—*

E' in £,

morphisms

Jfe(£)j

a cone over

of type I.

By currying, we can regard C, and for each object E of 8 there the expected manner, and similarly a

diagram

functor D: I

functor



does



£>(-, £)

Urn

D(—,E')

—>

£>(/, £7)

and hence there is



—?

D(I, Ef) \

morphism

I G

lim

I)

D(—,E)

—>

by, say, lim D(—, e). One can also check that the uniqueness properties of limits imply that the assignment + 1—? lim £)(—,+) gives rise to a functor lim D(—, +): 8 C, and that the family of morphisms k(E)j (as E runs over objects of 8) induces a natural transformation lim

D(—, E')

denoted

—?

*(+)/:

lim

£>(-, +)

-?

£>(/, +)

2.11.

Limits and Colimits

for each

object

99

J of I. In fact

(*(+)/: forms

a cone over

required

Urn

D(-, +)

/ G

family

I)

D(—,+)

and that this is the

limit.

functors may



It will be useful for

properties of functors

(for example) describe

we now

following definitions let F:C

to describe

some

properties that

—>



function

preserves and reflects order. The

based

are

£ be



We say that F preserves limits of

(kr.UmD D, the

us

enjoy. The reader will be familiar with the idea of

between posets which

for

£>(/, +) |

-?

the functor D with vertex Urn

Discussion 2.11.10

(i)

also check that the

one can

on

functor and I if

shape

-??

similar ideas.



DI



Throughout D:I->Ca diagram.

given



the

limit

el)

cone

{FkI:FlimD-^FDI\Iel) is

limit for FD.



(ii)

We say that F

reflects

limits of

I if

shape

given

any

cone

(Jfej:L->DJ| J l) in C for which the

then

(iii)

(ki:L

—*■

DI



(Fkf. FL I) is in fact

cone

/ G

-??



We say that F creates limits of



FDI

I G

I)

is



limit of FD: I

£,

-?

limit for D.

shape

I if

given

any limit

(k'j-.UmFD^ FDI\I el) for the over

diagram

FD: I

—?

D for which Urn FD

£, then there is =

FL and

The definition of F preserves,

kj

reflects



unique cone (&/: L —> DI \ I el) Fki and the cone is a limit for D. a

and creates

colimits of

shape

I is

similar and omitted.

Examples 2.11.11

(1)

Show that the definition of



functor which preserves limits of

shape

n,

finite discrete category with n G N objects, coincides with the definition of a functor which preserves finite products.

where



is



Chapter 2.

100

(2)



Category Theory

Primer

Let C and S be

Ap: [£,C]

—?



categories and let E be an object of S. Then the functor given by "evaluation at E" preserves any limits which exist in

[£,C]. forgetful functors on Qrp, Jb and Top to the category Set all preserve limits, but only the third preserves colimits. Here, Jb is the category of Abelian groups and homomorphisms, and Top is the category of topological spaces and topologically continuous functions.

(3)

The

(4)

Theorem 2.11.8 remains true if

has and F

preserves"

we

replace

every instance of "C has"

by

"C

in the statement of the theorem.

Discussion 2.11.12

In the remainder of this section

we

prove

some

results

categorical analogues of earlier results for preordered sets. We shall see that things are not quite as straightforward when preorders are replaced by categories. The basic aim of the results is to give conditions for the existence of a left adjoint of a given functor, and also to examine when a given

which

are

functor will preserve limits. The reader should compare Theorem 2.11.13 with Theorem 2.10.6, and Theorems 2.11.16 and 2.11.20 theorems" for

for

categories)

with Theorem 2.10.8

(which are "adjoint functor (the adjoint functor theorem

preorders).

Theorem 2.11.13

Suppose

that the functor G:S

Then G preserves all limits which exist in S.

Dually,

—?■

C has

if G has

a a

left

adjoint. right adjoint

then G preserves all colimits which exist in S.

Proof

exist.

We shall consider the result in two ways,

depending

on

what limits

Firstly,

Suppose

that C and S have all limits

pU]-^-[I,C] (i)

of shape

I. Consider the

diagrams

US] -£. [I,C] lim

(2)

lim

(F -\G), the functors F* and G* are given by postcomposition with F and G, and also (A H lim). Note that the diagram (1) commutes by dejfinition of the functors, and hence that (2) commutes up to isomorphism in which

we

have

using Corollary

2.10.22.

2.11.

Limits and Colimits

Now let D: I

S be

—?

101

given diagram with limit (ki: lim D



We have to show that

(Gki:G(limD)

(hi: A

be



GDI

—*

/ G

I)

GDI

—?■

GD in C.

a cone over



/ G

I)

is

DI





El).

limit in C.



Then the

—?

Let

of the

naturality

bijection associated with the adjunction (F H G) means that there is a cone DI | J J in I and note (hi: FA I). To see this, take a morphism /: / that hj [(GDf) o hi]A Df o hi. Hence there must be a unique morphism k: FA lim D for which ki o k hi for all objects / of I. This gives us a G lim D such that for all objects / of I, Gkiok hi. unique morphism k: A —?■

—?





—*



—?■



^ ̄

□ We shall need

couple of lemmas before proving



our

first

"adjoint functor

theorem." Lemma 2.11.14

C be

functor.

Suppose that S has and G preserves limits of shape I. Then for any object A of C, the under-cone category (A i G) has limits of shape I, and moreover the forgetful functor U: (A | G) Let G:£

—?



—>

S preserves them. Let D: I

Proof

D consists of over

this.

the

—>

(A [ G)

diagram of shape I. UD: I 8, together with be



diagram D diagram GD in C, say (hi'.A—* GDI \

(kf.

Let

hypothesis,







UmD

—?■



DI

limit for GD is

and hence there is



—?

/ G

I)

be



I G

I):

limit for the

given by the

—>

a cone

draw

see

that

with vertex A



sketch to

see

diagram D. Using the

(Gki: G lim D

cone

unique morphism k: A

It is easy to

—>

GDI

G Zzra .D for which the



I G

I)

diagram

GDI

commutes. We claim that the lim

object (k,

D)

of

(A [ G)

is



candidate for

D, that is, the family

(kr. (Jfe, {tm D) is

lim



take

->

(/i/, DI)\I



I)

limit for D. The verification of this is routine and omitted:

one

needs to

a cone

(h'i:(g,C)-+(hi,DI)\IeI) and

verify

ki

k'





that there is

h'j". (#, C)

—?■



unique morphism k': (g, C)

(fr/, £)/).

—?■

(k,

lim

D)

for which

That 17 preserves limits is immediate.



102

Chapter

Suppose

Lemma 2.11.15 an

initial

for every



2.

Category Theory Primer

locally small and complete. Then C has set of objects of C, say {Ax \ x G X}, such that B. is a morphism jx: Ax

that C is

object iff there is a object B of C there

—*■

Proof

(=¥>) Suppose set of

objects

C has

an

initial

{0}; {Ax | x

of C to be

(<=) Suppose that

object. Call the initial object

0 and take the

the result is immediate. G

X}

satisfies the

hypothesis. Consider the

morphism Jx^x-

^^x X-Ax

—?

Ax



JD

which exists

by completeness of C. Consider the diagram in C which consists of one object IIx x Ac together with all endomorphisms of the product; this is a small diagram because C is locally small. Now take the limit of this diagram B giving us a morphism I: L HxexAx and hence a morphism jx o wx o I: L B. for every object B of C. Suppose that there are two morphisms f,g:L We can form the equaliser e: B' L of / and g, note that there is a morphism B' and thus observe that lej'x7rx is an endomorphism of the j'x7rx: HxexAx product TLx xAx. As / is a cone over the diagram of all endomorphisms of idi using the UxexAx, we have / l(ej'x7rxl) which implies that ej'x7rxl universal property of the limit L. So e is split implying that / g. Hence L —?

—?

—?■

—?

—>







is initial.

Now

we

have the first of



our

results, known

as

Freyd's adjoint functor theorem.

Theorem 2.11.16

C where Suppose that we are given a functor G:£ S is locally small and complete. Then G has a left adjoint iff G preserves all small limits and for each object A of C there is a set of morphisms —*

{fx:A^GBx\xeX} morphism g:A—* GC there is which the diagram such that for any

GBX

—?

commutes. The condition which such solution set condition.

(jrhx a



morphism hx:Bx

—>

C for

GC

set of

morphisms satisfies is called the

2.11.

103

Limits and Colimits

Proof

(=>)

If G has

left



adjoint

then it preserves limits

using Theorem 2.11.13,

and the solution set condition holds because the unit t\a'- A in

(A I G) (<=)

for each

object

(A j G)

Note that the category

conditions of Lemma 2.11.15 and hence that

by appealing

to

GFA is initial

A of C. is small

(for

complete using Lemma 2.11.14. It is easy to verify done

—?

Proposition

(A j G)

S is

locally small)

and

that it satisfies the

has

an

initial

object.

We

are



2.10.17.

Set. The forgetful functor U:Qrp category of groups, Qrp, is locally small and complete, and U preserves all small limits. It remains to verify the solution set condition in order to use Theorem 2.11.16 to see the existence of a left adjoint to U. But if we are given any Example 2.11.17

function g: A

—?

Consider the

UG where A is



—>

set and G is



group, note that this function

UG where (im(G)) is the through the inclusion i: U(im(G)) subgroup of G generated by the image {g(a) \ a G A} of A in UG. Note that the cardinality of (im(G)) is less than \u\ x \A\ and that up to isomorphism there is only a set of groups of any given cardinality; in particular note that the cardinal number \lj\ x \A\ is independent of the group G. As G runs over all factors

—?■

groups, the collection of groups

gives H

rise to



runs over a

(im(g))

as



runs over

the functions A

UG

UH, where isomorphism classes. The set of functions A of representatives, satisfies the solution set condition.

set of set

—?

—?■

subobject of an object A of C is a monic A' A. We write Sub(A) for the category of subobjects which is defined to be the full subcategory of the slice C/A whose objects are the subobjects of A. Note that Sub(A) is a preorder; if the diagram Discussion 2.11.18

Given



category C,



>—*

implies that / g. We say that a category C is well powered if Sub (A) is equivalent to a small category for each object A of C. Note that Set is well powered, for each monic B A is isomorphic to an inclusion A' C A, and there is only a set of such inclusions, that is a set of subsets of A. The same is true for the categories Qrp and Top of groups and topological spaces.

commutes,

then



monic



>—*

104

Chapter

2.



Category Theory

Primer

category C, we call a collection of objects O of C a coseparating collection if for any parallel pair of morphisms /, g: A —?■ B in C with / not Given



equal to g there is an object O of O and morphism fr/ is not equal to hg. With this, after

one

we can now

state and prove the

h:B

—?

special adjoint

O of C for which

functor theorem

final lemma.

Lemma 2.11.19

Let



functor F: C

£ preserve any

pullbacks

which exist

in C. Then F preserves monies.

Proof

Let

morphisms

m:



>—>

B be



of £ for which Fm

monic







Fm



/, g: C monic implies

in C and let

morphism

g. That



is

—>

FA be

id &

id,



B m

is



this

image under F is a pullback by hypothesis, and using that there is a unique factorisation of both / and g through id fa,

pullback we see

implying f



in C. The



g.

Suppose that the category £ is locally small and complete, well powered, and has a coseparating set. Suppose also that C is a locally Theorem 2.11.20

small category. Then any functor G:£ has



left

—>

C which preserves all small limits

adjoint.

{Ei | i G /} be a coseparating set for £, and write F for the set \J{C(X, GEi) \ i £ 1} indexing the morphisms GEi in C for all i £ I. Set S /: X Ilf^pEi. G preserves the product 5 PROOF

First, fix

an

object

X of C. Let

—?

and

so



the set F induces



unique morphism 9: X

—>

GS for which the

diagram



S there may be some Among the subobjects S' GS. Note that the latter morphism is through GS'

commutes. factors

>—?

>—*

for which 9 a

monic

by

2.11.

Limits and Colimits

105

appealing to Lemma 2.11.19. Hence there can be at most one factorisation of 9 through GS' GS. Pick a representative set, say {mp: Sp S | /? G B}, of subobjects of S for which this factorisation exists, and write fp: X GSp o for the mediating morphism (so 9 Gmp fp). >—*

>—?

—?■



By completeness the

of

£,

take the limit of the

we

object S and the morphisms Sp .



G preserves this

following diagram

def =

limit, and



Oo

so



S,

>—?

rip

Sp



there is



diagram

which consists of

say



rnp



£>?

unique morphism k making the

commute:

(1)

We shall aim to prove that k: X

(X i G). Suppose H \J{S(Y,Ei) | i =

that e

I},

g:X

—?

—?

GSo

is initial in the under-cone

GY is another

and set T



Ti.heHEi.

object

in

category

(X J, G).

Then there is



Set

morphism

T for which ^ o cj> h. It is easy to check that <f> is indeed a monic <f>:Y morphism using the fact that {E{ | i G /} is a coseparating set. Noting also that Gh o g: X T G£"i is in F, then we can form the morphism ^: 5 for which 7r^ o i\) irchog- Finally note that G preserves the limit (product) Ff | /i G H) and so there is a unique morphism fc making (7Tfc: T >->



—>

—?■



—>

commute.

In fact

calculation is

we can

omitted).

check that k

Form the limit



G<f>



g and fc



Gi\)





(the

easy

106

Chapter



2.

Category Theory

Primer

again using the fact that G preserves limits, together with the fact that G(f> o g Gip o 0, we have and

once





where

fp

implying

exists because

(*)

that np:So

P exists—see

>—>



pullback



square, and hence P G

(1).

Hence

we

{S@ \ (3

B}

have the existence of



(g, Y) where to see this one needs to check that fp (unique) mediating morphism for the diagram above. It remains to see

morphism ip'np: (k, So) is

is

—>

ip'np is unique. Suppose form the equaliser diagram

that



which leads to another

there

are

r .

two such

S0



equaliser diagram GL

Gr

GSo





morphisms,

p and q. Then

: Y

G preserves limits:

as

Gp

! GY





mediating morphism e exists by appeal to the definition of p and q. Hence we have 0 5, Gj o k G(jr) o e, that is L {5/3 \ /3 B} via jr: L and so from the construction of So there is a morphism n^. So £ for which J {Jr)nL- But 7 is monic so ids0 r^L? and thus idi, njjr because r too is monic. Thus Sq L implying p □ q. The



>—?



>—?









£.i#

Strict Indexed

Discussion 2.12.1



We

Categories

begin

categories. Strictly speaking, what

this section with we

shall call

an



discussion of indexed

indexed category should

more

2.12.

107

Categories

Strict Indexed

properly be described as a strict indexed category; we shall ask that certain diagrams commute up to strict equality, whereas these diagrams are traditionally only required to commute up to (canonical) isomorphism. Let Cat be the category of small categories and functors. Then a C-indexed category C is by definition



functor C'.C09

—?

indexing collection;

form of

category CI. The

Cat.

so

One should think of the category C

each

/ of C is

object

category C is usually referred

to

as

an

"index" for

the base

as a



of the C-indexed

given an object / of C, the category CI is called the fibre of C at /. Not surprisingly, we can perform the game of defining notions of functor and natural transformation between indexed categories. Before doing this, we remark that if /: J —?■ / is a morphism of C, then we shall write /* for category

C,

the functor

and

C/,

that is

/*



Cf:CI

—?

C J. The functors

/*

are

known

as

remdamg functors. Now

we

define

functor between indexed



categories. Let C and D be

C-indexed a:C

—?

categories. Then a C-indexed functor a is a natural transformation D; thus by definition, for any morphism /: J —> / in C, the diagram CI

<*i

BI





CJ

BJ <*j

commutes. We sometimes say commute with the D: C09

—?

Next

Suppose

(informally)

reindexing functors,

and

that the component functors

we

shall sometimes write a:C

—?

Cat to denote the above data. we can

define

that both





natural transformation between C-indexed functors.

and a'

categories C and D. Then

are

C-indexed functors between the C-indexed

transformation 8: a. —? a! is given by a natural transformation <¥/: a/ a'j for each object / of C for which / in C the diagram given any morphism /: J a

C-indexed natural —?■

—?

a/ CI



18! 4

BI

\r

(*)

<*J CJ

18J

DJ



commutes, which is We refer to the

to say that for each

commuting

square

(*)

as

f:J

—>



we

have

(<¥j)/?

the intreid condition.

/*<¥/? is just



This

108

Chapter



2.

Category Theory

saying (by definition—refer to page 51) that for each object A of CI

(6j)fA

f*((8i)A),



Primer

we

have

where

Application of functor /* to the morphism (8i)a

/*(

(Sj)fA

Vi)a)

Component

Component of the

the natural

natural transformation

6j

at

So

far,

81

we

at A

discussion has revolved around the notion of indexed

functors and natural C. Now

transformation

f*A our

of

transformations, C,

a,

6,

relative to



categories,

fixed base category

shall consider the situation where the base category is allowed to

tidy, we shall actually define a new category IJCat. An object of UCat is given by a functor C: C0? Cat where C is any category, that is the objects of UCat are indexed categories. Then given any D in UCat is given other indexed category D:Z>op Cat, a morphism C V is a functor and a is a C-indexed functor by a pair (a, F) where F: C a:C DF^; we can draw a diagram thus: To make

change.

our

definitions

—?

—?

—?

—?

—?



Cop

that

Cat

D given morphisms (a, F):C Then the composition of (a, F) and (a', F') is given by

Suppose

we are

—?

(a7, F')(a, F)



(a'F o a, F'F)





-?

and

(a', F'):B

—?■

E.

E.

object C is given by (idc, idc) where of course a component of idc '■ C C at any object / of C is the identity functor idci on the fibre CI, and idc is the identity functor on the category C. The

identity morphism

at

an

—?

We

can

now

mimic the definition of



functor category in the indexed

setting. Let C and D be C-indexed and XMndexed categories respectively.

2.12.

Strict Indexed

109

Categories

[C,D]

objects of [C,D] are D. Then given another object morphisms of indexed categories (a, F):C (o/, F'), a morphism (<5,x): (a, F) —> (a', F') in the category [C,D] is given by a natural transformation \: F Fr, and a C-indexed natural transformation

We shall define

category

a new

follows. The

as

—*■

 ̄¥



Such



requires

: a —

6 is often referred to



(X(-)) V as

(X(-))*Q:/: C

—?■

explanation. The B)Fop at an object / CI

where of

course

DF/. Let

(6, X)

perhaps

of C is

given by the composition of functors BFI def

morphism of V and Xj DixiY-^F'I define composition in the category [C,D]. Take morphisms

Xi'FI

us now



The notation

component of the natural transformation

-^L BF'I -^*

F'l is

DF0?.



modification.



word of





(a, F)



—*■



—?■



(a', F')

(6\ X') (<*', F')

and



(a", F").



We set

(S',X'MX) Once

again,



((X(-))^(-) °*(-),x'x) (a,*1) :



word of

object

(a",^")-

explanation about notation is in order. The component

of the C-indexed natural transformation an



(x(-))*#_) 8^-y.a o

(x'X(-))*a"

—?

/ of C is given by the composition of natural transformations °I

?/



X*I<*I





Xi<*i

We have to check that this is well the intreid condition

we



defined,

(diagram (*))

morphism of C and then



/*

//

XiXi a/

def =

that is the

//>.*//

(X x)/?/-

appropriate

holds—see page 107. So let

/:

instance of



—?

/ be

have:

(x*j6'jo8j)f. <¥ tf((O/0o(*j)/. (*)for8f



(*)for8



functorial



transformation



(-)* X'-F

-+

F' is



natural

(-)* (F/)* The

at

identity morphism

at

is

zs

functorial



/unctor



25 a

(a, F)

is

given by (tda

x}((F'f)%)o(6j)f. x5((F7)*^)



(F'f o *j)*# (xj



Ff)*8j

{Ff)*x*A

°

(F/)*(x^ ,

zd^).





(F/)^/ (F/)*<57

(F/)*<5/

(F/)*?5j



fc).



110

Chapter

Category Theory



Exercise 2.12.2

calculations which

definitions of

in the

sense.

Verify the above composition of morphisms

2.

Also check that the definitions of

ensure

that

Primer

our

categories TZat and [C, D ] make

identity

are

good.

discussing categorical models of type theories in later chapters, we shall not only wish to talk about equivalences of categories, but also of indexed categories. We shall now define the notion of equivalence of indexed categories and then prove a little proposition which shows that what is a slightly unwieldy notion in fact amounts to a very simple idea. So let C Discussion 2.12.3

be



When

C-indexed category and D be

that C is

equivalent

to

D,

written C

(a, F) in USZat such that there

We shall

are

£>-indexed category; then







D, if there

C =L.B



are

shall say

we

morphisms

(/?, G)

isomorphisms

(a,F)(/?,G)^(*dD,*<*2>)

in

P,D],

{P,G)(a,F)^(idc,idc)

in

[C,C].

investigate this definition by proving the following proposition.

Proposition 2.12.4

Let C be

indexed category, for which there is

categories C and I oiC, that is



are

equivalent,

C ̄V

Let

Unravelling

definitions,

the

in the category

an

as are

equivalence C

and



(M-1)



(0Foa,GF)^>(idc,idc)

(p, tj)



(idc, idc)

[C, C ]

D.

Then the base an

object

CI  ̄BFI.

isomorphism (/?,G)(a,F) given morphisms

we are



the fibres CI and DF/ at

consider the

PROOF

us

C-indexed category and let D beaP-



—?

(Pf

°

a,

(idc, idc)-

GF)

for which

(^,r7_1)(p,r7) =f ((t7(-))*^(-) P(-),V ̄1'n) °



(^fdC(_}, ^fdc),

(1)

(?*(/?Foa)(_), idGF).

(2)

and

(P^XM"1)

=f

([to_1)(-)]V(-) <¥(_), TW"1) °



2.12.

This

that

means

1ry

have 77

we

GF

111

Categories

Strict Indexed

T1



and

idc





and r\r\

idac



idcF where

F :C

^=1 V





V that is GF



idc- If we apply a similar procedure to

concerning the isomorphism in [D,D], which,

can

say, is witnessed



(aG

(^e-1)



(id?,idv)—>(aGop, FG),



/?, FG)



idx>, and thus

also deduce from

(1)

(2)

and

tftii0 Pi

—?

have C

we





that if / is



proposition

by morphisms

(id?, idv),

(/z, e)

it will follow that FG

We

the data in the

an

as

required.

object of C, then

idida

(3)

id0Fioocr

(4)

and

(?7 ̄1)/P/ Note that the second of these Pi

&i

°



equations implies that °

vfi^i



(5)

idrifofojoaj,

where

idCi

Pi

Z=^

rfj



(3FI



a/

and a7

Now

we are

Firstly,

in



note that

position

(3)

and



to

CI ^=1 OF/ see



77J



/3F/.

that the fibres CI and DF/

(5) imply

We will have shown that C/  ̄DF7 if

we can

(6)

also prove

(7)

a/o(?7Jo0F/)SuiDFJ. see

for the where

(7),

note that

by following



equivalent.

that

{ri*iopFI)oaI*idci.

To

are

similar argument to the

one

just given, but

isomorphism in [D,D], we can also deduce that id?j (e ̄l)*j°oi.Gjo(3j, J is an object of V, this latter equation being an analogue of (6). Thus =

id?Fi



{^Yfi

°

aGFi

°

Pfi-

112

Chapter

The base

categories





have

we



(Ft//)*



aGF/



pFI.

(8)

just need to note that the following diagram commutes, where

using naturality

of

at / in 777: /



CI

BFI



(FtjiY

CGFI



(*GFI

diagram together

we are

GFI:

—?



This

Primer

equivalent, and thus (F H G), and we use that epi o Frji idpi- This implies (e ̄l)pi Frji, and idDFI

Now

Category Theory



are

Proposition 2.10.25 to deduce so we

2.

(8) implies (7),

with

BFGFI

as



required.

Verify that (5) holds, which is a very simple exercise using the definitions. Derive also the analogue of (6). Make sure you understand the essence of the proof. Exercise 2.12.5

This discussion is devoted to

Discussion 2.12.6

categorical

construction which is

Recall the category Cat of small

and suppose that F:C construction builds

—?

objects

are

categories

Cat is



G(F) G(F)

category



functor jP. In the category ?

(among

pairs (C, A) where C is

many

and

an



description

others)

of



The

functor

object

certain

due to Grothendieck.

functors, introduced on

functor. and



(covariant) 7i>: G(F)

an

83,

Grothendieck C out of the

—?

of C and A is

page

object

of

FC,

and

morphism (C, A) (C, A') is a pair (u, f) where of C and /: Fu{A) A! is a morphism of FC. ?

u:

—>





—?

C is



morphism

—?

It is clear what identities in

G(F)

like, and composition is more or less as expected. To be clear, if we are given morphisms (it, /): (C, A) —> (C, A') and (v,g): (C',Af) —> {C",A") in G(F), then the composition is given by look

(v,9)o(u,f)^(vu,goFv(f)) The functor 7i>:

G(F)

(u, f) The from

(contravariant) a



—?■

C is

(C, A)



(C,A)



given by the assignment —>

(C, A')

K^





Grothendieck construction builds

functor F-.C09

—?

(C",A").

Cai. In the category

G(F)

C a



C".

functor 7i>:

G(F)

—?■



Further Exercises

2.13.



objects

113

pairs (C, A) where C is

are

object

an

of C and A is

an

object of FC,

and

morphism (C, A) (C, A7) is a pair (u, f) where of C and f:A—* Fu(Af) is a morphism of FC. ?

G(F) really

It is easy to check that

ant)

is





u:

—?



category in the

C" is

—?■

case

(contravari- C is up'- G(jP)

of the

Grothendieck construction, and the projection functor

again given by "projection We shall make

use

morphism



—?■

to the first coordinate."

of the Grothendieck construction in later

chapters when

give domain-theoretic models of certain polymorphic type theories. We remark that the construction will also apply (by analogy) to a functor F:C —?

we

V where V is poset

as a

we

regard

each

category. Let C be

Exercise 2.12.7

regarding

of the category VOSet where

subcategory

some

every set

as a



category and F: C

Set

—?■

discrete category and every function



functor.

as a

By

functor between

categories, use the Yoneda lemma to prove that (H j F)09 and G(F) equivalent categories, where H: C09 —?■ [C, Set] is the Yoneda embedding.

such

Further Exercises

2.13 (1)

Let S be the category of non-empty sets and set functions. Define

V: S

—?



by sending /: X

V(f): V{X) Show that there is

(2) (a)

are

Let F: C

no



V{Y)



f(A) ^ {/(a) |



natural transformation

a:



—?

£ be functors.

-??

that F,G:C

£>

—?

are

functors which





.4}.

ids-

Show that F is faithful if

GF is faithful. Show also that if GF is full and G

(b) Suppose

functor

Y in <S to the function

—>

V and G: V

-??



faithful,

are

then F is full.

naturally isomorphic.

Show that F is full iff G is full and that F is faithful iff G is faithful.

(c) Suppose

that F: C

naturally isomorphic

(3)

to

Let X and Y be

—>

V and G: V

—?



are

idc- Show that F is faithful.

dcpos, Yj_

order ± < y, and ?/ <

have

{[y] | y [y'\ (so informally Yj_

underlying

[y] < element added, and is also a dcpo). Let i: Y given by 2(3/) [y]. Let J(.D) mean the set y'

iff



regarded

{idx



as a

functors and that GF is

—?

set



Y}



{_L}

is Y with



with least

Y± be the continuous function

of inductive subsets of



dcpo



category, and consider the functor

z)-1 :1(X



Y±)

—>

I(X



Y)



*-+

{(x, y)

e X x Y

| (x, [y])



/}.

114

Chapter

(idx

Check that



i)-1

adjoints, giving explicit

(4)

Show that the

2.



Primer

Category Theory

is well denned. Show that it has both left and

right

formulae for their definitions. of

pushout

epic morphism More precisely, show that given morphisms e:A an

is another -?

B and

epic morphism.

g:A

C in

—?



category for which the pushout exists, then the pushout is of the form

h C

(5)

Show that

(6)

Show that the category

e'

projections for binary products are not necessarily epic and that insertions for binary coproducts are not necessarily monic. C, is

[C^^et],

known

cartesian closed category which has



exponentials F => G: Cop

in

[C^^Set] tricky

to construct.

as

the category of

pullbacks. If' F,G:Cop

Set exists, apply the Yoneda lemma to F

—?

the

definition of

(7)

Let C be

cartesian closure

Set, suppose that G, and think about

—*■

=>

of [C^, Set].

category for which



Hint:

presheaves on you may find

every slice is



cartesian closed category.

Show that the slice of any slice is cartesian closed. Show also that every slice of C has finite limits. Hint:

(8)

In this exercise

we

Theorem 2.11.8 part

use

(ii).

show how to construct limits and colimits in the category

Set.

(a)

Let I be



small category and jD: I

set of families of the form ?

x/ G



if

Define

—*■



J is



(717:

We define



Urn D

there is at least



for any



—?■

for any

hf



hg.

—?

—*■



functor. Write Ivm D for the

such that

DI



DI for each I G

filtered category



and B

I)

morphism of I then Da(xi)

function 717: Urn D

Prove that

(b)

/ G

Set

DI, and I

a:

(xj |

—?

one

object

in

I)

is



C to be



xj.

object

/ of I

limit for the a

by (xj | / diagram D.



I)

?—>

xj.

category for which

C;

C objects A and B of C there is an object C, and morphisms A C, and C loi which morphisms f,g:A^>B'mC there is a morphism h:B —?



Further Exercises

2.13.

Thus filteredness is the some

115

categorical analogue

(of a poset):

of directedness

of the definition. Now let I be small and filtered and D: I

diagrams

functor. Let U be the



—?

Set

the

objects of I; formally U ob I x \J{DI \ I G I}. Define a relation on U by asking that K, (/,x) (J,y) just in case there is an object K oil and morphisms a:I is an equivalence (3:J-+K for which Da(x) Dfi(y) in DK. Prove that relation. Set lim D lim D by x ■-?■ [x] U/ and define a function Lf. DI a

disjoint

draw

union of the sets DI

as

runs over



—?■







where





—>



(tj: £>/

G .D/. Prove that

—?

lim D  ̄*



I)

I G

is

(filtered)



colimit for

D.

(c)

Let jD: I

?Sei be

diagram. Again let 17 be the disjoint union of the DI and define a relation R on U by asking that (/, x)R(J, y) just in case there is a morphism a:/ be the equivalence J in I for which y Da(x). Let &ra D map relation generated by R, write lim D U/  ̄, and let ij: DI elements to their equivalence classes as in (b). Prove that this gives rise to a —?



—?





—?■



colimit for D.

(9)

Let C be

category and O





class of

objects

of C. The category C is said to

be balanced if every

morphism which is both monic and epic is an isomorphism. B in C with / ^ g, We say that O is a separating class for C if given /, g: A then there is some O in O and h: O A for which fh ^ pfr. We say that O is a detecting class if given any morphism /: A .B in C for which given B factors uniquely through /, then / is an any O in O each morphism O isomorphism. —*■

—?

—?

-+

(a)

If C is

balanced, show that any separating class is

(b)

If C has all

show that any

equalisers,

(10) Suppose that F:C (F H G) with unit r] and

—>

following (a) Ft]a (b)

conditions

is

(c) GepA is (d) GFrjA

an

we are



separating class.

given

an

adjunction

of C. Prove that the

object

for all

A, and

r\GFA for all A. more

prove that your four

themselves to conditions Let C be

Define,

Let A be

isomorphism for all A,

Formulate four

(11)

e.

C, and

class is

class.

equivalent:

isomorphism

an



counit

—>

detecting

isomorphism for all A,

an

6fa is an

are

V and G: V

detecting





for each

conditions which

new

(a)

conditions

to

are

are

dual to the above conditions, and

equivalent.

Are

(d)?

cartesian closed category and T:C

object

they equivalent

C of C,

an

endofunctor C



—?■

C any endofunctor.

T(-)

on



by sending

116

Chapter

f:A-+Bto idc

Tf: C



TA



—>





TB. Define



T(C x —). Suppose also that there is a natural T(C x —) for each C, for which the diagram 1 x TQ

2.

'n

—--T(l

Category Theory

similarly

an

Primer

endofunctor

transformation rc: C



T(—)

—>

f2)



T7Tfi Tf2 commutes, where a

morphism

a:

1 is the

TO,

—?

(specified)

terminal

0, in C. Consider the

(FPOl) Given any morphism f:TA A for which the diagram /: Q,

object of C. Finally, following: C, there is

A in

—?■



let there be

unique morphism

—>



TQ



Tf TA



commutes.

(FP02) is



Given any

object C of C, unique morphism /: C x Q

—>

A in

C, there

(FP02)

holds of

morphism /: C x TA for which the diagram

and A

CxTQ

z^c

x a

-Cx f2

<7rc,T7oT£}|

/ /

commutes. Prove that

property

(FPOl)

holds of C

just

in

case

property

C.

(12) (a)

Let X be

x A

-\y

(b)

Recall





Boolean lattice. Prove that for x,y E. X

we

have



< y

iff

_L.

Proposition 1.4.8 which says that every Boolean lattice X is a Heyt- ing lattice. Use this result, along with Theorem 2.10.6, to deduce that for any x G X, the monotone function xA(-):X->X preserves all joins in X.

(c)

111

Further Exercises

2.13.

Let X be Boolean lattice.

not bottom

and)

for all

X* for the set of atoms of X. We call non-bottom element



We show that

V(X*)

two functions

by

X for any









complete



V(X*)



h->

{a

jjj



V(X*)—>X



h-

\/S.

(pip

show that

monotone. Use

(a)

then



atom if







(it

is

We write

a.

given

any

x.

atomic Boolean lattice X. Define



are

an

for which



—>

G X

Boolean lattice atomic if

atom

an





<p

See that <p and ^

(d) If 5 (e) The

X, there is



element

an

X, whenever _L ^





We call



G X*

ipcp

to show that







x}

idx- Use (b)

to

id-p^x*)-



is any set, what

the atoms of

are

category CAtBCat has

objects

V(S)7

the

Show that S

complete



(P(S))*.

atomic Boolean lattices

morphisms those functions which preserve all meets CAtBCat Set01', making use of the above results. and

and

joins. Prove that



(13)

object E of £ is above an object / of B if 7TE1 a. A /. A morphism / of £ is a6ove a morphism a of B if 7r/ morphism in £ above an identity in B is said to be vertical Every object / of B determines a category £(I) consisting of the objects above / and vertical B at /. morphisms, called the fibre of ir: £ Let

7r :



—?■

B be any functor. An





—?■



morphism c:E



£ is cartesian if

given any morphism 7 in B with c above 7 and any morphism f:E'-+C'm£ with 7r/ 7 o /? in B, then there E m £ above j3 with / is a unique morphism g:E' eg. -+







The functor

7r:



—?

B is





fibration

if for every

C oi £ and

object

morphism

C above 7. We call c morphism c:E a cartesian lifting of 7. Given any object C of £, write 7:7*(C) C for the cartesian lifting of 7. A choice of 7 for each 7: / 7rC is called a cleavage. A fibration equipped with a given cleavage is called a cloven fibration.

7: /

—?

7rC in

Z3, there is



cartesian

-+

—?

—>

(a)

Let Tarn be the category with

objects (Ai \ i G /) indexed families of sets, (Bj | j G J) is given by a function a.I-^J

morphism /: (Ai \ i G /) together with a family of functions and



Let

7r:

—>

Jom

—?■

<Se£ be the functor

have the obvious definition

(i)

Given



[I, Set].

set

on

mapping (Ai \ morphisms.

/, verify that the fibre Fam(I)

i G

is

/)

to

(the set)

equivalent

/ and let

to the



category

118

(ii) Verify

that



is

Primer

morphism if each fi is an isomorphism. / essentially performs a pure reindexing of sets.

Think

Prove that the functor

sets is

7r:

Tarn

—?■

—?

and cartesian

(a/3)*

(i)

7r:



indexing

fibration.



—?

Let



Set which maps families to their

B be a cloven fibration. (b) Let 7r: S / in B. Hint: S(J) for every a: J

(c)

2.

cartesian



about the fact that

(iii)

Category Theory

Chapter



think about the



functor a*:

£(I)

—*■

definitions of fibration

lifting.

—*■

B be



a*/?*, where

Formulate

Show that there is



cloven fibration.

a:



/ and

—?■



(3:K

split if id} idgy) and morphisms of S.

is said to be

-+



are



morphism between split fibrations by thinking about preserve cleavages. Hence define the category STib of split

notion of

functors which

fibrations.

(ii)

Prove that the Grothendieck construction

C: C°p

(iii)

->

Cat

produces

Hence prove that the

2.14

split fibration



G(C)

categories SHb and UCat

->

to

an

indexed category

C.

are

equivalent.

Pointers to the Literature

We

begin by describing some concepts of category theory can and natural transformation

[EM42]

ir:

applied

[EM45].

and

of the research papers in which the

be found. The first notions of category, functor

were

introduced

The idea that

by Eilenberg and cartesian products are an

[Mac48] and [Mac50]. adjunction appear in [Bou48] in which

Mac Lane in instance of

form of universal property first appears in

The

ideas for the concept of



of "universal construction"

original

can

be found.



primeval description

However, there does not

seem

to

explicit definition of adjunction until Kan's paper [Kan58]. The categorical form of the adjoint functor theorem is due to Freyd and appears in his [Fre64]. The general description of limit can also be found in Kan's [Kan58], but the underlying ideas had been studied before 1958, and mathematicians had worked implicitly with particular kinds of limit. have been

Now in

an

we move on

alphabetical

to



description

order of authors.

of useful textbooks.

Our first reference is in

These some

are

given

respects



(in content rather than style) to "Categories Types," namely Asperti and Longo's text [AL91]. Most of our Chapter 2

book which bears resemblance for

Asperti and Longo. Material on internal category theory can be found in Asperti and Longo, which is highly relevant to a complete understanding of models of polymorphism, and this material is not covered in "Categories for Types." Most of the ideas of basic category theory appears in the first half of

2.14-

Pointers to the Literature

be found in the book

[BW90] by

119

Wells, along with a few more advanced topics. Much of the content of Chapter 2 of "Categories for Types"

can

appears in

[BW90],

Barr and

but Barr and Wells present the material with

more

background discussion and at a slower pace. It is a textbook aimed at advanced undergraduates and early postgraduates, and is a book solely concerned with category theory. What still remains a classic reference for category theory is Mac Lanes's [Mac71]. This graduate textbook covers much of the general category theory used by computer scientists; published in 1971 it never mentions computer science as a discipline and its examples are from mainstream mathematics, but it remains an excellent textbook. Material is covered at a moderate to fast pace. Our Chapter 2 is much like a distilled version of the first four chapters of [Mac71]. McLarty's [McL91] covers much of our Chapter 2, excluding the Yoneda lemma. McLarty also covers some of the underlying foundational questions which arise in category theory, as well as basic topos theory. This book is written with logicians in mind, and so it should also appeal to computer scientists. The book [Pie91] by Pierce is an elementary introduction to category theory written for an audience of computer scientists. The contents are similar to our Chapter 2.

Algebraic Type Theory



Introduction

3.1

The fundamental idea of

DISCUSSION 3.1.1 provide



formal framework for

algebraic type theory is to reasoning using the usual rules of equality. Simple

algebraic type theory is far removed from the syntax and rules of real programming languages, but it is a good starting point from which to motivate and explain the ideas of categorical semantics. To a first approximation, algebraic type theory involves three entities, which will be called types, terms and equations. Think of

property, and

type



an

as a

equation

collection of items

as a

judgement

(terms) having

that any two items

some common

(terms)

are

essentially the same. We aim to define the notion of a theory in algebraic type theory. Recall that the general idea of a theory is that one has some basic assumptions, usually referred to as axioms, and some rules for deducing theorems from the axioms. Thus a theory in algebraic type theory consists of a given collection of types, terms and equations, where the equations are the axioms of the theory. The theorems are the equations which one is able to deduce from the axioms using the rules of algebraic type theory. These rules say that equations may be manipulated according to the rules of reflexivity, transitivity and symmetry. So, for example, if a term t equals a term 5, then we may deduce that the term s equals the term t, and this is the idea of symmetry. Let

informal summary of

begin by defining the syntax of algebraic type theory. This syntax will be presented using a collection of formal rules, much as we describe the syntax of any programming language. The syntax is based on a given collection of types and function symbols, known as a signature. For example, a signature for the syntax of arithmetic might have a type of natural numbers, and function symbols which us now

give

play the role of and returns

an

zero

zero),

(thought

of

as



Chapter

3. We

function which takes any argument

function, and primitive recursion. Next we show how to define an algebraic theory. We describe the syntactic form of an equation in an algebraic theory, and how to derive theorems from given axioms. This completes the syntactic presentation of algebraic theories, and so we move on to consider semantics. After reviewing traditional set-theoretic semantics, in which types are interpreted as sets and terms as elements of sets

(for example,

the

in the

successor

syntax for arithmetic, the type of natural numbers might

Definition of

3.2.

interpreted

be

and

so

on),

we

the

the set N of natural

as

fact

for this purpose is of

numbers, the constant

zero as

0 G N

categorical semantics for algebraic theories. In this interpreted as objects in a category and terms are interpreted

describe

setting, types are as morphisms. In

121

Syntax





we

shall

see

that the kind of category which is suitable

category with finite products. We give

some

examples

categories for interpreting the theories. A model of an algebraic theory is an interpretation of the terms in a category with finite products, in which the morphisms interpreting the terms t and s t are equal morphisms in the category. We prove a appearing in an axiom s soundness result, which says that if we are given a model of an algebraic theory, and 5 t is now a theorem derived from the axioms of the theory, then the morphisms interpreting s and t are indeed equal. We then show that for each algebraic theory Th we can construct a category Cl(Th) with finite products

algebraic

theories and suitable





out of the

syntax of the theory, and that there is

category.

Further,

we



model of the

show that every category with finite

theory in this products C gives mutually inverse

algebraic theory Th(C). These two processes are (for example there is an equivalence of categories C Cl(Th(C))). It is for this reason that we can regard algebraic theories and categories with finite products as "essentially the same" and moreover think of a category with finite products as a syntax free presentation of an algebraic theory. The study of relationships of this kind is known as categorical type theory: rise to

an



I—

Categorical Type Theory

Type Theory



Th





{Th(C) Th(Cl(Th))

Definition of

Category Theory



Cl(Th{C))

3.2

Cl(Th))



the





C Th

Syntax

algebraic signature for algebraic type theory. Think of an algebraic signature as specifying some basic data from which we will build types and terms. An algebraic signature, Sg, is specified by Discussion 3.2.1





We define the notion of

collection of types,

122





Algebraic Type Theory

Chapters.

collection of function

number

(possibly 0),

symbols

each of which has

an

arity which is



natural

and

sorting for each function symbol / which is a list of a + 1 types (say [ax,..., aa, a]) and will be written /: ai,..., aa —*■ a, where a is the arity of /. In the case that a function symbol k has arity 0, we shall write the sorting of A: as A;: a, and refer to fc as a constant function symbol. ?



be a function simplify notation, we will often write "let /: al5..., aa symbol" from which it will be implicit that / is the actual function symbol, that / has arity a, and the sorting of / is (formally) the list [a\,... ,aa,a]. We assume that we are given a countably infinite stock of variables, say Var {x, y,...}. The raw terms are then given by the following BNF grammar: To

—?■







::=







| f(M, ...,M). length

Here



variable, k any constant function symbol, and / symbol of non-zero arity a. x

is any

is any function

Note that the sorting of a function symbol does not play a role in the definition of the raw terms. One should think of the raw terms as Remark 3.2.2

expressions in



programming language which

DISCUSSION 3.2.3

Informally,

think of the

are

raw

not

necessarily

terms in the

well

typed.

following

ways:

(!),





is



variable



k is



language constant,



/(Mi,..., Ma)

is

Examples 3.2.4

an

and

expression which is the application of /

We give



arguments.

algebraic signature and some raw terms generated from it. Let the types be nat and bool, and the function bool. If x, y nat, t: bool, f: bool, ->: bool symbols be 0: nat, p: nat, nat and z are variables, then examples of raw terms are: an

example of

to

an

—?

—?



p(x,y)

-i(z)

p(0, -i(rr))

->(p(x, x))

p(p(x, x),p(y, z))



The types here should be



thought of as the natural numbers and booleans, and the terms as zero, binary addition, truth, falsity and negation of truth. Later on, we will give rules for deriving "well typed" or "well formed" raw terms which makes use of the sorting of function symbols; so p(0,  ̄>{x)) is an example of an "improperly typed raw term," because the second argument of p should take



natural number and not



boolean term.

123

Definition of the Syntax

3.2.

We

DISCUSSION 3.2.5

have to define

now

this,

terms for free variables. To do

of

a raw

"holes" in

as

term into

a raw

simple systems of algebraic type theory the free variables of a raw term are just the variables which "appear in" the raw term. More formally, the set of free variables of a raw term M is defined by structural induction: which

"slot" other

raw

first define the notion of free variables

we

think of free variables

Intuitively,

term.

notion of substitution of



we can

{x}

raw

terms. For the



fv(x)



fv(k)



fv(f(M1,...,Ma))d^fv(M1)U...Ufv(Ma)



is



0 where fc is



non-zero

where

arity

variable,



constant function



M,

M[N/x], by

written



x[N/x]



y[N/x]



k[N/x]



/(Mi,..., Ma)[N/x]

symbol of If



is





term N for

induction

on

y where y is



variable distinct from x,



k where fc is



constant function

arity

non-zero

[#i,..., xn]



is



finite list of

in another



leave the reader to



distinct

as

raw

term

is defined in

supply

Let

Exercises 3.2.6



follows:

as

where



is



function

[Ni,..., Nn]



(2)

Show that in

term

general term

M,

written

M[N/x]

analogous

a manner

to

or

raw

terms

sometimes

M[N/x]

and

the

raw

terms for



given algebraic

distinct variables.

defined,

raw

that is,

M[N/x]

M[N/x, N'/y]

is another

is not

raw

term.

syntactically

M[N/x][N'/y\.

M[N/x,N'/y]

is however identical to

M[N[z/y]/x][N'/y][y/z]

<£ fv(M) Ufv(N) Ufv(N').

can now

of well

raw

the next exercise shows.

Show that substitution is well

We

in another

the formal definition. Note that substitution has

(1)



of

and

variables, and N

M, N and Nr be any

signature Sg, and x, y and

where

symbol,

fiM^N/x],..., Ma[N/x\)

M[N\/xi,..., Nn/xn],

raw



terms, then the simultaneous substitution of the

n raw

Show that

symbol

a.

to be treated with care,

(3)

function



the structure of M



identical to the

is

variable



N,

N for the variables

we

a raw



list of

even

where/

a.

We define the substitution of term

symbol, and

typed

define raw



type assignment system, which will generate

terms. To do

this,

we

need



few

more



collection

definitions. A context

124

i—

I—

Chapter

Algebraic Type Theory

Variables

Function

Sg



T h

Mx: >

finite list of

T, x: a, V

Sg



T\-



<*i

...

Sp



k:a

x: a

T h

(k:a)

Ma: aa

(for example)

(f:au...,aa->a)

rh/(Mi,...,M0):a

(variable, type) pairs, usually

where the variables X{ that



3.1: Proved Terms Generated from

Figure a

Sg

Symbols

Sg

is

3.

are

required

an

Algebraic Signature,

written

to be distinct.

the variable X\ appears in V and

as

We shall say

(informally)

(for example)

the type an

appears in T. We shall denote concatenation of contexts

by juxtaposition, such the word judgement to mean "syntactical

r,r' or T,x:a, T'. We shall use expression." A judgement of the form T \- M:a (where T is a context, M is a raw term and a is a type) is called a term-in-context. Informally, think of the as

raw

term M

as an

as a

program, and the variables which appear in the context T

environment for M. We shall

of the form

Sg



T h M: a

now

define

where T h M:



is



certain class of



term-in-context;

judgements we

refer to

Sg > rhM:aasa proved term. Formally, the proved terms are generated by the rules given in Figure 3.1. Informally, think of the raw term M in the judgement Sg > Tl-M:aasa well typed program. We can also think of the free variables of M as program identifiers, and we shall see that every free variable must appear in the context T. Remark 3.2.7

We shall

always assume that the hypothesis and conclusion of any rule for introducing syntactical constructs are both well formed; thus (for example) it is implicit in the rule which introduces Sg > T \- k:a that T is a context, even though we do not say so explicitly. Recall that r, x: a, V is our informal notation for the concatenation of contexts T, [x: a] and T'. Thus if T, x: a, T' appears in an instance of the rule Variables, the variable x cannot

3.2.

Definition of

appear in T

or

the

125

Syntax

T'. Further, any variable appearing in T is not

and cannot



appear in T'. Of course, the terms-in-context which appear

Remark 3.2.8

judgements Sg

part of the

of all of the terms-in-context;

T h M: a form a sub-class



as

indicating that T h M: a is in this sub-class, and reminds us that we are working with respect to the signature Sg. In practise, we shall often refer to a proved term T h M: a, rather than writing the more cumbersome Sg T h M: a, when it is clear to which signature we are > referring.

the formal

symbol Sg

Now let

DISCUSSION 3.2.9

proved

terms.

type) pairs might



context of

say that

Also,

context T.



begin

us



"declaring

proved

We

can

(variable,

it is reasonable to be able to add

term to

produce another proved

more

term. We

identifiers for the program M will not affect

more

the well formedness of M; and the order of declaration is also

Finally, we can give ideas precise.

manipulate

to think about how to

it should not matter what the order of the

Informally,

is in

variables to

is



rules for the substitution of

raw

unimportant."

terms. Let

us

make these

permutation of contexts (altering the order

derive rules for the

(variable, type) pairs), and weakening of contexts (adding variables to contexts). Let ir be a permutation of the first n positive integers. If T [xi: ai,..., xn: an] then write 7rr for the context [xw(i)i a?r(i)) ^(n)"- ^(n)]- of





Also write T C T' if T is of

our

intuitions. The



proofs

are

easy, but

Sg We induct

giving separate judgements.

we

shall

techniques

spell

out the

proof

some

of the

involved.

A derived rule is

Sg

PROOF

?,

sublist of T'. The next few results formalise

first result in detail to illustrate the Lemma 3.2.10



cases

on

> >

r h M: a ttT\- M: a

the derivation of the

according

to the rules in

judgement Sg > T h M: a, Figure 3.1 for introducing such

We have to show (Case Sg > T h M:a is Sg > r^ic^r' h x:a): that Sg > T,x:a, V \- x:a, where r, x: a, V is any permutation of the list T, x: a, T'. But this is the case, being an instance of the rule Variables.

(Case Sg inductively



T\- M:a is

Sg



T h

/(Mi,... ,Ma):a):

that the lemma holds for the

proved

We

can assume

terms which appear in the

126

Chapter

3.

Algebraic Type Theory

hypothesis of the rule Function Symbols, that is Sg > irT i; but now we can just apply the rule Function Symbols to to deduce that

Sg

If T C T' then

Lemma 3.2.11

PROOF With raw

Induction

this,

/(Mi,..., Ma): a,

ttT \-



we can

Lemma 3.2.12



raw

use

T\-M:a

Sg



T'\-M:a



required.

judgement Sg



how

we

lemma which tells

us

forming proved

r,x:a,r'*- N:p



induction



on

Sg

appealing

hypotheses

T h M: a.



may substitute

terms.

Sg We



A derived rule for

Sg

Proof

Sg

simple

these

a* for each

derived rule is

the derivation of the

on

prove

terms in other



as

Mf.



Sg

T\ ̄M:a



TXl-N[M/x\:0

the derivation of the >

terms is

judgement

r,x:a,rt-N:0

to Lemma 3.2.11 in the case when N is

x.

Recall also Remark 3.2.7. □

Proposition 3.2.13 If

we are

able to derive



and a'

are

Suppose that T is a context Sg > T h M: a and Sg >

T \-

a raw

term.

M:af then the types

identical.

Use induction

PROOF

and that M is

Discussion 3.2.14

on

the derivation of

In view of

Sg



T h M: a.

Proposition 3.2.13,

we



might

say that the

Figure 3.1 define a type assignment system, in the sense that for any given context r, if Sg > T h M: a for some raw term M, then a is the unique type which may appear "after the colon." We refer informally to a as the type rules in

of Af. Exercises 3.2.15

(1)

Work

(2)

Let

through the details of the proofs of Lemmas 3.2.11 and 3.2.12, and Proposition 3.2.13. Prove that if Sg > T h M:a where Sg is an algebraic signature, then the free variables of M, /v(M), appear in T. term,

Sg

be

an

algebraic signature,

let x\. a1?..., xn: an h N:

and T \- Mf.ai proved terms for each i. Prove that

Sg

(5

> T h

be



proved

N[M/x\:j3.

3.3.

Theories

Algebraic

Algebraic

3.3

127

Theories We

DISCUSSION 3.3.1

now

set up

formal system in which



we can

assert

equality of raw terms. In fact we shall define a class of such systems, each known as an algebraic theory, and each of which has a collection of axioms and rules for deducing theorems from the axioms. Suppose that Sg is an M'\ a algebraic signature. An equation-in-context takes the form T \- M where T \- M:a and T h M': a are proved terms generated from Sg. Formally, an algebraic theory, Th, is a pair (Sg, Ax) where Sg is an algebraic signature and Ax is a collection of equations-in-context formed using Sg. We refer to the M'\ a equations-in-context in Ax as axioms and we shall indicate that T h M is an axiom by writing Ax > T h M M': a. The theorems of the theory Th comprise the collection of judgements of the form Th > T h M M':a the









(where

T h M

Figure

3.2.

M':a is



in-context which appear





equation-in-context) generated by

the rules in

It is clear from the definition of theorem that the

Remark 3.3.2

form

an

part of the judgement Th

as

sub-class of the collection of all

theorem T\- M



M':ato

when it is clear to which

T \- M





M'\



equations-in-context. We shall refer to

that

mean

equations-

we can

algebraic theory

derive Th

we are



T h M



M':



referring.

Examples 3.3.3

(1)

We

begin with the algebraic theory of groups; we assume the reader is acquainted with elementary group theory. The algebraic signature of the theory of groups is given by type G,



one



three function



sortings

o:

The axioms

(a)

x:G \-

symbols

G,G are

—?



(b) x:G \- o(x, e) (c) x:G \- o(i(x),x) =

i, e,

G, i:G

given by

o(e, x)

o,

x:



x:





—?■

the

and

G and

e:

G.

following equations-in-context:

e:G

(d) x:G \- o(x, i(x)) e:G (e) x: G, y: G,z:G\- o(o(ar, y), z) =

Of course,

(a)

o(x, o(y, z)): G.

(b) are the formal axioms for identities, (c) and (d) (e) is associativity of the group multiplication. The

and

for inverses and



axioms

axioms

128

I—

Chapter

Algebraic Type Theory

Axioms Ax



T\- M



M':a

Th



T\-M



M':a

| I—

3.

Equational Reasoning Sg Th

T\-M:a



T\-M



Th

M:a



T\-M







Th



T\-M

Th



T\-M'

Th

M':a

T\-M



Th

T\-M'

> =







M':a M:a

M":a

M":a

I— Permutation Th

| I—

Th

T\-M



7rT\-M



M':a





M':a

(where

is

7r



permutation)

Weakening



Th



T\-M

Th



T'\-M





M':a

(where

M':a

T C

T')

I— Substitution Th



T,x:a\-N Th

Figure





N':(3

T\-N[M/x]

Th =



T\-M



M':a

N'[M'/x]:P

3.2: Theorems Generated from

an

Algebraic Theory.

3.4-

Motivating

look

is





129

Categorical Semantics

familiar if

(for example) xoy for o(x, y). We say that xoy syntactically sugared version of o(x,y), meaning that the former is easier more

write

we

to read than the latter.

(2)

The

algebraic theory

of meet semilattices has

type L, and



one



function

symbols

The axioms of the

T: L and A:

x:

L, y:

(b)

x:

L, y: L, z: L h

(c)

x:

L h





(d)

x:

L h



A T

3.4

A y







L.

—?

theory (also syntactically sugared)

(a)

L \-

L, L





x:

(y A z)





x:

y A



are



(x Ay)

A z:L



x:

L.

Motivating

Categorical Semantics



We motivate the

Discussion 3.4.1

categorical approach to the semantics of algebraic type theory. Traditionally, the judgements of algebraic type theory built up from an algebraic signature would have been defined rather differently from our approach in Section 3.2, and we review this here. For each type a take a countably infinite set Vara {x", x*,...} of variables (we assume that such sets of variables are disjoint for different types a) and define the terms of the algebraic type theory by the rules =



Mx:

G Vara

k:a

x:a

where k:



semantics would

[a]

au

...,

Ma:

aa

/(Mi,...,M?):/?

/? are function symbols. A set-theoretic /: ai,..., aa then be defined by giving a set [a] for each type a, an element \k\ and

—?

for each constant k:



and



function of the form

for each function

[/]: [ai] x... x [an]

—?■



\(3]

/?. An environment for the type symbol /: a1}..., an theory is essentially a function which assigns a meaning to each of the variables. More precisely an environment p is a function p: where

p(xa)

meaning



—?

|J{ Vara |

[a]



is



type}

—?■

|J{[o;] |

for xa G VarQ. Given such

to the terms

by setting \xa}



p(xa)

is





type}

environment p,

an

and

[/(Ml5..., Mn)\ d^ lf\(Wil





?,

[Mn]),

we

assign



130

so

Chapter

in

if M:

general

There

are



[M]

then

types. proper class of types, then

[a].

For if any of the

set of



Algebraic Type Theory

thoughts about this approach. interpreted by non-empty sets

at least two

each of the types must be restrict to



3.

[a]

The first is that and that

empty,

were

or

must

we

we

had



would not be able to define the function p. The

we

second

thought is that the semantics is specified in terms of elements of sets. Of course, we might consider replacing the sets by some mathematical object which has an underlying set-theoretic structure. But we would be in a much stronger position if we could interpret our syntax in a more general setting, such as a category. We have seen that categories are very general mathematical structures, and that category theory is a powerful organisational tool, but are categories suitable worlds in which to interpret syntactical systems such as algebraic theories? Let to



us

consider the first

We

thought.

can

function with the variables of the term

of the term

meaning

such data

on

to the

as

sets to



taking input

the output. With this

types by assigning

functions. With due

think of

term



giving

rise

data and the effect

perspective,

them, and

as

we can

meaning

give



to the terms

interpretation of the syntax, we should abandon type tagged variables and present the syntax using proved terms, as we did in Section 3.2. Thus a proved term as

regard

for this

xi'.cti,... ,xn:an \-

will

now

of the

be modelled

by



function

/: A\

M:j3

An

—?

B, where

we

think

input variables of M being modelled by an element of the cartesian x An. We can now interpret types by non-empty sets, product A\ x because we no longer need to define the environment p. Now let us think about terms M with exactly one free variable; thus i:ah M:/3, for example, where n

...

fv(M) symbols of



{x}.

We

tacitly

assume

that

we are

only dealing

with function

generalise our set-theoretic model using as few as possible. Suppose we model a and j3 by "objects" A and B about which we make no assumptions. A function is a form of relation; so let us model x: a h M: /? as a "relation" between A and B about which we make no assumptions; we write A B for this. Now let us think about how our syntactic term language is built up. The crucial point is that terms are built up by substitution, in the sense that a raw term f(M) is precisely f(x)[M/x\. We now think about the process of substitution in general. Suppose that we have proved terms rah M: j3 and y:(5Y-N: 7. We have seen that there is a derived proved term rah N[M/y]: 7—so how should we model this? Let us arity assumptions

1. We shall

try

to

—?

3.4-

just

Motivating



Categorical Semantics

131

model rah M:

j3

and

y:(3\ ̄N: 7.

We

[x: a where

D(n,m)

is

some





depending

°^?)



and

on n

of substitution of terms for term variables? Let term

(where

tacitly assume proved terms

both of the

we

x:a\-

C, and

we

shall take one

(L[N/z])[M/y]: 6

syntactically

model them

ought

are

If

we

modelled, then a

□(ra,*^)

function

to be the

same





formed.

proved

variables). Well,

?—1lfl

q an(j ^4

to indicate this.

x:a



Now

we

terms with

exactly

raasa

relation

think about how the substitution of terms for variables is

we =

We will have to model

further

L[N[M/y]/z]: 6

_jly

D(Z,D(n, m))



So the relations which

this?).

too, namely A

□(□(/, n),m)

distinct

x: a

is

What about the order

m.

z are

and

(caution—why

same



step backward and think about how proved

variable

A —^ A.

and

the

will write a

that x, y and

we

B -±+C



7 h L: 6 be

z:

how

on

as

[y:0\- N:-y]

N[M/y]:H

relation

write this

can

\x:a\- M:0\ =A^+B

are

depends

say for the moment that whatever models this term

deduce that if E —^ A and A -^* B then

m.

symbol,

is



proved term x:a the proved term x:a

n(*^,e)

f(M):fif, where f:j3 f {y')[M/y']: fi', and so



(3f

—?







is

will be

by the relation A —^ £?', where £?' models /?' and we specify that proved term x: (5 Y- f {x): j3' \s modelled by B —^-> B'. Now we summarise deductions, writing n o m for D(n, m) and id a for *a:

modelled the our

Types



Proved terms



For each



Given relations A -^ B and B -^ C, there is



Given relations E -^ A and A -^-> £, then

771 O ?

zrf^

are



interpreted by "objects,"

A, B



are

say

interpreted by "relations,"

object A there is



...

say A -^ B...

relation id,A- a

relation A ^> C. we

have id a

° e





and

771.

For any A -^

£, B -^ C and C

—>

D,

we

have I



(n o m)



(I



n)

o m.

specification of a category. Thus we have deduced, subject to certain primitive assumptions about how to model function symbols and substitution, that we can model algebraic type theory in which exactly one variable appears in a term, in an arbitrary category. In such a category, the substitution of raw terms for variables will be interpreted by composition of morphisms; because of the importance of this idea, Note that the above summary amounts to the

132



Chapter

Substitution

Interpreting

Here,

x: a

h M:

(3 and

\x:a\- M:(3\

and

x:

interpreting the proved

[x: 7





by Composition

7 h M':

[x: 7

and

a are

h M'\

a]

of an algebraic type theory, morphisms of a category C

terms

are

terms.

M[M'/x}: 0\

{x:a\-









[x: 7

M':



a]









ii.

/?]

M:



Composition of the



Interpretation of M\M' x] in a category C Ti

Algebraic Type Theory

3.

.,,,,.,,

interpretations

of M

andM'

Figure 3.3: A Basic Principle of Categorical Type Theory.

special

Following our intuitions about more than one variable appearing in a term M, we will model a proved term xi:aii...ixn:an h M:(3 in a category with finite products as a morphism of the form m: Ai x x An £; this will be formalised in Section 3.5.

we

give



summary—see

many ways

Can

do

as

Work

possible

through

the details of Section 3.4.

Try

to think of

as

syntax behaves and how it should be modelled. modelling contexts of variables in a category which

in which

you think of ways of

products?

not involve finite

Categorical Semantics

3.5

Let

Discussion 3.5.1

us now

formalise Section 3.4.

with finite products and let Sg be C for

3.3.

—?■

...

Exercise 3.4.2

Figure

Sg

is

Let C be

algebraic signature.

an



category

A structure,

M,

in

specified by giving



for every type



for every constant function



for every function



of

Sg

an

object [a] symbol

symbol f:cti,...

of

C,

k: a, ,an

global



^>

element

(3 of Sg



[k]:l

—?■

[a],

and

morphism

[/J:[a1]x...x[an]^[/?]. If

we

—]m

wish to draw attention to the in

place

of

[—].

Given



particular

context T



structure

[x\: a1?...

,xn:

M,

we

will write

an]

we

set

irin11

Categorical

3.5.

i—

133

Semantics

Variables

[r, x: a, T' i—

Function



x:

a]

ir:



[T]

[a]





[T]

[a]

->

Symbols

hfc:a]^[felo!:[T]->l->[o] [r



Mji aj ^

[r



mi;

[an].



...

[qj

->

/(Mlt..., Ma)] d^f [/J

[r

...





Ma: qa] 1*

<mi,..., ma>: [T]

-??

ma:

[T]

(n?[aj)

[a,]

-?

-?

[a]

Semantics for the Proved Terms Generated

Figure 3.4: Categorical Algebraic Signature. aj x morphism

Fl

Then for every

proved

term T h M:

a we

shall

by

an

specify



[TI-M:al:[r]-[a] specified inductively using the rules for generating proved terms and the definition appears in Figure 3.4. One of the most basic results about the categorical semantics of algebraic type theory is that substitution of a term for a variable in a term is interpreted by composition of morphisms, and indeed this is what we would expect given our discussion in Section 3.4. More precisely, we have the following in C.

The semantics of

proved

Let r' I- N:

Lemma 3.5.2

(3



and let T h

T h

Mi'.ai be proved

N[M/x\:/3 [r

where





proved

N[M/x}: 0\

N[M/x]

PROOF

is

By



terms is

be





proved

[*k 1 ^15 ?





terms for i



term where



**^n ^nj





1 to

n.

Then

one can

show that

term and further that

[IT' \-N:0\o (\T



Mx: aj,..., [T



Mn:

an]>

denotes simultaneous substitution.

induction

on

the derivation of the

judgement I" h N: (5.



134

Chapter

Categorical

3.6

Models and the Soundness Theorem

Let M be

Discussion 3.6.1

Algebraic Type Theory

3.



structure for

category C with finite products. Given

an



algebraic signature Sg

equation-in-context T h M



in



M':



satisfies the equation-in-context if [r h M: a] and [r h M'\ a] equal morphisms in C. We say that M is a model of an algebraic theory (Sg, Ax) if it satisfies all of the equations-in-context in Ax, and say that structure M satisfies the axioms of the theory Th. We shall also refer to satisfaction of theorems by a structure M.

say that M

we

are

Th



the the

Examples 3.6.2

The

algebraic theory

of commutative monoids has

an

algebraic signature Sg with one type a and two function symbols +: a, a —?■ a and e: a, together with the following axioms (written using an informal "infix"

notation): (1)

x:

a,y: a,

(2)

x:

a, y:

(2>)

x: a

V-

z: a















(x + y)

+ y

y +











(y + z): a



ar. ot

x: a.



theory in a category with finite products is specified by M and e: 1 M such giving an object M of C, and morphisms +: M x M that the three axioms are satisfied. This means that the following diagrams So



model of this

—?■

—*

commute:

(^ +

MxMxM

°(^^MxM +

(+o(7ri,7r2),7r3)



MxM

<7r2,?Fl>

MxM



>MxM



M where !: M

addition is

(a

N,

on

+: N

one

—*■



point

1 is the

—?

N is

set is



MxM



unique morphism

the natural numbers is N

(idM,eo\)'—?



addition, and

terminal

object

to the terminal

object.

model in the category Set.

e:

{*}

of

—?

Set).

For

example, Formally, M

N is the function where

e(*)





Categorical

3.6.

Models and the Soundness Theorem

in

category C with finite products satisfies the axioms of

some

theory, then precisely, we

it will also

the theorems of the

satisfy

algebraic algebraic theory. More an

have Let C be

Theorem 3.6.4

theory

the soundness theorem says that if a structure

Intuitively,

DISCUSSION 3.6.3

135

and M





category with finite products, Th

an

algebraic

model of Th in C. Then M satisfies any theorem of Th.

We need to show that if T h M

M'\

theorem, then the morphisms [r h M:a\ and [T h M': a] are equal in C. We can prove this by showing that if M satisfies any equation-in-context appearing in the hypothesis of any of the rules given on page 128 for deriving theorems, then M satisfies PROOF

the conclusion.

To

that this is the

see



for

case

is





Equational Reasoning

easy. To prove soundness for the Substitution rule

we

Lemma 3.5.2. Permutation is also quite easy. We shall the we

case

of

[r

need to show that

[r'hM':a]. Then

we

Let

Weakening.

h M:

suppose that V Y- M

a\



[T

Letr

h M':

1, and



so

of

just give details for

M':

a] implies

use



and that

that

[n

T' h

rcT;

h M:

proved

a]



terms.

have

[T \-M:a]



using Lemma 3.5.2

using

us

have to make

is

the



hypothesis



using Lemma 3.5.2



\T'\-M[x/x\:a\ [T

\- M:

[r

h M':

[V



a]([T' a]([r'

h xx: h x^

ax],..., [r7 a^,..., [r

h xn: h xn:

an\) an])

M':a\. D

This exercise illustrates

Exercise 3.6.5*

in-context. We define

types ?

are

bool and

t:

theory

Th which has

an

only deal with equations- algebraic signature Sg whose we

given by

hegel,

the function ?



why

and

symbols

bool, f: bool,

->:

are

bool

given by

—*■

bool, tf: hegel

The axioms, Ax, consist of the

(a)



-.(*)

(b)



-.(/)

(c)

x:

bool h

/:





t: bool =

bool and A, V:

bool, bool

following equations-in-context:

bool

A(-i(a;), x)

—*■

f: bool

—*■

bool.

136

Chapter

(d)

x:

bool h

V(->(x),x)

(e)

x:

bool h

V(x, x)

(f)

x:

bool h

A(#, x)

(g)

y:

hegel

We



x:

bool



x:

bool



JJ(y):

(using

then deduce

can

Th



y:

&00J.

an

informal

hegel

h t













that is Th

(1)

y:

Write down

and

(2)



hegel

Algebraic Type Theory

t: bool





-?(tt(y))

3.

\- t



f:

notation)

V(-.(||(y)),|J(y)):

too*

V(Jt(y),|l(y)):6oo/ ¥(y):bool A({t(y),|}(y)):6ooZ AHiife), {{(</))): /:

&00Z

bool

bool.

model M of Th in the category Set in which



[fcooZ] d= {_L,T}.

Consider

variables

{xxeg

page 129.





traditional

x2ege,



In this







defined

on

presentation of the theory Th with tagged

?} (and similarly

setting

[ZieyeZ]

derive

we

for

bool)

and terms M:

equations M



M'\

a as

without contexts



variables, using the rules of equational reasoning. Thus (as above) we can deduce that t f: bool. Write down the environment style model (say M') of Th in Set which mimics M. Show that {t: 6ooZ]m' does not equal [/: bool^M'

of



in the set

[6oo/]m'-

So this is

an

unsound conclusion.

(3)

The soundness theorem shows that with

we

have

[y: hegel in any

(4)

h t:

categorical

bool]



\y: hegel

Think about the fact that the



Write down

large



/: bool]

model. Show that in

to unsound conclusions when

(5)



formal

our



[/iepe/]

particular

—>



—?

{bool]

this holds in M.

interpretation of types by empty

working

with

sets leads

equations without contexts.

deduction tree for Th

sheet of paper for this!

system of equations-in-context



y:

hegel

h t



f:

bool. Use

Categories of Models

3.7.

137

Categories of Models

3.7

Now

Discussion 3.7.1

turn

we

our

attention to relations between models

given theory Th in a given category C. In fact we shall define a notion of homomorphism between two models. Roughly a homomorphism will consist of morphisms (relations) between the interpretation of a type of Th in the two models, such that these morphisms commute with the interpretation of the function symbols in the two models. of



algebraic theory Th in a category C with finite products. A homomorphism h: M N is specified by giving a collection of morphisms ha: [ckJm Mn f°r eacn type a, such that for each function has the following commutative diagram: symbol /: a1?..., aa Let M and N be models of

an

—?■

-*■

—*■



one

[aJM Ot"\







Pn



to the

Let C be the category



ha

as



K]M



hp



...



[aa]N

the components of the

-=—?

1/Jn

of Th in

C,

written

[/?]N

homomorphism

category with finite products and Th

of models

Mm

luQi

[ai]N We refer

...

an

h.

algebraic theory.

Mod{Th,C),

Then

has

the models of Th in C and



objects



morphisms

the

The

homomorphisms of models of Th in C.

M has identity id: M a composition hh' are {hh')a —?

components =

hah'Q.

ida



id[ajM

and the components of

We shall also need another

new

category.

Let C and V be categories with finite products. The category TV{C, V) has

objects

the finite

product preserving functors and morphisms

natural

transformations. We intend to show that for

given theory Th, we Cl(Th), such that for all categories with finite products equivalence a

TV{Cl(Th),V) The idea is that thus

enabling

we can

us

regard

to view





model of

can

find



V there is

category a

natural

Mod(Th,V). a

theory

questions about models

questions about functors. Often this leads to a problem and yields a neat categorical solution.

functor, and vice versa, of algebraic type theories as better understanding of the Before doing this we need as a

138



Chapter

little

F: C

—?

machinery. Given

more

technical



shall define

we

functor



F*:Mod(Th,C) Let M be

follows.

as

[a]f,M the

F[q]m



an

where





[an]F.M



...

where

(3 /: a1?..., an isomorphism. Let h: M by (F*h)Q F(hQ). We —>

—?



that is F*h: F*M term T h M:

given by



the

Mf.m If

Mod{Th,V)

of

composition

Mf.m

is

is

->

Mod(Th,C). F*M is defined by putting type of Th and setting [/]f.m to be given by

object





is



F(Mm





have to be

sure

that such

is the canonical



Then F*h is

given

definition makes sense,

homomorphism of models. Given a proved one can show by induction that the morphism [T h M: a]p.M composition

...

F*N really is

—?



[an]F.M



F([ai]M







...



good definition of F* defined on morphisms. a

The definition of F* is

[T



for which

h N:

a]F.M-

model of Th in £> and

on

our

[an]M) F[ri^f}M F[a]M.

h A/":



is well

K]M) FJ^ F[/?]m =

given proved terms T Y- M:a and T AT: a]M then certainly [T h M: a]F,M

have



...

function

model of Th in C then F*M is we



symbol of Th and be a morphism of Mod( Th,C).



we are



product preserving functor

finite



Algebraic Type Theory

3.

objects.

[r

h M:

ckJm



Thus if M is

we can



conclude that

The reader is left to check that F*

first item of technical

machinery;

now

we

G is a natural transformation between finite give the second. If (f>: F product preserving functors F and G then we can define a homomorphism G*M of models which has components <£[Q]M" F[a]M <f)JS/L: F*M G[o]m at the type a of Th. We will verify that <f>*M. is indeed a homomorphism of models. By definition, we need to check that the following diagram commutes: —?■

—?

—*■

n?F[af]M

(Fir1,...,F*n)-1 x





"'



rVTTBf





F(nT[aJM)

F[/] -J^

F[flM

(2)

^1/31m





xi<fy*]M



(!)

^n?[?<lM





n?G[?i]M 77; pr^rr G(nj[a?]M) T^j- G[/?] M G|/Jm (G7Ti,...,G7Tn) It is immediate from the that

(1)

naturality of <f> that (2)

also commutes. Note that

commutes.

We shall check

139

Classifying Category of an Algebraic Theory

3.8.





(0[ai]M

°

(0[ai]M



i?7I"l' ?















^(a?]M

4>{anjM)



°

F7rn)

(FtTi







F7Tn).

Let C and £> be fixed model of



fixed

categories with finite products, and let M be any algebraic theory Th in C. We define a family of modelling

functors

ApM:7V{C,V) by setting ApM(F)



->

Mod(Th,V)

F*M and ApM(<f>)



<£*M, where </>:F

—>

G is



natural transformation between finite

product preserving functors. It is the

notion of

shall

modelling functor which an equivalence between categories preserving functors.

3.8



thought

of

as a

use

in the next section to set up

of models and

Classifying Category of

Discussion 3.8.1 be

we

an

classifying category

for

categories of finite product

Algebraic Theory an

algebraic theory

category with finite products which is in

smallest such category in which Th

can

be modelled

Th

can

some sense

the

We shall

see

soundly.

later that the

classifying category arises through a formal construction using the syntax of the theory Th. The reader should compare this section with the idea of a freely generated vector space or group on a given set—compare the set to the algebraic theory Th and the freely generated gadgets to the classifying category. algebraic theory. A category Cl(Th) with finite products is the classifying category of Th if there is a model G of Th in Cl(Th) for given any category T> with finite products, the modelling functor

Let Th be called

which

an

ApG:FV{Cl(Th),V)

—?

Mod(Th,V)

equivalence. Such a model G will be called generic and its corresponding modelling functor the generic modelling functor. We shall see that such classifying categories are unique up to equivalence and that they play the role described at the start of Discussion 3.8.1. We shall then give an example of a classifying category and in Theorem 3.8.6 show that every algebraic theory has a classifying category. is

an

Proposition 3.8.2

Let Th be

an

algebraic theory

Cl(Th) a category in Cl(Th). Suppose

and

with finite products for which there is a model G of Th that given any category T> with finite products there is an equivalence

ApG:TV(Cl(Th),V)

—?

Mod(Th,V).

140

Chapter

Then it is the there is

an

Cl(Th)' and equivalence Eq: Cl{Th) Cl(Th)' case

that whenever



Given the

PROOF

Algebraic Type Theory

G' also have the above property for which

Eq^G

G'.



ApG, we can show that for any model M of V for which preserving functor F: Cl(Th) Ap^M. To see this, we have by hypothesis a

equivalence Th in V there is a finite product M: we can just take F F*G natural isomorphism ApGApGl isomorphism ApG(Ap£(M))

—?





3.

idMod(Th,v) implying that there is a natural M in Mod(Th,V); that F*G ^ M follows





from the definition of

too difficult to

such F

are

F*G



ApG. It is also not naturally isomorphic. For if we

see

that any two

given another choice F, then F*G. Using the definition of ApG and applying its inverse, we get

are

F^T. Hence, using instances of these properties of ApG and ApG,, are

may

Eq: Cl(Th) Cl{Th)' and Eq'1: Cl(Th)' Cl(Th) for which natural isomorphisms Eq+G G' and Eq ̄xG' G, giving one

define functors

there

we

->

->





part of the proposition. It follows from the definitions that

Eq^iEq^G))

(Eq'1



Eq)*G



(idcl(Th) )*G G; using the observations of the first paragraph we deduce that Eq'1 Eq idci(Th)- It is equally easy to check that we have Eq Eq'1 idci(Th)' and thus we have the required equivalence. □ and











For any model M of

Corollary 3.8.3

V with finite products, there is



an

functor F:

algebraic theory

Cl( Th)

—?

Th in



category

V which preserves finite

products, for which the composition of the semantics of Th given by the generic model G in Cl( Th) with the functor F yields the semantics given to Th by the model M, up to isomorphism. This may be seen pictorially as Th



-M-

-.

V where F*G



M.

Cl(Th) Moreover F is

unique

up to

isomorphism.

property that the model G is referred to the "smallest"

PROOF

as

It is because of this universal

the

generic model and that Cl(Th)

category with finite products in which there is

Follows from the first part of the

Example 3.8.4

We shall

give

an

proof

example

algebraic theory. In order to do this

we

of

of





Proposition

is

model of Th.



3.8.2.

classifying category

of

an

shall define the category of finite

Classifying Category of

3.8.

an

sets and multirelations. This

The

P: X

objects y

are

141

Algebraic Theory

category TSMR, is given by the following data.

finite sets X and the

morphisms

R:X



—>

are

functions

composition of R, and S: Y —?■ Z, is given by the function SR: IxZ->N which we define by SR(x, z) =f £yGyP(x, y)S(y, z) where the latter is a finite sum of products of natural numbers. The identity on X is given by the function idx- XxX->N where x

—?

N. The









idx\x,x)

def



1 if



0 otherwise.









x'

simple to see that the category TSMR, has finite products. The terminal object is the empty set 0. The (specified) product of objects X and Y consists of the object P which is the disjoint union of X and Y (let us define this to be X and tt2: P y (X x {0}) U (Y x {1})) together with projections tti: P which are given by the functions 7Ti: P x X N and 7r2: P x y N where It is

-?■

-??

—?

ttAv

We shall

now



Then there is







disjoint

algebraic theory

Jlifp=^1)

n2(py) d=

0 otherwise

write X W y for the

Let Th be the page 134.

f1[iP=(xi°)

x) d=

—?

0 otherwise

union of X and y.

of commutative

monoids,

as

defined

model G of Th in TSMR, where the type



on

is

interpreted by the object [ajc {*} of TSMR, (that is a one point set), the function symbol + is interpreted by the morphism [+]g: {*} x {*} {*} which is given by the function [+Jg* (i*}1*1!*}) x {*} N which is constant with value 1. Finally, e is interpreted by the morphism [e]Q:0 {*} which is given by the unique function 0x{*} 0—>N. We shall simply refer to =

—?■

-*

—?



this model of Th

particular

as a

monoid is

monoid in the category FSMJl. As

theory

shall see, this

generic.

Now let V be any category with finite of the

we

products

of commutative monoids. We shall

and M any model in T>

now

write

(M, +, e)

for the

interpretation ([a], [+], [e]) of the theory of commutative monoids specified by M. It is hoped that this overloading of notation will clarify rather than confuse the technical details. Our aim is to prove that the

ApG : TV{TSMH,V)

—?

gives rise to an equivalence of categories; thus is Cl(Th) up to equivalence. Define a functor

Ap-£:Mod(Th,V)

-?

modelling

functor

Mod(Th,V) from

Proposition 3.8.2, TSMR,

TV{TSMR,,V)

142

Chapter

by the following prescription, where R: X

Algebraic Type Theory

3.

Y is any

—>

morphism

of TSMJZ.

We shall define

Ap-£(M):TSMH^V object X is given by Ap^(M.)(X) Tlx XM where the notation means the finite product of one copy of M for each element x of X. To define the action of Ap^(M) on the morphism R we have to give a morphism Ap^(M)(R): IIl xM IIy yM in V. In order to do this, x M we note that up to isomorphism there is a morphism +n: M x M for which the source is a finite product of n copies of M where +n is defined M. With this, the yth component of ApQ1(M)(R) is given using +: M x M by to be the functor whose action

on

the



—?■

—?■

...

—?

UxeXM

(that is iryoAp'^'('M)(R) 0 is





+|x|°0)

UxeXM

^HL



where the xth component of the

morphism

given by nx

where 7rx is the a;th

—?■

N is

nf >w ^3ai

projection of the product Ux

Ap^



Ap<2(h): Apq-(M.)

we

is indeed

—*■

ApQ1(N)

have written N a

xM. This completes

the

on

has components

UxeXM where



objects M of Mod(Th,V). Suppose that homomorphism of models; then the natural transformation

definition of the functor h: M

<*--*■!

XM

finite



[q]n-

Note that

we

-*

UX

XN

have to check that

product preserving functor and that

Ap^(h)

is

Ap^(M) a

natural

transformation. All these details form the next exercise. Exercises 3.8.5

(1) Verify

that TSMR, is



category with finite products.

(2)

Write down the action of the functor

(3)

Write down

(4) Verify

that



ApG.

formal definition of +n-

Ap^(M)

preserves finite

products and that

Ap^(h)

is



natural transformation.

(5)

Prove the

required equivalence of categories.

Every algebraic theory Th has a classifying theory Cl(Th). A classifying category can be constructed from the syntax of Th and we shall refer to it as the canonical classifying category of the theory Th. Theorem 3.8.6

Classifying Category of

3.8.

PROOF

Then ?



We

we

begin

with

(r | M)

define

[x\: ai,..., xn: an]



given

some

to be

is

143

Algebraic Theory

an

notation. Let ax,..., an and

an

equivalence class of pairs (r, M) where

context where the



/? be fixed types.

types appearing in T

are

the

Th



ai,...,an,



M is



the

equivalence

r h M



Sg

term for which

a raw

T h M:



relation is defined

M'[x/x'\. 0

where

x are

(3,

by (r, M)

and

(T', M') just



in

case

the variables in T and x' the variables in T'.

objects of Cl(Th) are finite lists of types from the algebraic signature Sg of Th, for example a [al5... ,an]. The morphisms with source a and target /?, where /? [/?i,... ,/?m] and both a and 0 are non-empty lists, are given by finite lists of the form The





{(T\M1),...,(T\Mm)}:a^p where the types

Such





appear in T and

we

have

(r | M) (take

list will be written

Sg care



My.fij for 1 < j < m. this abbreviation). We

T h

with

leave the reader to consider what

happens if a or /? is empty. It is clear that ([xi:ai,...,a:n:an] | x) is the identity morphism on a. Now consider The composition the morphisms (r | M):a (3 and (I" | N): (3 7. (r I AT) o (r I M): a -> 7 is given by [(r | ^[M/y]),..., (r | Nt[M/y\)] where y are the variables in T'. Of course we must verify that the composition is well defined: these details are left to the reader. The terminal object of Cl(Th) is the empty list [ ] and binary products are given by list concatenation. —?■

—*

The a

is



given by putting [a]o [<*] where (3 is a (r | f(xi,..., xn)) where /: ax... an [xi: ai,..., xn: an]. The proof is completed by

generic model G of Th in Cl(Th)

type of Sg and

[/]g

is



—?



symbol of Sg and T showing that the modelling functor function



ApG : TV(Cl(Th),V)

given by

the

Mod(Th,V),

assignment <f>:F —>F'

is

—?

h+

0?G: F*G

—>

F'^G

equivalence for all categories V with finite products. We write Ap^ for proposed inverse equivalence. Suppose that M is an object of M.od{ Th, V). V by setting define a product preserving functor Ap^}"M.: Cl(Th)

an

the We

—*■

(T\M):a—> (3

l—-

Mi: A]M,

([r



if

is non-empty



/? :

n"[ajM

—*







?,

[r



Mm: /?m]M): ^[aJm

otherwise.

—^

n-[ft-]M

144

Chapter

Ap^M.

Rather than verify formally that

Algebraic Type Theory

3.

products, we shall just check that it preserves the product [a, a'] x [/?]; the formal proof that the functor preserves all finite products follows an identical procedure. Set T [x: a, x'\ a', y: /?], and so there are projections preserves finite



[(r | s),(r | *')]:[<*,<*',/?] Cl(Th).

in

[{T | y)]:[a,a',0]

[a, a']

—?

We need to show that the

morphism

(Ap^M([(T | x),(T | xf)]),Ap^M([(T \ y)})) Ap^Md^a'^}) is

an

isomorphism

(Ap^M([a,a'})

—?

[a']M



[/?]M



isomorphism in V. This is certainly (irp, ir'p, p') where we have projections an

Mm

t:

tt': p:



Ap^M([p}))



V, that is

in

((^Wm.tMmJ.^IsIm) : Mm is

[/?]



Mm





Mm

(Mm



Mm)

p': (Mm





Mm)

the

Mm)



with inverse

case



[/3]M

given by

Mm

-??

[a]M

([a]M

—>



Mm [fi\M





\0\m



([a]M

Mm)



[flM

in£>. Now let /i: M

transformation

—?

N be



morphism

Ap^h: Ap^M.

—?■

of

Mod{ Th,V).

Ap^N by setting

def

(Ap£h)s a= xJha< : II?Mm We need to check that

Ap^h

morphism (r | M): a

/?

—>

in

We define the natural

—?

n?[<*]N.

transformation, that is given Cl(Th), the diagram is



natural

y.nh * 1

xrv

;tai

n?[aJN

([TI-M1:j91]N,...,[ri-Afm:AnlN)

commutes. This will

certainly

[/?]

\-

we

have

induction

on

h0o\T



be the

M:a]M

the derivation of



Sg

case

if

given

M:a]N

[T





T V- M:a.



any

nriftlN

morphism (r | M):a

(x?/iQi).

We show this

—?

by

Classifying Category of

3.8.

(Case

T h M:

is



is T h



[xim. a[,..., xm: a'm],

x:a):

a, V \-



tt[q]n



(Case r h M:

T, x:

We have

(x?/iQi) xhax (x?/iQ>). Suppose

/(M): a):

and that

145

Algebraic Theory

an

have

we

proved

that the context T is

terms T h

M*:

given by

a*. Then

we

have

fyo[rh/(Mi,...,Mn):a]M ^o [/]m





by

induction





we see

Now

we

To define c,

(xJ/O

[/]N



([T



Mi]N

[/In



([T



MJN,..., [T









?,

(x?/iq>),..., [T

Mn]N)





[T



Mn: an]M)

Mn]N





(x?/iQ,))

(x-/iQ,)

isomorphisms and

idMod(Th,v)

need to define

77:

id^v(^Ci(Th),v)

homomorphisms

isomorphisms in Mod(Th,V) such a homomorphism, we have Now,

cm-



Ap^ApQ.

ApG(Ap^'M)

—?

M which

for each model M of Th in V. But to define to

ApG(ApGlM){ct) so we can





is well defined.

are

and

([T

Afi: aJM,



need to define natural

we

Mi: ai]M,..., [T h Af?: a?]M)



[/In

ApGl

that

ApGApGl

e:

([T

[rh/(M1,...,Mn)]No(x-/ia,).



Hence



give =

its

components

Ap^daJG)



at



type



of Th.

[a]M,

define

( m)o In order to define 77,

we

"Z[a]M: Mm



have to

-??

Mm-

give components

rjF-.F^Ap^iApaiF)) in

TV{Cl{Th),V)

and then

Cl(Th).

give the components But

we

so we can

arising and 77

define



natural.

Apg(FmG)(a)

(r)F)s- F(a)

from the fact that F is

are

—?



X>, of

have

Apg(ApG(F))(a) and

product preserving functor F: Cl(Th) of this natural transformation at an object

for each finite



—*■

II"F[ai]

finite



njF[aJG



njF[a<]

isomorphism product preserving functor. Certainly e to be the canonical



146

Chapter

3.

Algebraic Type Theory

The definition of classifying category that

Discussion 3.8.7

have

given is a very general one, and we have seen that such a category is unique up to equivalence. In fact the canonical classifying category Cl(Th) given in Theorem 3.8.6 satisfies

an even

we

stronger universal property than that stated

Corollary 3.8.3, namely that the diagram in that corollary commutes up to strict equality and not just isomorphism. This is stated formally as a corollary in

to Theorem 3.8.6.

Corollary 3.8.8 a

algebraic theory

Given any

category V with finite products, there is

Th and

(up to Cl{ Th)



model M of Th in

canonical

isomorphism)

—*■ V for which F*G unique finite product preserving functor F: where Cl(Th) is the canonical classifying category of Th.

define F

ApgM—see



structures F*G and M

are

Wf.g .







Otn

—?

(3

U\f.q

is















proof of Theorem 3.8.6; we say informally that F is given

page 143. We could

by "applying the structure [—]m-"

where T

M,

The existence of F follows from the

Proof

If/: Q?l,





All that remains is to check that the

identical. If

F(Wo)



function





is



type of Th

*"([?])



symbol of Th

we

we

have

Mm- have

F(T\f(x))

lThf(x):p]M ai]M,

[/]m



([r

[/1m

°

(Tlj-'-jTn)

h xi.





?,

[r

h xn:

an]M)

[/]m

[xi: Qi,..., xn: an).

T> preserves finite products and that Suppose also that F':Cl{Th) F^G M. If a is any object of Cl(Th), then there is a morphism (in fact a canonical isomorphism) ¥a: Fa F'a given by —?



—?■

Fa

It is

an

natural

^ nr^M



n?[adf*.G



^^[0,]



F'a.

F'a give rise to a verify that such isomorphisms ¥5: Fa F' (in the functor category [Cl(Th),T>]) as asserted. isomorphism F exercise to







3.9.

The

Categorical Type Theory Correspondence

The

3.9

147

Categorical Type Theory Correspondence

In this section

Discussion 3.9.1

shall show that

algebraic theories and categories with finite products can be seen as essentially similar concepts. First, let us see that every category with finite products gives rise to an algebraic theory, and that this process is, in a sense to be made precise, mutually inverse to that of constructing a classifying category. For any category C with finite

Theorem 3.9.2 a

we

particular algebraic theory, Th{C)

canonical model of

Th(C)



products,

we can

(Sg(C),Ax(C)). Moreover,

associate

there is



in C.

algebraic signature Sg(C) has (essentially) types which are copies of the objects of C and function symbols which are copies of the mor- phisms of C. More precisely, there is a type A for each object A of C, a constant function symbol k: A for each morphism k: 1 A of C, and there is a function x An B for each morphism /: A\ x B of C. symbol /: A\t..., An PROOF

The

—?

—?

—*■

...

morphism of C gives rise to a number of function symbols. For C is a morphism of C, then there are function symbols example, if f:Ax B C (n l and Ax A x B above) and /: A, 2? 2 and C (n f:Ax B B above) in Sg(C). We ought to decorate these function A and At Ai symbols with (say) subscripts, in order to distinguish them, but we will not do this—with a little common sense we will not run into problems. Note: Each

—?

—>









With this definition there is in C

—?



obvious canonical structure M for

Sg{C) Ax(C)

A, [k] d= k and [/J d= /. The collection equations-in-context over Sg{C) which are satisfied by M. It

given by setting [A]

consists of those

an



is thus immediate that M is



each category C with finite

universal property of

Th(C).



C : Eq'1 for equivalence Eq : Cl(Th(C)) products, where Eq is the functor arising from the

There is

Theorem 3.9.3

model of



an

Cl(Th(C)) applied

to the canonical model M of

Th(C)

inC. Proof

Eq:V

—?

Write V for

Cl(Th(C)).

Let

us

recall the definition of the functor

C, namely

(r|M):a—+/? f <[T



) if (3

is

I !



i—*

Mn AIm,





?,

[r



Mm: AJM): n?[<*i]M

non-empty

II"[aijM

—*



otherwise.

—>

K?[PjU

148

Chapter

Let f:A

—?

B be any

morphism of C. We define

Algebraic Type Theory

3.

Eq l:C

functor



—?■



by setting Eq ̄l{A) [A] and £?_1(/) d= ([x:A] \ f(x)). To prove the idc equivalence, we must show that there are natural isomorphisms EqoEq'1 and Eq-1 o Eq idx>. The first isomorphism is trivial to see: the components are identities on objects of C. For the second isomorphism, we define a natural transformation /z: Eq ̄l o Eq idj> which has a component =





—?

[(x: U^Ai | tti(x)),

...,

(x: U^A | 7rn(x))]



object a [A1?..., An] of X>, where projections (the reader can consider for himself =

7Tf:

list).



id?

component

at



natural transformation rj:

->

[Ai,..., An]

A{ are product IIJ A* what happens if a is the empty

at any

We define

[11?^]

—?■

—?■

.E^-1

.E^ by setting



its

to be

I idn^Ai{xu

...

>xn))] : [Ai,... ,An]

[11?A*]

-*

II"Ai gives rise to a function identity morphism idrp^nfAj symbol idnnA.:Ai,... An II? A*. Appealing to Lemma 2.5.3, we need to prove that one of /z and 77 is a natural transformation, and that their components are isomorphisms in V. We omit the routine details, except for one part where the

—?■

—*



of the verification, namely that

We have Vs

°

Vs

From the definition of Th



In fact the above





l(x: II?Ai I idn?Ai (*"i (x),..., 7rn (x)))]. morphism

x:U"At

in

V,

we

wish to show that

\-idn?(ni(x),...,'Kn(x)) =x:TJ%Ai.

equation-in-context is

an

axiom of

lx:TL1}Ai)ridnzAi('Xi(x),...,irn(x))]







where of

course

[—]

Th(C),

idn?Ai

°

(^i,







,*"?)

idu^Ai [xiU^AihxiIl^Ai]

refers to the canonical structure M for

Sg(C)

in C.

following slogan:

We

can

1—

Categorical Type Theory Correspondence

summarise Theorem 3.9.3 with the

because

Categories with finite products yield a representation algebraic theory which is syntax independent.

of the notion of



The

3.9.

149

Categorical Type Theory Correspondence

products, the algebraic theory Th{C) is called the internal language of C. This language is extremely useful because it allows us to reason about the category C as though it were the B is a morphism category Set of sets and functions. For example, if /: A of C, then there is a proved term x:A\- f(x): B in Th(C). We can think of x as an "element" of the set A and f(x) as the action of the "function" / on x. The soundness theorem allows us to prove facts about C using the internal gf in C it is enough to language. For example, if we wish to prove that h show that x\A h g(f(x)) h(x):B in Th, because the soundness theorem gives h=[x:A\- h(x): B]G [x: A h g(f(x)): B]G gf. Given any category C with finite

DISCUSSION 3.9.4

—*■









perform calculations in the internal language than argue category-theoretically. Note also that there is a derived syntax in Th(C) for "binary products." The theory Th contains function symbols

It will often be easier to

Fst

d=

tt.AxB^A

Snd

d=

tt'.AxB^B

(-,+)



idAxB:A,B^AxB

and axioms

So

we can

x:A,y:B



Fst((x,y))

x:A,y:B



Snd((x,y))

z.AxB



(Fst(z),Snd(z))

to

x:A

y:B



language

say that in the internal

provably equal





z:Ax B.

C, the "elements" of Ax B

of

are

pairs of "elements" of A and B.

important question which remains thus far unanswered is "what might a notion of translation of algebraic theory be?" Another way of asking this question might be to inquire how we may interpret one theory in another theory. It turns out that our categorical machinery can be used to give a very general notion of translation using the concept of classifying category. In fact we shall define a translation, T: Th —*■ Th', to be given by a finite product preserving functor T: Cl(Th) Cl(Th'). Using the equivalence Discussion 3.9.5

An

—?

ApG we see

that to



FV(Cl(Th), Cl(Th'))

specify

look at what data

are



T amounts to

giving

needed to

such

conclusions. For each type



give

of Th

we

Mod(Th, Cl(Th'))



have to



model T: Th

—?

Cl(Th').

model and then summarise

give

an

We our

object of Cl( Th'), which

150

is



Chapter

list

[a]x

ot! of



3.

Algebraic Type Theory

types of Th'. For each function symbol f:ct\,...,an

—>

/3

x give a morphism [/]t- [g*i]t x [^Jt —* 1/3] t- If the source of this morphism is given by [a[,... ,a'n] and the target by (3, then writing V (T' | N) will [x[:a'1,...,x,n:a,n] the morphism [/]x V h Ny.fij. In order be specified by a list of proved terms, say Sg' > that these data define a model T, the axioms of Th must be satisfied. If

of

7%,

have to

we











M'-.ol

(where Th (Sg,Ax)) then we must ask that there is an equality [r h M: a]x [r h M': a]x of morphisms in the category Cl(Th'). Let us write [r]x [71,... ,7^] where of course each ^ is a list of b ̄- Writing V types from Sg', and also [a]x [x{:'yi,... ,x^:%] we will Ax



r h M













have

ir\-M:a]T [rhM':a]T for

some raw

Nj

and

for the

iVj).

terms

(and similarly Th'

must have

translated into

V h

> a

In summary,

Nj

l(r'\N1),...,(r\Nm)}





[(r'|Aro,...,(r'|iv;)]

such that

Sg'



V h

From the definition of

Nj



A/"j:^

Nji 6j

for each 1 < j <

morphism

for each j.

in

CZ(TZi'),



we

So each axiom of Th is

finite set of theorems in Th'.



Th' is specified by giving a list of types list of proved terms of Th' for each function

translation T: Th

of Th' for each type of

Th, and



—*■

symbol of Th, in such a way that the induced structure [—]x (as defined transports each axiom of Th to a finite set of theorems of Th'.

above)

equivalent, denoted by Th Th', if there is an equivalence of classifying categories Cl(Th) Cl( Th'). Note that each of the functors giving rise to the equivalence is automatically finite product preserving. In fact: We shall say that the theories Th and Th'



are



Theorem 3.9.6

PROOF

For every

algebraic theory

A routine verification We have

Discussion 3.9.7

Th

we

have Th



Th(Cl(Th)). □

using the definitions. seen

that the

categorical

semantics

given

to

algebraic theories is sound, meaning that any theorem of a theory is satisfied by a categorical model. The converse notion to soundness is called completeness. The categorical semantics for an algebraic theory Th is said to be complete if an equation-in-context E of Th is a theorem whenever for all categories C with finite products, E is satisfied by all models M in C. Theorem 3.9.8

with finite

categorical semantics of algebraic theories in categories both sound and complete.

The

products

is

3.10.

Further Exercises

151

proved in Theorem 3.6.4. Conversely, let T h M M':a be an equation-in-context of an algebraic theory Th. If it is satisfied by all models, in particular it is satisfied by the generic model of Th in Cl(Th). One can check by induction on the derivation of proved terms that [r h M: a]o (r | M) for any proved term Sg > T h M: a, and so we have PROOF

Soundness

was





(V I M)

(r | M').



Hence Th

T h M





M'\

a as



required.

Further Exercises

3.10

(1) Suppose

that Th is any

is identical to



theory Th'

which

Th, but in which the rule

( Th



xi'.oti,... ,xn:an h N



Tl-Mi

N':p







Consider also

algebraic theory.

Th

Th



M[:a1 T h



Th

...

N[M/x\





T h

Mn



M'n:an

N'[M'/x\:(5

replaces the rule Substitution in Figure 3.2. Prove that the theorems generated by Th and Th' are the same. Warning: this will need a little care.

(2)

Produce

given

an

algebraic theory,

Th say, which has types a,

/?,

p,



any model M of Th in



category C with finite products,

[ckJm



[/2]m

terminal

theory

object

in C and

Th does indeed

satisfy

these

isomorphic properties. is

to

[p]m-

for which

[t]m

is



Check that the

(3) Let Th be the theory of commutative monoids (see page 134) and Th' be the theory of monoids; so Th' is identical to Th but does not have the axiom x:

a, y:





products,



+ y



y +

x: a.

and that there is

Show that the category

an

fAod( Th', Set)

has finite

isomorphism

Mod{Th',Mod{Th',Set))^Mod(Th,Set). (4)

Let TSMR, be the category of finite sets and multirelations and Th the

theory of commutative monoids. Let M be and write

{Mgen, +gen, egen)

Example

3.8.4.

(a)

Show that there is

of TSMJZ to X

=>



for the



model of Th in

Set,

say

(M, +,e),

generic model of Th in TSMR.—see

functor F: TSMR,

—?

Set which takes

an

object

M, the set of functions from X to (the underlying

of) M, and which takes a morphism R: X FR: (X^M)^(Y^- M) defined by

—?

X set

Y of TSAUZ to the function

FR(f)(y)d^i:xeXR(x,y)f(x)

Chapter 3.

152

where SxGx indicates

R(x, y) f(x) (b)

is the



sum

of

sum



of the elements

f(x) (in M) R(x, y)

Prove that F preserves finite

(c) Show that F(Mgen)

(d)

finite

Algebraic Type Theory

R(x, y) f(x)

in M and

times.

products.

M in Set.

Prove that

F(Mgen



Mgen)

—-

F(Mgen)



F(Mgen)

—-





M +



\ ̄T ̄gen)\ M



F(Mgen) and

F(0) F

\egen)

F(Mgm) are

commutative

Th in TSMR.

(5) Complete

diagrams



in Set. Thus F



transports the generic model G of

to the model M of Th in Set—see

the

proof of Theorem

3.9.3. In

Corollary

3.8.3.

particular verify

that \i and 77

are

natural transformations.

3.11

Pointers to the Literature

Some of the

early background ideas behind the kind of type theory presented in "Categories for Types" can be found in [Chu40]. The concepts of arity and sorting certainly go back to Frege [Fre67]. For an up-to-date textbook which gives a general account of both proof theory and type theory, see [Gir89]. A good introduction to set theory and logic, which gives background information about formal logic and (set-theoretic) models is [Joh87]—the idea of a single sorted equational theory is discussed in the first chapter. The first account of the connections between the notions of a syntactical theory and appropriate categorical structure appears in [Law63]. An account of algebraic theories from a slightly more "mathematical" rather than "logical" viewpoint can be found in [Man76]. The use of type theory as a programming formalism is due in the main to Per Martin-L6f—see the papers

[ML]

and

[ML84]. Although

none

[ML71], [ML72],

of these papers contain information about

3.11.

Pointers to the Literature

153

theory, they do cover many more type-theoretical constructions than are presented in "Categories for Types." An excellent textbook reference for type theory is [NPS90]. This book is in part a polished account of the many works of Martin-L6f (amongst others). A nice account of propositional and predicate logic can be found in [vD89]. While not of direct relevance to type theory, predicate logic soon appears in more advanced work which involves type theory. model

4 4A

Functional

Type Theory

Introduction

Discussion 4.1.1

Our task

develop a categorical type theory correspondence for an equational type theory based on the "simply typed A- calculus." It will be helpful if the reader has a nodding acquaintance with simply typed A-calculus, but this is not crucial. Let us review in an informal fashion the basic principles involved. Originally, the A-calculus developed from attempts to produce a notation for representing and calculating with functions. (Strictly speaking, the original work in this area was concerned with (a primitive form of) a system now known as the untyped A-calculus, but we shall not worry about such details in this very superficial discussion). Consider an expression such as x + y. We might think of this as being a definition of a function / given by x i—? x + y (where the value of y is constant), or as a function g defined by y \-* x + y (where the value of x is held constant). In day to day working life, mathematicians deal with such niceties simply by using ad hoc notations, and letting a context of discussion allow an intelligent reader to deduce precisely what the author means by his ad hoc notation. However, present day computers are not quite as intelligent as the typical reader, and it is essential to develop precise notations and syntax in order to program up mathematical functions. The A-calculus is a formalism for dealing with these problems. In the A-calculus, the functions / and g would be denoted by /



Xx.x + y

now

is to

and





Xy.x

+ y.

symbol which appears after the A and before the dot, called the binding symbol, indicates that occurrences of the symbol after the dot are to be thought of as "slots" into which values can be plugged. Thus "A-expressions" such as / and g can be thought of as functions which take an input, pop the input into occurrences of the slot, and produce a result; the binding symbol is said to be bound and occurrences of the binding symbol after the dot are also said to be bound. We refer to the syntactic expression Xx as an abstraction and say that occurrences of the binding symbol after the dot are captured by the abstraction Xx. So, if the function / is given an input 3, we write 3 + y to indicate this procedure. What about substitution? (Xx.x + y)(3) With the intended meaning of a A-expression borne in mind, we would expect The



to define

(for example) (Xx.x



y)[4/y]



Xx.x + 4. Now let

us

think about

4.1.

Introduction



(Xx.x + y)[x + 4/y].



155

which adds y to its x

+ 4 to its

The intended

input;"

input." Yet if

so we

we

put

meaning of Xx.x + y is "it is a function would hope that h "is a function which adds

(Xx.x + y)[x + 4/y]



Az.rr +

(# + 4)

we

get

function which "doubles its input and adds 4." The

problem arises because the symbol x appears in the expression which is being substituted; the symbol x in x + 4 has been captured by the abstraction Xx, meaning that the symbol x in x + 4 has become bound (in the expression Xx.x + (x + 4)). The solution in such cases is to change the binding symbol to one which does not appear in the substituted expression. This makes sense, because such a binding symbol is just denoting some "slots" and clearly the positions of the same slots can be indicated by a different symbol. Thus a

(Xx.x where



y)[x



4/y]



(Xz.z + y)[x



4/y]



Xz.z +

(x + 4)

Perhaps surprisingly, these ideas are more or less the complete essence of the A-calculus; we have a basic syntax in which to write expressions, some of which we may want to denote functions, and then use the formal symbol A to indicate which parts of an expression are to be regarded as inputs, thus giving rise to a function. This completes our informal review of the A-calculus and now we shall give a summary of the contents of Chapter 4. 2

is chosen not to appear in



+ 4.

begin by defining a formal syntax for a functional type theory based on the ideas given above. The word functional just indicates that there is a formal syntax for defining expressions which can be thought of as functions, and such type theories will subsume algebraic type theories. The types will be built from a given collection of basic types, and will include a type of We

"pairs of values"

type."

as

well

This is followed

shall call

as

by



type of "functions from

the definition of

one

type

to another

equational theory, which we same as an algebraic theory, but an

Ax-theory. This is much the now we are dealing with a richer class of terms (or programs). Next, we show how to derive a categorical semantics for Ax-theories, subject to certain basic assumptions over the way the syntax is interpreted. As for algebraic theories, types are modelled by objects in a category, and terms as morphisms. The most fundamental assumption about the model will be that substitution of one term in another term in the syntax is interpreted as a composition in the category of the interpretations of the two terms—recall Section 3.4. We can use this assumption to write down equations which must hold in the categorical model if the syntax and equations of our functional type theory are to be modelled soundly; and these equations will determine a minimal kind of category theory in which the syntax of a functional type theory can be a

156

Chapter 4-

interpreted in



sound way. In fact it turns out that

type theories in and



Functional

we can

Type Theory

interpret functional

cartesian closed category. With the basic definitions of Ax-

model of such

theory in a cartesian closed category, we move on to prove a categorical type theory correspondence for functional type theories. Just as for algebraic theories, we now show that we can construct a cartesian closed category Cl(Th) from a Ax-theory Th and a Ax-theory Th(C) from a cartesian closed category C, and that these constructions are mutually inverse in a precise way. We shall see that the category Cl(Th) contains a model of Th, and from this it will follow that our categorical semantics is both sound and complete. The chapter finishes with an application of the categorical semantics. If we are given an algebraic theory, we can consider the Ax-theory which uses the types and function symbols of the algebraic theory as its own theory





types and function symbols, and has the axioms of the algebraic theory own

axioms. Then there is

an

important question, namely

is



given

term

as

its

of the

Ax -theory

provably equal to a term of the algebraic theory? We shall see that this question can be translated into a problem about category theory, using the categorical type theory correspondence, and that a proof of the categorical problem (which we give) amounts to a proof of the original question.

Definition of the Syntax

4-2

Discussion 4.2.1 type



signature for



functional

theory, which consists of basic data from which to build types and terms.

A Ax -signature, ?

We shall define the notion of

A collection of

Sg, is given by the following data:

ground types.

The collection of types is

generated by

the BNF

grammar a

where 7 is any

ground type.



function type.



A collection of function

number

::=

unit





We call

symbols



a x a

a x

(5





a =>

a,

binary product type

each of which has

an

and

arity which is



a =¥>

(3

natural

(possibly 0).

sorting for each function symbol /, which is a non-empty list [?!,..., aa, a] of a + 1 types, where a is the arity of /. We shall write /: ai... aa —*■ a to ?



sorting of /. In the case that fc is a function symbol of arity 0 we denote the sorting by k:a and the function symbol k will be referred to

denote the

shall as a

constant of

type

a.

Definition of the Syntax

4-2.

We

can now

these

are

given



define the

Here,

For x, k and



()



(—, —)



Fst takes

be

can





takes a



Chapter 3;

see

thought

of

as

"a

unique element of

a one

point set;"

pair of arguments M and N and returns the pair (M, N);

pair P and returns the first argument Fst(P) and similarly Snd

pair P and returns the second argument Snd(P);

Xx: a.M is



function whose value at

of the variable is,



in M

replaced by N;

the result of the

Remark 4.2.2

expressions

are

MN. We will

argument N is M with

an

application of



function F to

We shall often write syntax in

complicated,

use

brackets

might

we

"("

and

"application

occurrences

and

")"

also write in

an

an

an

argument M.

informal

fashion. When

M(N), (M)(N)

or

(M)iVfor

informal fashion to indicate the

structure of formal syntax. We shall also write

MNPQ for ((MN)P)Q

so

that

associates from the left."

DISCUSSION 4.2.3

As discussed in Section

concept of free and bound variables of

raw

4.1,

we

will need to define the

terms. In order to do this

auxiliary definitions. We define the relation R is M, written R C M, through the following clauses:

need

MM

variable, k is any constant and / is any function symbol of arity a. Informally, think of the raw terms in the following ways:



FM



\x:a.M

is any

non-zero



we are





takes

and

Ax-signature Sg,



given by the following BNF grammar, where we assume that countably infinite stock of variables, say Var {x, y,...}:

length



generated by

terms

raw

::=x\k\ /(M,...,M) | () | {M,M) | Fst(M) | Snd(M) |





157

some







given Mi for 1



if jR C M



URcPthenRc

Fst(P),



if R C P then R C

Snd(P),



HR



iftfCMortfcAT then R

a raw

we

shall

subterm of

CM,



or

< i < n, if

R C Mi for at least

RCN then R C

(M, N),

xoiRcM then R C Xx: a.M, and C MN.

one

i then R C

/(Mi,..., Mn),

Chapter 4-

158

An expression of the form Xx:a is called subterm of

a raw

term

M,

occurs

in

x occurs

in

term

a raw

occurrence

M, then

subterm of M of the form Xxia.N. We say that



Type Theory

abstraction. If Xx: a.N is

an

say that N is the scope of the

we

abstraction Xx:a. If the variable if it

Functional



a raw

of the

is bound

occurrences

captured by the abstraction Xx: a. If the variable x occurs in M and is not bound, it is said to be free. If the variable x has at least one free occurrence in the raw term M, then x is said to be a free variable of M. In fact it will be convenient to give an inductive definition of the set fv(M) of of



in N

are

free variables of For the



?M<?

raw



a raw

terms x,

term M:

k, /(Mi,..., Ma)

see

123,

page

0,

.fv({M,N))d^fv(M)Ufv(N), MFst(P)) d^fv(P) and MSnd(P)) ^(P), ?



/v(Az:a.M)



fv(MN)



fv(M) \ {x},



and

fv(M) Ufv(N).

Example 4.2.4

Consider the M



raw

term

a.yx(Xx:(3.y(Xy:8.z)x).

A#:

The scope of the abstraction Xx:a is

yx(Xx:(3.y(Xy:8.z)x).

The scope of the

given by y(Ay: 8.z)x. The scope of the abstraction Ay: 8 is just z. The first and second occurrences of y in M, from the left hand side, are free, but the rightmost y is bound. All occurrences of x are bound. It is abstraction Ax:

very

important

(5

is

to note that variables

We shall say that

Discussion 4.2.5 if

they differ only

Xx:a.(x,y)

and

can

be both free and bound.

a raw

in their bound variables.

Xz:a.{z,y)

are

Xv:

a-equivalent example, the raw

term M is

For

a-equivalent. Also,

the

raw

to M' terms

term

a.yv(Xv: (3.y{Xu: 8.z)v)

Example 4.2.4. Note that in the raw term L (Xx: a.x)x the variable x is both free and bound; L is a-equivalent to (for example) (Ay: a.y)x. Any raw term M clearly determines an a-equivalence class for which M is a representative. We shall also refer to such an equivalence

is

a-equivalent

to the

raw

term M of



class

as



raw

term.

equivalence class a-equivalence as

From

determined

now

by "the renaming

on,

"the

raw

M. Note that

term M" will

we

mean

the

a-

could refer to the notion of

of bound variables." The

reason

for this odd

Definition of the Syntax

4-2.

technicality is not but to

provide

159

perversity



the part of the author to confuse the

on

framework in which substitution of



well defined. The definition of substitution of the x

in the

following

/(Mi,..., Ma)

When M is x,



<>[*/*]



(M, M')[N/x] d= {M[N/x],M'[N/x)).





term N for the variable

raw

M, through the

on

clauses:





terms for variables is

structural induction

by

term M is defined

raw

raw

reader,



k,

or

see

page 123.

<>?

Fst(M)[JV/x] d= Fst(M[AT/x]) and Snd(M)[N/x] d= Snd(M[N/x\). i (i) {Xx:a.M)[N/x]= Xxia.M.

|[

(ii)

(\y:a.M)[N/x] and

Xz:a.{M[z/y][N/x])

is different from



(MM')[N/x]





Note that clause



where



<£ fv{M) Ufv(N)

and y.

(M[N/x])(M'[N/x]). (ii)

simple renaming of the variable y to ensure that occurrences of y in N are not captured by the abstraction Ay: a when N is substituted for x. It is due to this renaming that substitution is only well defined up to a-equivalence, that is up to renaming of bound variables. amounts to

Work

Exercise 4.2.6



carefully through

the definition of

a raw

term

as an

a-equivalence class. Also make sure that you understand why substitution is well defined only up to a-equivalence. Think about which of the brackets in the definition of substitution are informal, and which are part of the formal syntax. A

Discussion 4.2.7 written distinct.

as





context is

[xi: a1?..., xn: an],

A term-in-context is

context, M is

a raw



term and



finite list of

where the variables

type. We shall

judgements of the form Sg > T h M: a we refer to Sg > Tl-M:aasa proved generated by the rules in Figure 4.1.

are

required

of the form T h M:

judgement a a

(variable, type) pairs, usually

now

define

where T h M: a is a

term.

Formally,

the





to be

where T is



certain class of

term-in-context;

proved

terms

are

Remark 4.2.8

(1)

It is assumed that both the

hypothesis

are

well formed. For

in the rule which introduces

is

implicit

that



example,

does not appear in

and conclusion of each of these rules

T, because T is

both the hypothesis and conclusion of the rule.





function type, it

well formed context in

160

i—

Function

Sg

x:a

T\-



():

unit

Symbols

T\-Mi:ai



Sg

T\-k:a



Sg

...



(k: a)

T\-Ma:aa

if' w

T\-f(Mu...,Ma):P



& —





<*a ->?

P)

Binary Product Terms Sg

Sg

T\-M:a



Sg

1—

\-

Unit Term

Sg

I—

T, x: a, V



Sg

1—

Type Theory

Variables

Sg

i—

Functional

Chapter 4-





T h

N:/3

T\-(M,N):ax(3

Sg



T\-P:ax/3

Sg

Sg



rhFst(P):a

Sg

> >

T h T h

P:a



(3

Snd(P):/?

Function Terms

Sg 5p





T,x:a\-F:(3

r h

Ax: a.F:

a =>

Sg /?



T\-M:a=>/3

Sg



Figure 4.1: Proved Terms Generated from

Sg



T\-

T\-MN:0



Ax-Signature.

N:a

Ax -Theories

4-3.

(2)

161

The terms-in-context which appear

M: a

form



as

part of the judgements Sg

sub-class of all of the terms-in-context; the formal



symbol Sg

T h >

indicating that r h M: a is in this sub-class, and reminds us that we are working with respect to the signature Sg. In practise, we shall just refer to a proved term T h M: a, when it is clear to which signature we are referring. is

Lemma 4.2.9 for

theories

are

still valid for the

Essentially

the

same as

algebraic

PROOF

The Lemmas 3.2.10, 3.2.11 and 3.2.12, and

Work

Exercise 4.2.10

for

through

proved

Proposition

3.2.13

terms of Ax-theories.



algebraic type theory.

the details of the

proof

of Lemma 4.2.9.

Ax -Theories

4.3



Discussion 4.3.1

and Ax is

Ax-signature

Xx-theory, a

collection

Th, is a pair (Sg,Ax) where Sg is a of equations-in-context. An equation-

M':ct where T h M: a and judgement of the form T Y- M r h M':ct are proved terms. The equations-in-context in Ax are called the M':a. The axioms of the theory. We indicate this by writing Ax > T h M M': a theorems of Th consist of the judgements of the form Th > T h M (where Sg > T h M: a and Sg > V V- M':a) generated by the rules in Figure 4.2. in-context is









give an example of a Ax-theory. Consider the Ax- signature Sg which has ground types nat and bool, and has function symbols: Example 4.3.2

We



tt:

bool,



f f:

bool,



C:



kni nat for each



S: nat

—?

nat,



P: nat

—>

nat,



Z: nat

—?■

bool, and



Ya:

=>

a)

bool, nat,

(a

nat

—*■

—*■



nat, G



now

N,

for each type

We then set Ax to consist of the ?

x:

nat, x': nat h

C(tt, x, x')



x,

a.

following equations-in-context:

162

I—

Chapter

1 Ax



TV- M



M':a

Th



T\-M



M':a



Th

T\- M: unit



T h M





():

unit

Binary Product Equations Sg



Th

T\-M:a

Sg

T\-Fst{(M,N))



Th

Function



Sg Th

M:a

T\-



T h



Sg



Snd((M,iV))

T h =

Th

Sg >

T\-



N:(3



P:ax/3



r,x:a\-F:fi

> >

Th

M:a=>

Th >

Sg

r\-(\x:a.F)M

Xx:a.(Mx)

Th





> =

(3

r h Ax:

a.F



F[M/x]:P (provided

M:a=>/3

T,x:a\-F

T\-M:a





& fv(M))

F':P

Ax: a.F'\

a =>

(3

Together with the rules for Equational Reasoning, Permutation, Weakening and Substitution as found on page 128.

Figure

N:p

P:ax{3

T\-(Fst(P),Sn4(P))



M:a

T h



Equations Sg

Th



T\-N:(3



Sg

I—



Equations

Unit

Sg

I—

Type Theory

Axioms

J I—

Functional

4.

4.2: Theorems Generated from



Ax-Theory.

4-4-

Deriving





x:

nat, x'\



V-

S(kn)





P(k0)





P(kn+i)







Z(k0)

tt,





Z(k?+i)



x: a

nat h







C(f f, x, x')



163

x'\

kn+i, k0,



=> a

Categorical Semantics



kn,

f f,

and

Ya(x)



x(Ya(x)).

One should think of this

theory

4-4

Categorical Semantics

having ground types the natural numbers and the booleans (where the latter is a two point set which indicates truth or falsity). The function symbols are to be thought of as truth, falsity, a conditional test for two terms, numerals, a successor operation on the natural numbers, a predecessor on the natural numbers, a test for zero, and a fixpoint operator. We shall see how to give a semantics to this theory later on.

Deriving

Discussion 4.4.1



as

The

categorical semantics which we gave to algebraic theories in Chapter 3 was strongly motivated by traditional set-theoretic semantics. In this chapter we give a semantics to Ax-theories. Some readers will know that this syntax can be modelled in cartesian closed categories. However, we shall present a uniform analysis of the syntax and rules of Ax-theories to discover what, in categorical terms, is the most general interpretation. As discussed in Chapter 3, types will be modelled by objects in a category. In a Ax-theory, the types are specified by giving a collection of ground types, and then constructing further types from the ground types using the type constructors x and =>-. The interpretation of a type a x (3 will depend on the interpretations of a and /?, and similarly for the function type constructor. The proved terms will be interpreted by morphisms in a category, and the assumption that the theorems are soundly interpreted will then determine equations which hold between morphisms. In the cases of binary product types and function types, we shall see that the equations between morphisms will determine the objects which model the types up to isomorphism. Finally, recall the basic assumption that all of our syntax is interpreted in a category with (at least) finite products: products are used to model the list of types which appear in contexts. Let a

us

suppose that

we are

given



Ax-theory

Th

(locally small) category with finite products. First



(Sg, Ax)

we

and that C is

consider the types of

164

Functional

Chapter 4-

Sg. We have

Type Theory

object [7] of C to interpret each of the ground types 7, and an object \unit\ to interpret unit—for the moment we cannot say anything more specific about {unit]. We will assume that the interpretations of binary- product types a x /? and function types a => /? depend on the interpretations of a and (3. So there should be operations in C which give objects AD B and A 0 B for all objects A and B so that we can define [a x 0\ d= [a] □ [/?] and [a =? /?] [a] 0 [/?]. Having done this, we can now choose a morphism x (3 of [/]: [ai] x [an] [/?] in C for each function symbol /: ai... an Sg. Now recall that the interpretation of a proved term r h M: a is given by a morphism [rhM:a]:[r] [a] in C; see page 133. At the moment we do not know how to define such an interpretation, but by looking at how to soundly interpret the terms and equations of Th we will deduce how to do this. give

to

an



—?

...

—*■

—?

Let

us

think about the rules of formation of

assuming just

hypothesis.

one



typical

Sg

Sg where

R(M)

is

a new raw

Now suppose that do

model

we

[r



(R)

T\-R(M):p is



depend

on

(think of R as Fst, for example). an element of C([r|, [a]). How



depending on

will

general,

rule looks like

[r h M: a] which R(M):/?] G C([r], [/?])?



morphism

that this latter

having



term

terms in

T\-M:a

> >

proved

All

we can

m, and

say at the moment is

we can

model this idea

by

function

*w.Mjn:C(in.W) —c(pi,D8|) and

setting [T

terms

old any



R(M):/?]



^>[al,[/3],[r](^)-

Now think about how the

raw

formed. The crucial point is that new raw terms are formed from terms by substitution; and we can easily see that a derived rule for

are

raw

Ax-theory

is

Sg



x:

7 h M:

Sg Suppose

that





Sg



y:

7'

h N: 7

y:j'\- M[N/x]:a

and y:

7'

h AT: 7

(Sub).

given proved terms. Using our basic assumption that substitution is modelled by composition of morphisms, if m [x: 7 h M: a] and n {y: 7' h N: 7] then we will assert that [y:7' h M[N/x\:a] =mon. Applying each of (Sub) and (R) in turn, we deduce that there are proved terms x:

7 h M:





y:i

\ ̄

R(M)[N/x\:(3

are

any two



and

y:7'



R(M[N/x\):0.

4-4-

Deriving

However,



both of the above

definition of

165

Categorical Semantics

substitution),

raw

syntactically identical (by the categorical interpretations should

terms should be

and therefore the

be the same, that is

¥M,lfl,M(m)

on

(*)

The astute reader will notice that in fact

every

we can

object



¥l<*Wlb'}(m n)-

¥a,b : C(-, A) We

can

I—

Categorical Modelling

summarise these

thoughts



naturality condition; demand the following. For

looks similar to

be certain that it will hold if

A and B of C there is

(*)

°

we



natural transformation

—>

C(-, B):C

in the

—>

Set.

slogan:

of Term Formation

categorical interpretation of the notion of term formation amounts to requiring that certain naturality conditions hold in the categorical model. The sound

Let

us now

First

think about

specific types

and terms.

deal with the type unit. There must

always be a morphism u0 [T h (): unit]: [T] [itra£]. Looking at the Unit Equations, z/this is to be soundly interpreted, then whenever there is a morphism m [T h M: a] in C, we must have m uq. All this amounts to saying that for every object A of C, there must exist a unique morphism !: A [unit], that is up to isomorphism \unit\ is a terminal object 1 ofC. we



—?





—?

Recall that the rule for

introducing product

terms is

T\-N:(3

T\-M:q

T\-{M,N):axP In order to

soundly interpret

this rule

*** : C(-, A)



we

shall need

C(-,B)

for all

—>



natural transformation

C(-, AD B)

A and n: C B be morphisms objects A and BofC. Now let m:C of C. Applying naturality in C at the morphism (m,n):C->AxBwe deduce —?

{?A,B)c(nA{m,n),irB{m,n)) that is

(¥.4,b)c("^?)

morphism qA,B- A











—*

{^a,b)aub{^a^b)

°

(m,n),

{^a,b)aub{^a->^b) ° (m,n). Now let us define the ADB to be (¥a,b)axb{ka,^b)- Then we can make

166

Functional

Chapter 4-

Type Theory

the definition

IT\-(M,N):ADB]

(F'-'M.in-Mfl)

PI Recall

one



of the rules for



M *?l



wDM.

eliminating product types T\- P:ax

(3

n-Fst(P):a Arguing

as

above,

to model this rule

^a,b'-C(—,A

natural transformation

we

£)



lemma, namely Lemma 2.7.4. With this,

—?

may deduce that

we

[C* Set](HADB, HA)

(for each A and B) a C(—, A). Recall the Yoneda

shall need



C{A □ B, A) ¥a,b corresponds

which is to say that each natural transformation

morphism Pa,b'A □ B components of

¥>i,b

to



unique

A.

Moreover, the Yoneda Lemma says that the given by (¥a,b)c C(C,pa,b)- So now we can define

—?

are



[F h Fst(P):a] *f m

[rhP:QX/?l

[a]



[/3] ^Hl [aj.

proved terms of the form r h Snd(P): (3 in much the same way, involving a morphism p^ B: A D £ —? B. Our last task is to see what information we obtain by soundly interpreting the equations-in- context for product types. These are Of course

we can

TY-M:a T h

deduce



semantics for

T\-M:a

T\-N:0

Fst((M, N))



M:a

(1)

_.

T \-

T\- P:ax T h If

we





(Fst(P),Snd(P))

put /i d=

P:a

[r

—*■



[r h N:0\:C



/?]:C

->



.??

.^

Snd((M, N))

(3 =

A D

B, and demand that





our





[T



M:a]:C

PA,B°<lA,Bo(m,n) qA,B°{PA,Boh,pA,B°'h)

-?

A and

categorical interpretation

satisfies the equations-in-context, this forces

PA,B°qA,B°{m,n)

(2)



N:0

(3)

P:ax(3 B,

T\-N:0





(1)





(2)





(3)

4-4-

Deriving



167

Categorical Semantics

done, because these equations imply that, up to isomorphism, ADB and Ax B are the same. Thus we may soundly interpret binary product types by binary categorical product. At last

we are

Now

To

we

shall

resume

the

investigation of the semantics of function types.

the introduction rule

soundly interpret

T,x:a\- F:P T h Xx: a.F:

(for

shall need

we

every

object

<f>AB:C(- and

we can

[T To

B)

A and x

A,B)

/?

a =?



—>

natural transformation

C(-,A0 B),

then define

h Xx: a.F:

0\ 1* (*W,|fl)[n([r,x:a

a =?

h F:

fl) PI -

(H 0 [/?])?



the elimination rule

soundly interpret

T\-M:a^(3

T\-N:a

T\-MN:p we

shall need



natural transformation

#A,B: C(-, A 0 B) for all n:



—?

objects A and

7r:

applying naturality,

(A 0 B)

morphism

[r

evA,B

h MN:

[PI

C(-, A)

A and B of C. Given any two

{^A,B)c{m,n) where



x =



—?



we

At) B and

{yAyB){AOB)xA(n,ir') (ra,ra) °

A 0 B and tt':

(A{)5)xA->A

{^a,b){aob)xa{^^'),

we can

So if

we

define the

make the definition

(ja] , [/3])

T\-M:a =

(4)

F[M/x}:(3

categorical interpretation

must have

—?■

have

(IT HM:a->fl,F ■-*:<■])

T\-(Xx:a.F)M we

m:C

0\ d=

T,x:a\-F:(3

our

C(-, B)

morphisms

The equations-in-context for the function type

If

—?

is to

evA,B((?A,B)c(f), ?)





,a, ifMfl j,,.

are

T\-M:a^(5 :r—

T h

satisfy



Xx:a.(Mx)



M:a

=>

(3

the equation-in-context

f{id, m)

for all

(4),

morphisms /: Cx A

(5) then —?



168

Functional

Chapter 4-

and m:C holds

A.

—*■

in

just

Using

the

naturality of ¥a,b

Satisfaction of m:C

(5) requires

that

A() B and from

—?



we

to the crucial

come

id)



equation

/?

(*)

(¥a,b)c{cv^^^(m x IcIa)) the naturality of ¥a,b this



(¥A,B)AOB{evA,B) Now

show that this

case

evAA(?A,B)c(f) phism

w^ can

Type Theory

point.

If

we



for every

holds

just

in

mor- case

(t)

id.



define



natural transformation

0:C(— xA,B) C(-,A§B) by setting 0c{f) evAyB°(fx id) the equations (*) and (f) imply that 9 is a natural bijection. Thus, up to isomorphism in the —?



category C, the object A§ B is exactly the exponential A => B and of course £Va,b- (A (} B) x A —? B is the evaluation morphism, and such categorical structure will

soundly interpret function types.

Remark 4.4.2 C

was



—*■

Recall that in Section 4.4

we

assumed for convenience that

In fact it is

small.

possible to apply very similar arguments when C is not locally small by considering a suitable system of set theory with universes, and modifying the Yoneda Lemma appropriately. We could also replace each of the natural transformations between functors of the form

locally

(that

Set

is functors with

functions etc'- FC

—?■

GC which

elementary naturality equation

product

Work

through

"natural in C"

indexed collection of class

meaning that

an

obvious

holds for each component etc-

the details of the derivation of the semantics of

Be careful

types.

are

an

With reference to Section 4.4:

Exercises 4.4.3

(1)

target Set) with

binary

to understand the crucial fact that because the

deriving proved terms and performing substitutions commute, the procedures of deriving a proved term can be modelled in an appropriate categorical structure by operations which are natural in their arguments. procedures of

(2)

Work

types. In

through the details of the derivation of the semantics of function particular, prove the equations (*) and (f) hold using naturality of

¥a,b.

4-5

Categorical Semantics

Discussion 4.5.1 cartesian closed

We formalise the discussion of Section 4.4.

category and let Sg be

for Sg in C is specified by giving:



Ax-signature.

Then



Let C be



structure, M,

4-5.

169

Categorical Semantics



For every



for every constant function

[a] ?

ground type

is defined

below),

for every function

Sg

7 of

an

object [7] of C,

symbol

k: a,



[&]

element

global

[a] (where

of

and

symbol /:

ai... an

ft of Sg with

—*■

non-zero

arity,

a mor-

phism lf\:[ai] x...x[aB]-[fl, where

define

we

[unit] d^f 1, [a is



[a] for an arbitrary type a via structural induction, setting /?] ^ [a] x [0] and [a =? /?] d= [a] =? [/?] (and of course [7]

given).

Given



context T

for every

proved



[x\: ai,..., xn: an]

term T h M:a

we

we

set

shall

[r]

use



[ax]



...



[an].

the structure M to

Then

specify



morphism [TI-M:a]:[r]-[a] specified inductively using the rules for introducing proved terms and the definition is given in Figures 4.3 and 4.4. It is easy to see that substitution of terms is modelled by categorical composition of morphisms. We have in C. The semantics of

proved

Let r" I- N:

Lemma 4.5.2

terms is

(5 be



proved

and let T h Mi'.ai be T h

N[M/x\: (3 [r

where





proved terms for i proved term and further

N[M/x]:p]

AT[M/x]

PROOF

is

By

term where r'





[r'

h N:

0\



([r



1 to

n.



Then

[x\: ai,..., xn: an] one can

show that

that

Mx: aj,..., [V h Mn: aj)

denotes simultaneous substitution.

induction

on

the derivation of the

judgement V h N: j3.

Exercises 4.5.3

(1)

Look at the details of the

understand the ideas of such

(2)

Work

through



categorical

semantics of Ax-theories and

model.

the details of the

proof

of Lemma 4.5.2.



170

I—

Chapter 4-



[r, x: a, T



x:

a] d=

tt:

[r]

[a]



[T]





[a]

->

Unit Term



(where



{T \-{): unit] I—

Type Theory

Variables

| I—

Functional

Function

=\:

IT]

^1

Symbols



[Tr-fe:al



[*]o!:|ri->l->W

[ThM1:a1l=m1:[ri->[ai] [r



object of C)

1 is the terminal

/(M): /?]



[/]



[T

...

(ml5..., mn): [r]

h -?

M?:a?] ([aj

mn:





...



[r]

[aj)

-? -?

[aj [/?]

(/:<*!,..., <*?-?/?) I—

Binary

Product Terms

[r \-M:a]= [r



m:



jT]

(M, JV): a



->

0\

[a] =

[T \-N:0\

(m, n>: [r]



->

n:

([a]

jT] x

->

[fl

[/?])

[rhP:ax/?J=p:[rj^([aJx|[/?]|) [r



Fst(P): a]



TTi op:

[r] 4([a]x [/?])

->

[a]

->

[/?]

[n-P:ax/?]=p:[ri^(Mx[/?])



[r

I-

Snd(P):/?]



tt2 op:

[r]

->

([a]



[fl)

Figure 4.3: Categorical Semantics of Proved Terms Generated from Signature.

| a

Ax-

Categorical Models and the Soundness Theorem

4-6.

I—

171

Function Terms



[r,i:ahF:^]=/:[r|x[aHM [r

h Ax: a.F:

a =*

/?]

A(/): [r] ->([<*]=>? [/?])



[ThM:a^/?]=m:[r]->([<*] =?>[/?])



[r

h MiV:

/?] 1*

Figure 4.4: Categorical Signature, Continued.

et; o

(m, n): [r]

[T

([a]

->

h JV:

a]

[fl)

=?



[a]



[T]

n:

[a]

-?



[fl

->

Semantics of Proved Terms Generated from



Ax-

Categorical Models and the Soundness Theorem

4-6

Let M be

DISCUSSION 4.6.1



structure for

Ax-signature



in



cartesian

M'\ a we say that equation-in-context r h M M satisfies the equation-in-context if [T h M:a\ and [r h M': a] are equal morphisms in C. We say that M is a model of a Ax-theory Th (Sg,Ax) if M satisfies all of the equations-in-context in Ax. We shall also speak of M satisfying axioms and theorems. We will prove a soundness theorem for closed category C. Given

an





Ax-theories after the

following example:

We shall

Example 4.6.2

give



model for the

page 161. Consider the

category cjCPO±, which is

and whose

those cjcpos which have

objects

are

easy exercise to check that structure M in ujCPO

{£, /}

with

for each



f G



N, where

this c^cpo the and

{*}

t, and

flat

ujCPO± is



by setting \bool\

{naij n





natural numbers.



bottom element.

Q, where Q, is the

G N are

Let

for the terminal a;cpo. We then

the function



us

incomparable

sending



to t.



[ff]: {*}

—?

B is the continuous function

sending



to

N is the continuous [C]: B x N x N (t, m, n) to m and (/, m, n) to n. —?



[S]: N

—?■





and n.







We call

to

symbols: B is the continuous function

—*?





give the following interpretations

—?

[kn]: {*}

give

write B and iV for these a;cpos,

[tt]: {*}



if

an

Sierpinski poset

with order _L <





It is

cartesian closed category. We

{_L, 0,1,2,3...}

G N and



Ax-theory Th given on full subcategory of cjCPO,

function which for all m,n G N sends

N is the continuous function

iV is the continuous function

/.

sending

sending





to

to



n.

+ 1.

172

Functional

Chapter 4-



[P]: N

—?

N is the continuous function

sending





[Z]: N

—?

J3 is the continuous function

sending

0 to t and



IYa]: (M

M is the continuous to VnGN/n(-L) where a element of [a].

W) /: [a] [a]

function

=>■

is the bottom

Exercise 4.6.3 a

essentially immediate from model of Th. Verify this fact. Let C be

Theorem 4.6.4



cartesian closed

model of Th in C. Then M satisfies any



is any

It is

structure M that it is



function

—?■

—?■

+ 1 to

Type Theory

and 0 to 0.





/.

+ 1 to

sending



continuous

type of 77* and _L



[a]

the definition of the

category, Th

Ax-theory and equation-in-context which is a a

theorem of Th. We need to

Proof

[T

a]

I- M:

and

[T

by demonstrating

that if T h M

see

h M':

a]

M':



equal morphisms

are

is



theorem of



in C.

This

and



give

one

Function

[r



of this. Let

example

d= [r \-M:a]: [T]

(Case

[a]. Then Equations): -??

(Ax:a.F)M:0\

where the last step follows Exercise 4.6.5

Work

by

/ d= [T, x: a

we

h F:

given on hypothesis of the

/?]: [T]



[a]

eu(\rv-\x:a.F:0\,[T\-M:a])



ev(A(/),m>



ev(X(f)



f{id,m)

an

through

-?

[/?]

have





Theorem

be shown

can

that M satisfies the conclusion of any of the rules

page 162 if M satisfies any theorem which a*ppears in the

rule. We

Th, then



id)(id,m)

lT\-F[M/x):p]

application



of Lemma 4.5.2.

remaining details of the proof of

the

4.6.4.

4-7

Categories of Models Recall the discussion in Section 3.7 in which

Discussion 4.7.1

the category of models of an

namely between

Aiod(Th,C), categories

similar story in the

algebraic theory

in



case

defined

category with finite products,

and the category of finite

with finite

we

product preserving functors products, namely TV{£,,!}). Let us consider a

of functional type theories.

4.7.

173

Categories of Models

We describe

approach which mimics Section 3.7. Given that both C and V are cartesian closed categories, we define the category OOCat(C,V) to have objects which are cartesian closed functors, and morphisms which are natural transformations. It easy to check that this definition makes good sense. We shall now give one possible definition of homomorphism of models M and N of Ax-theories (in a cartesian closed category C, say). A homomorphism h: M N is specified by giving a collection of morphisms ha: Hm Hn f°r eacn type a, called the components of h, which commute with the interpretations of the function symbols (just as for algebraic theories—see page 137), and in addition the components of h commute with the interpretations of the syntax for binary product and function types, by which we mean the diagrams an

—?■

—*

Hm







Hn



7T

Hn

ha

=>

IP]m)



Hm

nj

/inj

*JM

7i

n?[7f]N (m', n')

(m, n)

7T

a] M (Hm



Hm

k{a*0)XQ>



[/?]M

hQ x/3

(Hn



Hn



[flN

)xH N

ev

ev





n?W M

/lnn7.

n?b]N

Hf) Hm

=?

A(/) Mm

la=>0

<*]n

=?

Mn

morphisms m, n and /. Then the category of models of Th in N C, Mod(Th,C), has objects which are models M, and morphisms /i:M are model homomorphisms. We would like to be able to show that for a given Ax-theory Th, we can find a category Cl(Th) such that for all cartesian closed categories V there is a natural equivalence commute for all

—?

ApG : COCat(Cl(Th),V)



Mod{Th,V)

modelling functor ApG similar to that defined for algebraic theories. N of Th in V should be Under such an equivalence, a homomorphism h: M

given by



—?■

174

Chapter 4-

sent to



natural transformation <£: M

Cl(Th),

for each

object

One

check that (f> is not

can

of



</>a



naturality of'<f>

in

an

(z: 7 I

object

Xx:



V where

—?■

/ia. But there is

(necessarily)

Prove that (f> is not

Exercise 4.7.2 consider the

and

Cl( Th)

iV:

—>

Functional





Type Theory

M(a)

problem



[ckJm

with this.

natural transformation.

natural transformation. Hint:



of Cl(Th)

a.M): 7

—?

(a

=>

at



morphism

/?).

simple example of a Ax-theory Th, a category with finite N of models M and N of Th in V. products V and a homomorphism h: M Do you think the components of the homomorphism h should be determined by those at ground type?

Try

to think of



—?

We

problem of Discussion 4.7.1 by giving a slightly more restricted notion of homomorphism of models of Ax- theories. This will still enable us to give a very general definition of classifying category, and will mean that the components of homomorphisms are determined by those at ground type. Let Th be a Ax-theory, C a cartesian closed N of category, and M and N models of Th in C. A homomorphism h: M models of Th in C is given by Discussion 4.7.3

can

deal with the above

—?■





collection

/i7: [7]m

-*

Mn

of

isomorphisms

in C for each

of

ground type

Th, such that ?

the component of h at



ground type

function types the components

/i7,

7 of Th is

and at

product and

def

def





ha x hp and hQ=>p given by haxp h ̄l => hp, and the components of h are required to commute with the function symbols of Th. With

are

of models Mod*(Th,C) to have objects the models of the Ax-theory Th in C, and morphisms homomorphisms of models. Also, let C and V be cartesian closed categories and write OOCat^(C,T>) for the category with objects which are cartesian closed functors C V, and morphisms natural isomorphisms. We now need a little more machinery to set up a natural equivalence between these two categories. this,

we

define the category

—?

Suppose that

we are

V. We shall define







morphism of cartesian closed categories

F: C

—>

functor

F* Let M be

given

:Modc*(Th,C)

model of Th in C.

ground type of Th, then

we can

If

we

—>

Mod ̄{Th,V).

define

[7]f.m

show that there is





-^Hm

canonical

where 7 is



isomorphism

4-8.

Classifying Category of

175

Ax -Theory



[a]f,M ^[qiJm where a is any type of Th. Then the model F*M is given by [7]f.m ^Hm on ground types and [/]f.m is given by the composition =



[<*i]f.m





...

[an]F.M



F(Mm



F[an]M =' K]M) Fj^ F\0\M S [/?]f.m

F[ai]M ...





...



/? is a function symbol of 77i and =' arises from F /:ai,...,an preserving finite products. The homomorphism F*h has components at ground type 7 given by (F*/i)7 F(/i7). We need one more piece of machinery to set G be a natural isomorphism between cartesian up our equivalence. Let <f>: F closed functors. We can define a homomorphism </>*M: F*M G*M of models of Th in C by setting (<^>*M)7 ^Mm, where here 7 is any </>[7jM: ^[tJm ground type of Th. where

—>



—?■

—?

—*■



Write out

Exercise 4.7.4



which shows that F*M

proof

defined model of Th in T> and that F*h

Verify

that

</>*M

is



is



homomorphism. Let C and V be fixed cartesian closed categories, and let

Discussion 4.7.5 M be any model of

really

really is a well homomorphism of models.



fixed

Ax-theory

Th in C. We define



family

of

modelling



G is any

functors

ApM:GQCatc*(C,V) by setting ^4pM(F)



-?

Mod ̄(Th,V)

F*M and ApM(<f>)

</>*M, where <f>:F



isomorphism between cartesian closed functors. It is the notion of modelling functor which we shall use in the next section to set up an equivalence between categories of models and categories of cartesian closed functors. natural

4-8

Classifying Category of

Discussion 4.8.1 as a



classifying category

cartesian closed category which is in

in which Th



Ax

for



-Theory

Ax-theory

some sense

can

be

thought

of

the smallest such category

classifying category arises through a formal construction using the syntax of the theory Th. The reader should compare this section with the idea of a freely generated vector space or group on a given set—compare the set to the Ax-theory Th and the freely generated gadgets to the classifying category—in just the same way as for algebraic theories. can

be modelled

soundly.

We shall

see

later that the

Ax-theory. A cartesian closed category Cl(Th) is classifying category of Th if there is a model G of Th in Cl(Th) Let Th be



called the

for which

176

Chapter 4-

Functional

Type Theory

given any category V with finite products, the functor

ApG:GCCat ̄(Cl{Th),V)

Mod ̄{Th,V)

—?

equivalence. Such a model G will be called generic and its corresponding modelling functor the generic modelling functor. We shall see that such classifying categories are unique up to equivalence and that they play the role described at the start of Discussion 4.8.1. The following result is proved in the same way as for the corresponding results in Discussion 3.8.1. is

an

Let Th be

Proposition 4.8.2

category for which there is any cartesian closed



an

Ax-theory and Cl(Th)

model G of Th in

category V there is

ApG:GCCat ̄(Cl(Th),V)

an

that

given

Mod ̄(Th,V).

—?

that whenever

case

Cl(Th). Suppose

equivalence

Cl(Th)' and equivalence Eq: Cl(Th) Cl(Th)'

Then it is the there is

an

cartesian closed





G' also have the above property

for which

Eq*G



G'.

It follows that for any model M of Th in a cartesian closed category C, there is a cartesian closed functor F: Cl(Th) —*■ C for which the composition of

given by the generic model G in Cl(Th) with the functor F yields the semantics given to Th by the model M, up to isomorphism. This may be seen pictorially as

the semantics of Th

rn,

Th



^ -

V where F*G

Moreover, PROOF

Corollary

any two such functors F

The

proof is essentially

are

the



M.

naturally isomorphic.

same as

for

Proposition

3.8.3.

3.8.2 and D

The fundamental idea of the

categorical type theory correspondence is the same as that for Chapter 3. However, because we model syntactical contexts by finite products, when we constructed the classifying category of an algebraic theory we had to construct finite products directly (by showing that juxtaposition of contexts gives rise to binary products and the DISCUSSION 4.8.3

empty context to of



terminal

object).

In the

case

of Ax-theories the presence

binary product types and a unit type makes the construction of a classifying category with finite products a little simpler. We have the following theorem:

4.8.

Classifying Category of

Theorem 4.8.4

We

construct

can





Every Ax-theory Th has a classifying category Cl(Th). canonical classifying category using the syntax of Th.

The construction of

PROOF

177

Ax -Theory

Cl(Th)

be

can

simplified

the construction given for the classifying category of

in

some

respects from

algebraic theory. We had to define finite products in the classifying category of an algebraic theory by using concatenations of finite lists of types. Our syntax now has binary product types and a unit type and we can use this fact to define finite products in the classifying categories of Ax-theories. objects of Cl(Th) The morphisms of Cl(Th) The

an

exactly the types of the Ax-signature of Th. are, roughly speaking, equivalence classes of raw terms with at most one free variable where the equivalence relation is given by provable equality in Th. More precisely, a morphism a —? (5 is an equivalence class raw

(x: a \ M)

term for

are

pairs of the form (x:a, M) where x is a variable and M which Sg > x: a h M: /?, with equivalence relation of

(x:a,M) ̄(x':a1M')

Composition

iff

Th



x:a h M



M'[x/x']:(3.

morphisms is given by raw term substitution (as classifying category of an algebraic theory) and the identity on a (x:a | x). of

Given two



for the is

given by

/?, the binary product consists of the object ax/? is given by together with suitable projections. The projection 7ra: a x (5 (z: a x 0 | Fst(z)) and the projection irp is defined likewise from Snd. If we are and (y.'y \ N):j (3, then the given a pair of morphisms (x:j \ M):^ mediating morphism is given by objects



and

—?■

—?

—*■



(2:7 I (M[z/x],N[z/y])):j We leave the reader to check that

(x:a I ()) is for Cl(Th). Now

the

unique morphism

we

—>

unit

so





j3.

binary product, and that that unit is a terminal object

have defined

a —?





exponential of objects /? and 7 is given by (3 => 7. Given a morphism (z: a x (3 \ M): a x (3 7 the exponential mate X(z: a x j3 \ M): a —? {(3 => 7) is given by we move

to the cartesian closed structure. The

—*

(x:a I \y:P.M[(x,y)/z])

(for which term).

we can

show that

Sg



x: a h

We leave the reader to check that

structure for

Cl{Th).

Xy: /?.M[(x, y)/z\: (3 we have specified a

=> 7

is



proved

cartesian closed

178

Chapter 4-

The generic model G of Th

[7]



ground type (5 /: a1?..., an

7 where 7 is any

a).

for any type

arity



If

is

—*■

function

symbol of Sg

with

(... ((ai x a2) x a3) x ...) x an and where Projn(z) Snd(Fst(z)) and so on. Certainly we have





Sg

Finally, To

[aj





non-zero

if k:



[fc]

then

complete

the

proof we

need to show that the —?

Mod ̄(Th,V), —>F'



4>*G: F*G

Cl(Th). Let us define the functor Ap^ Mod ̄(Th,V). We define Ap^M: Cl(Th)

-?

: a —?



Ap^M is a cartesian closed functor.

Aiod*(Th, V).

We

can now

Ap^N by setting the (Ap^h)a /ia: [o]m =

natural

transformation, the diagram

h M:

[<*]n-

an

We have to

that is for each

can

for all



follows. Take

sense —?

an

by M-

and it is easy to

N be



morphism of —>

see

that this does indeed define

morphism (x: a \ M):

[x: a "



a —?

(3

in



Cl( Th)

Mn

0\M

do this



Let h: M





commutes. We



generic

isomorphism Ap^h: Ap^M object a of Cl(Th) to be given by

<*]m

[x: a

as

define the natural

components at -?

F^G

[x:ah M:0\M : [a]M

l—-

The soundness theorem says that the definition makes

that

—>

where G is the

model of Th in

(x:a J M)

functor

modelling

equivalence for any cartesian closed category V, M in

Snd(z),

(a;: unii | A;).



4>:F

object



z:IIJa£l-/(Proj1(z),...,ProjB(z)):j9.



ApG : COCat ̄{Cl{Th),V)

see

given by defining

hence it follows that

Sg (and a

is

[/] *f (z: IIJc* I /(ProhCz),..., Projn(z)))

U^ai Projn_1(z)

an

of

Cl(Th)

in

Type Theory

then



where

is

(Sg,Ax)

Functional

h M:

/?]N

IPJn

by showing that

M:/?]N

proved terms r h M:/?, T. We shall give just one case.



hr



where /ip

h0 =



[r



x"/iai

M:/?]M and the types o^ appear in

4.8.

Classifying Category of

(Case



179

Ax -Theory

Xy:(3.M:(3 =? 7): proved term, then so is T, y: /? h M: 7. By the the following commutative diagram r h

M:(3

[T]M 771

If T h

is T h

^-^

[0]M



\y:(3.M:(3 ^ 7 is a induction hypothesis, we have

[T]N

[/?]N



def





[r,y:^hM:7]M

hy

h ̄iom

o m o

Our aim is to prove that is

Mn



/i7

in the category X>, that is

(id

(/i^1

o ev o





=>

(id

m!



fy^1)

/i7)



(hT





m'

A(m)



/i^),



(/ir



hg1)) A(m) o



id). o

(2) by showing

exponential ev o

that

ev o

that both I and

hr)



A(m'

([A(/i7





id)

(/ir

o ev o





(id

evo

id)) x

(A(m/) A(m')



to





id)



m!



hr

r, and

we

have



h^o /i7

(/ir







(/ir



id)

id)



ev o

o mo

/i^1) (X(m) (id x/i^1) (id







id)

that

A(/i7 o m o (id It follows from

e :

certain derived

equal

r are

id)



/i^1)) A(m)] =

To

(2)











implying

for



mate. We have

((A(m/)

implying

(1)

/ir, which by definition

A(m')









A(m/)



equivalently

or



We shall prove



[r,y:/?h-M:7lN

Mm

A(/i7

def



(1)

complete

ApGApGl

We define

that I

the =

h^1))





proof

r.

we



A(/i7 o

ev o

(id



The other inductive

need

idjuod^Thj))

we

/i^1)) X(m) o

cases

77:

/.

proceed similarly.

need to define natural

and



idanaS!(ci{Th),v)

isomorphisms



ApGlApG.

by taking a model M of Th in V and giving the component cm'- ApG(ApG1TS/L) M, and we can define this homomorphism by giving its components at a ground type 7 of Th. Working the details we see that ( m)7: [t]m [t]m5 and we take this to be id[7jM, certainly an isomorphism. V, and noting that Similarly, given a cartesian closed functor F: Cl(Th) Fa. This APg^ApgF)^) F([a]G) Fa, we define (r)F)Q d= id: Fa D completes the proof. e

—?

—?■

—?





-?

180

Chapter 4-

Functional

Type Theory

Exercises 4.8.5

(1) Why

is the soundness theorem crucial to the definition of

(2) Verify a

natural

some

of the

ApG(Ap'^'M.)

Proposition

category C and



isomorphism) =

proof

that

Ap^h

homomorphism of models—take





Th in

Ax-theory



cartesian closed

C, there is (up

Cl(Th)

—?■

to

C for which

Ap^M.—see



verify

that

essentially to apply the structure [—]m- /3. Then symbol /: a1? a2

For

page 178.

It is routine to

M. The action of F is

[/]f.g

consider

[z:ai

—?■





{[z: ai

/(Proj^Proj^z)):/?]^ x

a2 h

Fst(z): ai]M, [2: ^XQzh Snd(z): a2]M)

[/]Mo(7r,7r')



[/]m.



FiG

x a2

[/]m



Suppose

function



F(z:a!xa2 I/(ProJiW.ProJaW))





which



satisfies the

Given

strong way.



cartesian closed functor F:

unique



classifying category

4.8.2 in

model M of

Define F

example,

that there is another cartesian closed functor F': =

M. If

is



Fa

an

of

object

d^f [a]M



Cl(Th)

Hfig



Cl(Th)

—?

C for

then

F'Wg



F'a

because F' preserves finite products and exponentials, and this gives rise to natural

isomorphism

Exercise 4.8.7

^.P

is

M.

Proof F*G

M is

—?

The canonical

universal property of

F*G

in the inductive

with this.

Corollary 4.8.6

canonical

occur

isomorphism.

(3) Verify that cm". care

which

cases

Ap^?

T/ie





F'.

Prove that F



D =

F' in

Corollary

4.8.6.

Categorical Type Theory Correspondence

Discussion 4.9.1

We aim to show

Ax-theories and cartesian closed

that,

in

a sense

to be made

precise,

categories are essentially the same. First we show that any cartesian closed category C gives rise to a Ax-theory Th(C) in a very simple way, and then show that this process is mutually inverse to that of constructing a classifying category of such a theory.

The

4-9.

181

Categorical Type Theory Correspondence

For every cartesian closed category C

Theorem 4.9.2

particular Ax-theory, Th(C) Th(( the Ax-theory Th{C) in C.



(Sg(C),Ax(C)).

There is

we can

associate



canonical model of



Ax-signature Sg(C) has ground types which are copies of the objects of C and function symbols which are copies of the morphisms of C, together with some distinguished function symbols which will witness certain isomorphisms. More precisely, for each object A of C there is a ground type A. The types of Sg(C) are therefore given by a grammar PROOF

The

a ::=



unit







""x"1







r=^ ̄l



object of C, and the notation rxn simply distinguishes formal binary products of Sg(C) from binary products x in C (and similarly for =>). For each morphism of the form k: 1 A in C there is a constant function x An B in C symbol k: A, and for each morphism of the form /: A\ x there is a function symbol /: A\,..., An B. There are also function symbols, each of arity 1, with the following sortings: where A is any

—?■

—?

...

—?



JQ: [a]



JQ:



a, and

—?

[a]

—?

[a]

where

is defined below.

(Here,



runs

over

all types of

Sg(C)). A for Sg(C) in C is defined by setting [A] each ground type of Sg(C), [k] k, [/] / and [Ia] [Ja] id[a]. (Note def def that by definition we have [a rx^ (3\ [a] [a] x [/?] and [a r=^ /?] see Discussion 4.5.1). The canonical structure M for







it



ir /yn





it

i-





 ̄i

/?ti



The collection of axioms

Sg(C) Th(C) in

generated from

which

model of

C.

THEOREM 4.9.3

We write

A of C and

[-]

that M is indeed

—*

to the canonical model M of



Eq.V

—?



Th(C)



the

in C.

C, and V for Cl(Th(C)). C is defined by Eq(a) [a] on objects and

for the model M of

We define

Eq ̄1(f)

means

equivalence of categories Eq: Cl(Th(C)) category C, where Eq is the functor arising from

Eq ̄x:C

Th(C)

in



Eq(x:a | M) morphisms.

M. This

an

Cl(Th) applied

Recall that the functor

on

by

equations-in-context □

for each cartesian closed

PROOF

consists of those

satisfied

are

There is

universal property of

Ax(C)



—?

(x:A\ f(x))

def =

V at

[x:ahM

by setting Eq ̄1(A) any morphism /: A



—>

A at any B of C.

object

182

Chapter 4- First

e:

Eq



we

Eq ̄x



show that —?

EqoEq idc and v\ idc

—¥

Eq

eA



vA It is trivial to

that

see

ev



idc- Let





idac



Functional

Type Theory

define natural transformations

us

Eq ̄l by setting

idA'-A



—?■

id a- A—* A.

and that

ve

and that

idEqoEq-i,





and



indeed natural transformations.

are

Second

transformations fi: ?

fxQ



Va

we

Eq ̄l



Eq ̄l

show that

Eq



id-p and 77:

—?

Eq zdp

idp. Let



-^

Eq ̄l



define natural

us

Eq by setting

=f (x: [a] I 7a(x)), and =

(x:a \ Ja{x)).

Appealing

to Lemma

2.5.3,

need to show that

we

one

transformation and that their components witness calculations

are

A*a



def =

[x: a

h M:

/?],

(z: [a] I h(m(z)))



l0(m(z)):0\

Take any



that is



we

wish to prove

(z: [a] | M[Ia(z)/x\)

in V. But this is the case, for in the canonical model M

[z: [a]

in V. These

(x: a I M) M/3



natural



(z: [a] I m(z))

where



(3 of V. We need to show that the diagram

—*

a]

commutes,

isomorphisms

We show that fi is natural.

tedious but trivial.

morphism (x: a \ M): a

of fi and 77 is



idm

om



mo

id{a]



\z: [a]

we



have

M[Ia(z)/x]:pl D

proof of Theorem 4.9.3, especially the verification that fi and 77 make up a natural isomorphism in the final paragraph. Note that the function symbols J and J are saying in essence that if A and B are objects of C, then the objects A rxn B and A x B of Cl(Th(C)) are isomorphic—and similarly for =>. Exercise 4.9.4

Work

We

our

can

summarise

through

the details of the

recent deductions in the

following slogan:

I—

183

The Categorical Type Theory Correspondence

4-9.

Categorical Type Theory Correspondence

Theorem 4.9.3 is the basis of the

give

notion of



Ax-theory

slogan

that cartesian closed

which is syntax

The internal

Discussion 4.9.5



categories

independent.

language of

cartesian closed category C



theory Th(C). We can use the internal language to reason about the category C. Let us give an example. Suppose we wish to prove that for any D in C that X(gf) morphisms f.AxB^C and g: C X(g o ev)X(f). We can prove this directly using the universal property of exponentials. We have

is the

—*■

ev o

(\(g o ev)X(f)



id)

ev o



go



However,

(X(g o ev)

ev o

(X(f)

x x

id)

(X(f)





id)

id)

9f



and hence the



required equality follows from the said universal property.

we can

proceed

more

proved terms of Th(C) D, namely f:A,B^C and g:C

write down

directly using

the internal

which make

of the

use

language. We function symbols

—?

x:A



Xy:B.f{x,y):B

z:B=>C



Xw:

Sg

Sg and

B.g(zw): B

=¥>



=?



Sg > x:A\- Xw: B.g((Xy: B.f(x, y)) w): B => D. This latter proved "corresponds" to the composition of X(g o ev) and A(/). But

so

term

Th and





so



x:A\-Xw:B.g(Xy:B.f(x,y)w)

Xw:B.g(f(x,w)):B=>D

writing [—] for the canonical model of Th(C)

X(gf)







With





[x:A\- Xw:B.g(f(x,w)):B [x:A\-

Xw:

=>

in C

we

have

D]

B.g((Xy: B.f(x, y)) w):B^D\

X(goev)X(f).

little practice, it becomes very easy to write down

proved

terms of

correspond to given morphisms, and to then prove statements about the morphisms by using rules for deducing theorems in the internal language. Note that the crucial step in the above proof using the internal language is the derivation of the given theorem from the proved terms, an

internal

language

which

which is easier than the

morphisms /

and g.

corresponding calculations involving

the category

Chapter 4-

184

Functional

Type Theory

The notion of a translation of one A x-theory into another is similar to that for algebraic theories. However, the presence of a syntax for DISCUSSION 4.9.6

binary products in little

simpler

that Th and

Th in the

than

Th'

are

Ax-theories. Then

theory Th',

Cl(Th)

functor

Ax-theory makes the definition of such that for algebraic theories, as we shall see.

—?

written T: Th

Cl(Th'). Using

—?

the

we

define

Th',

to be

that to

us

T amounts to

specify

look at the data needed to

Let

us

suppose

translation of the



given by





theory

cartesian closed

equivalence

ApG : O0Cat ̄(Cl(Th), Cl(Th')) we can see

translation







giving

such

specify

Mod ̄(Th, Cl(Th'))



model T: Th



model.

—*■

Cl(Th').

Let

Our task is to define



theory Th in the cartesian closed category Cl(Th'). First, for each of the ground types 7 of Th, we will have to give an object [7)1 of Cl( Th'), structure for the

that is



type a' of Th'. Second, for each basic function symbol /:

a\,..., an

—?

x morphism [/]t- [<*i]t x [an]x [/?]t in x a'n and Cl(Th'). If we suppose that the source of this morphism is a[ x the target ff then the morphism [/]t (z: II?a[ \ N) will be given by a proved term Sg' > z:II?o4 h N:ff. This gives us a structure for Th in Cl(Th'). For this structure to be a model, the axioms of Th must be satisfied by the structure. If we work through the details, we see that this will be the case if

(3 of Th,

have to

we

specify



—*

...

...



for every axiom Ax



T h M

[Th M:a]T [n-M':a]T for can

some raw

as





N' of

M'\



of Th for which

(z: \V\T | N) (z: {V\T I N') Th',

[T]t







[T]T

then 7%' >

z:

follows. A translation 77i

—?

terms iV and

summarise this



Ht



[T]T

Ht \ ̄ N

N':



[a]T.

We

7V between Ax-theories

type of Th' for each ground type of Th and a proved term of Th' for each function symbol of Th, such that the induced translation of proved terms of Th into proved terms of Th' (via the structure [—]t) carries amounts to

giving



axioms of Th into theorems of Th'. We

can

say that Th and

classifying categories Theorem 4.9.7

Proof

Routine

are

Th'

are

equivalent,

equivalent. One

For any

Ax-theory

we

can

Th



Th',

if the

corresponding

then show

have Th

manipulations of the definitions.



Th(Cl{Th)). □

4-10.

185

Categorical Gluing

4.10

Categorical Gluing In this section,

Discussion 4.10.1

we

shall

apply techniques of category

categorical semantics to prove a result about Ax-theories which have been generated from algebraic theories. By the Ax-theory generated from a given algebraic theory, we mean the Ax-theory which takes the types and function symbols of the algebraic signature as the ground types and function symbols of its Ax-signature, and the axioms of the algebraic theory as its axioms. The result we are going to prove (stated formally in Theorem 4.10.7) says that any raw term of the Ax-theory which has ground type is provably equal in the Ax-theory to a raw term of the algebraic theory. We might interpret this informally by saying that if we enrich an algebraic theory with the syntax of functional type theory we will arrive at a "better" programming language which has "the same power" as the original. and

theory

In order to prove this

result,

we

shall set up



little

more

category-theoretic

machinery. Suppose that C is a category with finite products. Then a category JC is the relatively free cartesian closed category generated by C if there is a functor J: C 7C which satisfies the following two properties: —?

(i) Suppose that F: C a

cartesian closed

preserves

finite

V is

—?■

finite



product preserving functor and V is

category. Then there is

products

and

commutes up to natural

exponentials, isomorphism:



functor F:JC—*V which

and for which the

following diagram

^— JC





V We shall write

(ii)

<j>: ̄FI**F

for this.

If also F and <f> have the

natural

isomorphism ijj:F

Let Th

Ax-theory



(Sg,Ax)

—?

properties

as

F for which the

F and

an

<f>, then there is

following diagram

algebraic theory. ground types of Sg' are

be

for which the

same

Let Th'





commutes:

(Sgf, Ax')

the types of

unique

Sg,

be the

the function

186

Functional

Chapter 4-

symbols of

Sg'

symbols of Sg, and Ax' £ for the classifying category Cl(Th) and £' for Cl(Th'). a functor I: £ £'. On an object 7 of £ set are

the function



Type Theory

Ax. We shall write We shall

now

define

—*■

7(7) d= (... (71

72)



...)





7?

l' (where the subscript given a morphism (r | M)Th'-l equivalence up to provable equality in Th), then we set

and

->

Th denotes

I(T\M)Th^(z:nli\(...(M[,M'2),...,M'm))Th, in which

have written

we

II7; for (... (71

72)





...)



jn and also

M; d^ M^Prqhto/*!,..., Pro'}j(z)/Xj,... Projn(z)/xn] Projj(z)

where

is defined

on

page 178.

Our programme for the rest of this section is

as

follows.

First

we

prove

Proposition 4.10.2 which shows that a certain classifying category plays the role of a relatively free cartesian closed category. Second, we prove a purely categorical result called the gluing lemma, which is Lemma 4.10.3. Third, we set up a final piece of notation in Discussion 4.10.5 and then prove Theorem

4.10.7.

Proposition 4.10.2

The functor I:£

free cartesian closed category Let F: £

Proof

C is the



cartesian closed

syntactic

objects ?







we

F(unit) -R

C be

—*■

generated by



structure of the

On

the

relatively



products where

functor F: £'

—?



set =

0)

lc, the terminal object of C,



Fa

=?



F(z:6\())d^\:F6^1c,



F(z: 6 I



F(z:8 I f(M))

z:

6)



of

Sg',

Ffi.

morphisms (z: 6 \ M) of £'

we

put

id-p6, =

(using

category £') through the following clauses. On



=^

as

£.

category. We shall define

def

F(a

£' presents £'

functor which preserves finite

F[7] where 7 is a ground type F{a x 0) d= Fa x F0, and F7

—?

F([xi:7i,...,x?:7?]

| f(xu ,xn))o (F(z:6\M1),...,F(z:6\Mn))1 ...

4-10.











187

Categorical Gluing

F(z: 6 | Fst(P)) d= ttiF(z: 6 \ P) where tti: Fa x F/? T(z: 8 | Snd(P)) d= tt2F(z: 6 \ P) where tt2: Fa x F/?

Fa,

->

F/?,

-?

F(z:<5 | (M,M')) d= (F(z:<5 | M),F(z:<5 | M')), F(z:?5 | MAT) d= ev(F(z:8 \ M),7(z:6 \ N)), F(z:8 | Xxia.M) d= X(F(y:8x a | M[Fst(y)/z})).

Note that F

essentially

preserves all of the structure of 8'

from this that F does indeed preserve finite that is F is Now

shall define

definitions that



given an finite product preserving

fy where 7^:7

[7J

—?

def

a^

isomorphism (f>: FI object 7 of £, we have FItf) natural

we can

(Fttx,

in S.

that

nose.

It follows

exponentials,

and

m:



—?

7' is

F. It follows from the





II"F[7j],

and

as

F is

set

...,

Of

transformation. The details

Suppose

and

products

the

cartesian closed functor.



we

on

F7rn) ̄l : njFfa]

course

we

—?

F(j)

have to check that <f> is



natural

omitted, but the following fact will be needed. Fm. morphism of S. Then we have FI(m)

are a



This fact follows from the structural definition of the functor F.



Suppose now that F and natural isomorphism ifr. F



"07



ipaxp



1>a*0



4>m '? F7 def =







—>

oipa



o^1

(j> also —*■



satisfy the roles of F and <f>. We through the following clauses:

F7, where

we

ip0: (Fa

F0)

=*



^: (Fa

note that -?

F/3)

=?

(Fa -

F7





F0)

F[7] -?■

(fa =? 7/?)

and

F/fy],

F7



/?),

and

7(a =?

/?),

F(a ->

shall define



isomorphisms are the canonical ones. It is clear from the definition that the morphisms ipQ are always isomorphisms. It remains to see that ip is a natural transformation. Suppose that m: a —*■ (5 is a morphism in £'. Then we need to check that the diagram in which the

Fa Fm

Fa

Fa

(*) fa

Fm

F(3

Any such morphism m is of the form (x: a | M); we prove that the diagram (*) commutes by structural induction on the raw term M. We shall commutes.

188

give

Chapter 4-

an

example of just

namely commutativity

one

So it remains to check the

case,



def

Functional

(z:8 \ Xx:a.M):6



of the

F8

F(z:6 | Az:a.M)

\F(z:8 | Xxia.M) i>a

=?

7a ^7(3

Vfc

Now, of course F preserves binary products, and see that the diagram

F(z:8 | \x:a.M)

7(a=>0)



so our

^6

F8

commutes, where F8



Fa

F(8



i>a

=?

V>/3



F(8



so we

Fa^Fp

a). Now, by induction,



a)

following



7(6

F/?

^/3

F{u: 8xa\ M[Fst(u)/z])

tp0oT(u:8x



We show that of each of the

(**)

a)



have



that

the

F(u: 8 x a | M[Fst(u)/;z])

def =^/

='

to

commutes:

F/?'



equivalently

X(F(u:8 x a | M[Fst(u)/z))o *)

F(u:8 x a | M[Fst(u)/z])

and

task is

F6

(**)

Fa^Ffi

diagram

<*=?/?.

diagram

^6

F8

Type Theory





ip6xa



(idT6

M [Fst(u)/z])

paths of (**)

commutes via the universal





-0"1)

(idTs

is the



il)-l):l?8 x?a^ 7/?.

exponential

mate of

/, implying

property of exponentials. So,

4-10.

189

Categorical Gluing

ev o

([(ip'1

ipp) o T(z: 8 \

=>■

ipp



o ev o

ippo



ev o

^j"1)

{id-pa=>-pp



(X(F(u: 8

x a

ip0o  ̄F(u: 6



a.M)]

Xx:







id=



(F(z: 8 \

\ M[Fst(u)/z]))

a\ M[Fst(u)/z])



a.M)

Xx:

(idp5



idja)



id=





(idj6



ip ̄l)



-0"1)

if;'1)



/,



and also ev o

([A(7(m: 6

x a

Af [Fst(u)/z])o





id=J o(tp6



id=

F(u: 8



o(^



ipQ)(.idTs

| M[Fst(u)/z])o

x a









^]





required.



T{u: 8xa\ M[Fst{u)/z])o



as

^)

The other inductive

cases are

similar;

we

deduce that

tp

is indeed

natural transformation. The final task is to

4> <f>: FI —? FI. The details are tpi omitted, but we remark that the equality follows essentially from the naturality of <f> : F —*■ FI in 7 at morphisms of the form 7^:7 —? [7J. This completes the proof. □ Lemma 4.10.3

verify

that



categories and that r: C —? T> is a functor which preserves finite products. Suppose also that V has all pullbacks. Then the comma category Ql(T) (idx> I T) is also a cartesian closed category and the projection functor P2: Ql{T) —*■ C defined by

Suppose

that C and V

are

cartesian closed



(d,c):(D,f,C)^(D,,f,,C) cartesian closed

(d, c): (D, /, C) functor. Ql(T) is

been

along

(where

of

course

glued

PROOF

to V

—?

and

(£>',/', C")

part of the definition of binary product (A /, C) where

=:

TC



(D,/,C)

=*

is



has

(A, /', CO *f (£>

objects of Ql{T). Then the object given by

be is x

D\

T{C x C") arises from exponentials are defined by



products; and

TC



morphism of Ql(T)) glued category. We say that C is any

the functor I\

(D,f,C)

Let

(£>', /', C") called

c.C^C

1—

—>

(A,/,,C) ^ ((D

=?

A)





o(/



/'), C



C")

the fact that T preserves finite

T(C

=?

CT),7r2,C

=?

C)

Functional

Chapter 4-

190

where

7r2 is

Type Theory

given by the pullback

(D

=>

D')



T(C

=?

*2

C)

T(C

TC

Tl

C)

=?

TC

=?

f £>=>£>'



idD

/'

=?



idrc

=>-

rc

=?

n Complete the proof of Lemma 4.10.3. Now let C be any category. Prove that the Yoneda embedding H:C —*■ [C^^Set] preserves any Exercise 4.10.4

finite

product

which exists in C.

Discussion 4.10.5 J: C

Now

[C^.Set] (where

-?

TC is

realising ^C as the relatively free cartesian closed category G to the morphism a/: FJ by C) by taking the morphism a: F set T to be the functor which is given by the composition

—>

generated

P-^TC^^Set]

Define the functor

—?

FoH.TC—* [JV*,Set] where H is the Yoneda

—?

on

GJ.

[?*,&*],

embedding. By definition,

category, and the category of presheaves

—?

TC is



cartesian closed

C is also cartesian closed and

has

pullbacks; see page 114. Further, T preserves finite products, and so we can apply the gluing lemma (Lemma 4.10.3) to deduce that the comma category Gl{T) (id\c°p,set] j T) is a cartesian closed category and the functor TC, which takes a morphism (a,h):(F,(3,D) P2'-Gl(T) (G,/?',£) to h'.D E, preserves finite products and exponentials. =

-?■

-??

—?

We shall also define

/: A

-?



functor J:C

—?■

Gl(T) by sending

the

morphism

B of C to

(HfJf):(HAJAJA) where the natural transformation IA: HA

->

—>

(HBlIBJB) VIA has component

(IA)C:C(C,A)^TC{IC,IA) at the

object C of C09 which sends

Note that J preserves finite

morphism products because a

g: C

A of C to

H and J

and faithful because H is. After the next exercise main result of this section.

—?

Ig: IC

—?

/A.

do, and that J is full

we can

state and prove the

4.10.

191

Categorical Gluing

Prove that the functor J:C

Exercise 4.10.6

Gl(T)

of Discussion 4.10.5

is full, faithful and preserves finite products. Let Th

(Sg,Ax)

algebraic theory. Let Th' (Sg', Ax') be the Ax-theory for which the ground types of Sg' are the types of Ax. Sg, the function symbols of Sg' are the function symbols of Sg, and Ax' Suppose that Sg > xi:ji,...,xn:yn\- E:i

Theorem 4.10.7



be

an





proved term generated from the Ax-signature Sg', where the types 7* appearing in the context and the type 7 are ground types of Sg', that is, types is



of Sg. Let

us

write T



[x\: 71,..., xn: jn].

Then there is

a raw

term M for

which

Sg



T h M: 7

Moreover, if there is another Th!



Proof

r h





M': 7 then

Consider the

raw we

Tti

and

T \- E



term M' for which

have Th



Sg

T h M







M: 7. T h

M': 7 and also

M': 7.

following diagram S' J

Ql(T)

idr.i

S'

£'

J naturally. By Using Proposition 4.10.2, the functor J exists and JI I naturally, that is (P2oJ)oI definition, P2J I. It follows that P2oJoI I (trivially!) it follows from the defining property of I, and as ids' o I relatively free cartesian closed category and Proposition 4.10.2 that ids' P2J naturally. This latter isomorphism implies that J is faithful. This fact, J implies that J together with J full and faithful by construction and JI =













is full and faithful. we

expand

Sg'



on

the details for the existence part of the theorem.

Xi'.^i,...



The fact that / is full and faithful proves the theorem:

def =

Suppose

,xn:yn\- E:7. We shall write

J^Proj^zVxi,..., Pro'jj^/xj,..., Projn(z)/xn]

and

II7 =f (. ..(71 X72)



...)

X7n.

that

192

Functional

Chapter 4-

Then

Type Theory

J [7] in £'. Using the fullness certainly have e (z: II7 | E)Thr. py of J, there is a morphism ([2:1:71,... ,xn:jn] | M)Th'-l [7] which is taken to e by J. But this implies that Th E: 7 (using an obvious > z: II7 h M notation for M) that is 2V > x\: 71,..., xn: jn h M E: 7. The uniqueness □ part of the theorem follows from Ps faithfulness in a similar fashion. we

—>



->





4.11

Further Exercises

(1)

State



(2)

In this exercise

result for Ax-theories and prove it.

completeness

derive

categorical semantics for a very small type theory in a (for convenience locally small) category C with finite products. The types are given by the grammar a ::= 7 | a □ a where 7 is any given ground type. The raw terms are given by we



where



is

::=



bound in E. The rules for

terms)

I Vec(M, M) \ Atom(M, x.y.M)

variable. In any





raw

Atom(P, x.y.E),

term

introducing well typed

are

(the proved

are

Sg



Sg

Sg

T\-M:a >

Sg

T\-N:(3



(1)

T\-yec(M,N):aDp

T\-P:aDP



Sg



The pure equations of the

Sg

Th

T h



Sg Th



T,x:a,y:(5

theory (excluding logical

h E:6

5^

rules such





a raw

r,z:aD^hF:6

r\-Atom(P,x.y.F[Vec(x,y)/z])



F[P/z]:6

"expected" definition of substitution of term—note the variable binding.

To model the types

B of C. Deduce that to

we

shall

require

an



equational

C{C,B)

(4)

a raw

term for

object A □ B for all objects

soundly interpret (1)

¥c : C(C,A)

as

E[M/x, N/y]: 6

Write down the

variable in

(2)

are

Atom(Vec(M, iV), x.y.E) rhP:aD/9





Atom(P, x.y.E): 8

T h

reasoning, weakening of contexts etc)

(b)

and y



terms-in-context



(a)

variables

—?

we

need



function

C{C,AUB)



A and

193

Further Exercises

4.11.

for all objects A, B and C of C which is natural in C. By considering naturality in C at (m,n):C ^ Ax B where m:C —? A and n:C —> B are any morphisms of

C, show that ¥c

by

is determined

¥c(ra, n)

(c)

Show that to





Vi



soundly interpret (2)

#c

morphism vi'.AxB^ADB



(1')

(m, n).

shall

we

where

require

C(C,ADB) xC{CxAxB,D)



function

C{C,D)

—?

C x (A D B) By considering naturality in C at {idc,p)'> C deduce that ^c is in fact determined by giving for each object C of C a function natural in C.

—*■

9C : C{CxAx B, D) natural in

C,

Hence show that to

for all

morphisms m: satisfy (4) we need



?c(/

and



C,

and

—?■

°

A,



n:

(?^c

an

instance of

similarly that (4')

e:

{idc,p)

/:





(f)

(5)

and

Show that

(6)

(3'),

holds

(5)

hold for all and









deduce that

(id



just in

and

(6) imply

9C : C(C xAxB,D) and









as



vi)





(3')



—?■

—?■



(3')

(4')

D in C.

Ax B to each of

holds

just

in



(5)



f,

(6)

above. a

natural

isomorphism

C(C x(AUB),D): C(idc



case

case

that there is

B, D)

A, B

e,

x vu

idD)

by taking C to be 1 deduce that the function

C(vx, idD) : C(A

C, and to

D in

(tdc,P>



(A D B)

ec(fo(idxVl)) where

(idc, m, n)

e o

projections from C

0c(e) and show



and



(2')

need

we

B and

—>

vi))



about the three

using

ec(e)o(tdc,p).

(idc, vi (m, n?

morphisms p:C->.4D5

(e) By thinking



satisfy equation (3)

0c(e)

for all

(A D B), D)



where

*c(p,e)

(d)

C(C

—?

C(A xB,D)



■-?.





Vl

Functional

Chapter 4-

194

Type Theory

isomorphism (bijection). The functions C(vi, idu) define a natural HAxB (as D runs over the objects of C) with components transformation HADB is

an

—?

with v\.n

given by "pre-composition A□ B





theory in

B. Hence write down



Use the Yoneda lemma to deduce that

sound



categorical

semantics of

our

type

category with finite products.



type theory in which there is a type of booleans and a syntax for conditional expressions. We omit a formal definition of raw types and terms, for which the reader ought to be able

(3)

In this exercise

derive

we

categorical



semantics for

provide a definition if desired. There is The proved terms are given by to

Sg

Sg



Sg



Th



Sg



Th

Sg Th

(a)

The



(raw)

Sg

Sg





Sg

T\-

T\-M:a



in this syntax.

T h false: bool



Sg

binding

T\-N:a



n-Cond(B,M,iV):a

T\-M:a T h

Sg



T\ ̄N:a

Cond(true, M, N)

ThM:a

Sg



Sg



M:



JV:a

Cond(£, E[true/x), ^[false/a:])

terms true and false

are

(2)



(2')

T, x: bool h E: a



(1)

T\-N:a

rhCond(false,M,AO

r h B: bool



variable

bool

T h true:

TV-B: bool



no



thought

of



as

E[B/x): a

(3)

elements of the type bool.

interpret the rules introducing them we need an object Q of a (locally small) category C with finite products, along with morphisms t: 1 —? Q and /: 1 —? fi, To

so we can

[r]

define

[T

h true:

bool]



[T

I- false:

bool]



to!:

[T]

fo\: [T]

-?

->

1 1

->

->

Q Q

product of the interpretations of the types appearing in T. Write down a function on morphism sets which can be used to interpret (1). Show how your function is more simply determined by functions

where

is of

course

the finite

¥c : C(C, A) which

are

natural in C.



C(C, A)

—?

C(C



Q, A)

4.11

Further Exercises



195

interpretation of the proved term T h Cond(JB, M,N):a in terms of 3>c- Use this to write down equations which must hold for morphisms of C in order that the equations-in-context of (2), (2') and (3) are satisfied by the proposed categorical model.

(b)

Write down the

(c)

Use the

(d)

Now let C have at least

equations of (b) to deduce that each function ¥c is an isomorphism (bijection). By taking C to be 1, deduce that Cl is determined up to isomorphism in C. What is £2?

C((C the



1)



isomorphism ttq'-C

(C

binary coproducts. By considering x





1), A)

C(C



1, A)





C(C

C and your deductions in



lemma to deduce what property Q must have in order to syntax of conditional

idc

expressions. Hint: think about the

xt:Cxl





Q,

Cxi:

<—

bijection



1,4),

(c),

use

the Yoneda

soundly interpret morphisms

idc



the

/.

categorical semantics for an equational type theory based around the "case" construct found in programming languages. The types are given by the grammar a ::= 7 | a + a where 7 is any given ground type, and raw terms by

(4)

We shall deduce

—?

the

M In the

raw

::=

term





I \n\p(M) \ lnrQ(M) | Case(M,

Case(C,

x.E

\ y.F)

variable y is bound in F. The type

the variable

theory

is

x.M

\ y.M).

is bound in E and the



presented through

the

following

rules:

5^

Sg Sg







ThM:a

rhlnl/9(M):a



T\-C:a +

Sg

(3

Sg

S#



Tl-M:a

Th

Sg





T\-

Tl-M:a

Th



T h



5p

(1)

^ >

T h





Sg

T, x: a

Case(C,

x.F

x.E

x.F

T\-N:P



*.

T h

Sg



,./

lnra(7V):a



T, y: /?





Sg =

Sg

| y.F)





T,y:0\-F:6

E[M/x]:6 >

T,y:(3\-F:S

F[N/x]:6

(3

h F: 6

| y.F): 5

\ y.F)

T,x:a\-E:8

Case(lnra(iV),



h E: 6

T,x:a\-E:6

Case(lnl/3(M), 5p

Sg "

(2)

(3)

(4)

(5)

196

Chapter 4-

So

T\-C:a +





Sg



T,z:a





Functional

Type Theory

h L:<5

(6)



Th

r h



The idea of the types

the



and

raw

Case(C, s.Lpnl^aO/z] | y.L[lnra(y)/z]) case

syntax is that the type

/?, that Inl^M)

term

an

/?



is

inclusion of M in

L[C/z]:<5

"disjoint union" of the disjoint union, and that





\ y.N) represents M[C/x] if it is the case a," and represents N[C/y] if it is the case that

Case(C,

term C is "of type

is





x.M

/?." One might expect

that the C is "of

type a + /? by a coproduct in a category, mimicking the intended meaning of the syntax. We shall show that this is about three quarters of the true story. We suppose that there is an type

object A + B of C for coproduct, but we do

(a)

all

to be able to model the

A and B which

objects

not

assume

we

expect

this.

soundly interpret rules (1) give morphisms i:A-*A+B and j: B

Use the Yoneda lemma to deduce that to

it is necessary and sufficient to

binary

to prove is

and

—*

of C for all objects A and B, where

we

(2)

A+B

may define

[rhlnl/3(M):a + /?J d= io[rhM:a] [rhlnra(AT):a + /?l ^ j



[T



#:/?].

(b) By writing down an appropriate family of functions on morphism sets which will give a sound interpretation to (3), and considering naturality conditions, prove that your functions may be

specified

in terms of

¥c''C(CxA,D) xC{CxB,D) which

are

natural in C. We

[rhCase(C,

can

C(C

—?

family

of functions

{A + B),D)

then define

x.E\y.F):8jd=

%l(ir,i:ah E:8l [T,y:p\- F:6\) (c) Using







{id[rh [T

h C:a +

/?]).

proved terms in (a) and (b), write down the equations which must hold between morphisms of C in order that the equations-in-context (4), (5) and (6) are always satisfied. Deduce that the the semantics

assigned

to

function

C{Cx {A + B),D)—?C(CxA,D) given by / object

i—?

(/ o (idc



i), f ° (idc

A + B is indeed the



j))

is



xC(CxB,D)

bijection.

Hence show that the

binary coproduct of A and B.

Further Exercises

4.11.

(d) By considering

the

197

bijection

use

C((C

**

C(C xA,D)x C(C xB,D)

A)





(C

£), D),



binary products of C must distribute objects A, B and C of C we have

the Yoneda lemma to prove that the that is for all

binary coproducts,

over





{A + B)

*±

{C



A)

{C





B).

syntax soundly we require a category with finite products and binary coproducts, for which binary products distribute over Thus to interpret the

case

binary coproducts. preliminary definitions. A natural numbers object in a category C with finite products is specified by an object N of C with morphisms 0:1 N and s:N-+N which enjoy the following universal property: given any morphisms m: C A and /: C x A A in C, there is a unique morphism rec(f):CxN-+A for which the following diagram

(5)

For this exercise

we

shall need



few

—?

—?

—?

commutes:

Cxi

id





id

?CxN

rec(f)

C———:—- C xA



{id,m)

has

we a

?CxN

(7Ti,nec(/)>

7Ti|

Now

x s

give the notion of

nat-theory.



syntax for natural numbers.

This is similar to



::=

MM

proved



occurrences

terms

Ax-signature,

are





| Suc(M) | (x.M)M(M)

of the variable

those for





in x.M

are

Sg >



rhO: nat

T,x:a\-F:a

Sg

bound. The rules for

Ax-signature augmented by Sg

Sg





x\ fc|/(M,...,M) | () | (M,M) | Fst(M) | Snd(M) | Ax:a.M| length

where

but

A nat-signature is specified by giving

signature Sg of ground types and function symbols just as in and the raw terms are now given by a grammar of the form M

Ax-theory,

Sg Sg







> T

T\ ̄M:a

r h N: nat

\-Suc(N): Sg

T\-(x.F)N(M):a



nat

T\ ̄N:nat

forming

198

Functional

Chapter 4-

A nat-theory Th

(Sg,Ax)

Type Theory

given by such a signature Sg together with a collection of equations-in-context which are deemed the axioms of the nat- theory. The theorems are generated by the rules for Ax-theories, augmented by the rules =

Sg

T,x:a\-F:a

> Th

Sg Th





Sg

Sg

T, n:

with





(c)

Oo!:

[T]

F[{x.F)N{M)/x]:a







r\-G[N/n]

semantics to

-+



-?

F[G/x]:nat

(x.F)N{M):a

nat-theory in a cartesian closed example, we would have {nat}



For

object.





category



N and

N.

the discrete natural numbers N

gives



natural numbers

object

category uCPO of u;cpos.

Given

category





natural numbers

[T I- O: nat] (b) Prove that in the

give

T\-M:a



G[0/n] M:a T, n: nat h G[Suc(n)/n]



Show how to

M:a

h F:a

r 1-

Th

(a)

nat h G:

T, x:a



Th

Sg



r h N: nat



Th

T\ ̄M:a



T\-{x.F)°{M)



T\-{x.F)s^N)(M) >

Sg

Sg

T,x:a\-F:a







is



nat-theory

Cl(Th).

Prove that

it satisfies the

expected

category V with



Cl(Th)

functor H:

Th show how to construct

Cl(Th)



object,

canonical

natural numbers

universal property:

natural numbers —?

has



given

any other cartesian closed

there is

V which preserves natural

classifying object and that

unique cartesian numbers objects. a

closed

(d) Consider the following category, Ql, constructed using a given nat-theory Th. Let Gbl(a) be the set of global elements of a in the category Cl(Th). If [([] | M): unit a] G Gbl(a) then we shall write just M for ([] | M). Regard Gbl(a) as a discrete u;cpo. The objects are triples (D, <, a) where D is an u;-cpo, a is an object of Cl(Th), and < C D x Gbl(a) is an inductive subset of the product u;cpo. A morphism -*■

(/, F) is

given by

of

Cl(Th)

an



(D, <,a) —(tf, ?',a') /:D

^-continuous function

for which if d < M then

f(d)

—?

a' morphism F:a where o is composition

D' and

<' F





—>

Pointers

4-12.

in

Cl(Th).

to the Literature

199

Prove that Ql is indeed

Prove further that Ql is

category.





object. Hint: The cartesian closed structure of Ql is given coordinatewise. For example, the binary product of (D, <, a) and (£>', <', a') is the object (D x D', <", a x a') where (d, d') <" P just in case d < Fst(P) and d' <' Snd(P). The natural numbers object is (N, <nati not) where n <nat N just in case Th > hiV Sucn(0): nat where cartesian closed category with



natural numbers



Sucn(0)

indicates

Suc(Suc(... Suc(O)...)).







length

(e)



Use the category Ql to prove that all closed terms of Th of type nat

provably equal

to standard natural

Th

Sucn(0):



\- N



classifier Cl(Th):

numbers,

that is if

nat. Hint: Use the universal

show that there is

Cl(Th) ujCPO and Ql



commutative

Ql



7T2



Sg



h N: nat

are

then

property (see (c)) of the

diagram of functors

ljCPO

7Ti

categories with natural numbers objects. Here, [—] indicates the obvious functor derived from the semantics of Th in ujCPO. If Sg > h N: nat then there is a morphism N: unit —? nat in because both

Cl(Th). Complete

your

are

cartesian closed

proof by thinking about the image of this morphism

in

Ql by applying H.

(f)

How does the category Ql relate to the

4.12

glued category

of Section 4.10?

Pointers to the Literature

fairly detailed exposition of much of our Chapter 4 in [AL91]. The treatment in that textbook does not discuss categories of models, and the equational syntax of functional type theory is presented less formally than in "Categories for Types." A comprehensive discussion of many aspects of A-calculus is given in [Bar84]. This book covers much of the syntactic and computational details of A-calculus which are only just touched on in "Categories for Types." The textbook [BW90] contains a very brief discussion of the correspondence between functional type theory and cartesian closed categories. The first account of the connections between A-calculus (functional type theory) and cartesian closed categories appears in [Lam80]. A rapid exposition of the correspondence between functional type theory and cartesian One

can

find



200

closed categories

Chapter 4-

can

be found in

[LS80].

This book

Functional

covers

Type Theory

most of

our

excluding a discussion of categories of models. The description of the internal language of cartesian closed categories is described through an approach making use of polynomial categories. A brief description of models of functional type theory appears in [Pie91] which is written for an audience of Chapter 4

computer scientists.



Polymorphic

5.1

Type Theory

Introduction begin this chapter by taking a look at the "programming" judgement that has so far appeared, namely:

Discussion 5.1.1 form of

Functional

Let

us

Xi'.cti,... ,xn:an

\-





Type assigned List of identifiers r

for





input data

M is the code for



gives the working



given

program

program. The list of



types of

input data

(variable, type) pairs

environment for the program,

(or variables) appearing

to

program for



functional





basic

giving



X\:a\,...,xn:oLn

list of the identifiers

body of the program, and shows the types for the input data. The type a gives the overall type assigned to the program M when it is fed with input data whose types match those appearing in the in the

environment.

mainly concerned with giving an account of the formal syntax (and its semantics) which forms the background to modern typed (functional) programming, we shall pause here to consider, in broad terms, some of the underlying programming and implementation issues. First of all, think While this book is

about the

uses

to which

types

are

put. There

are

(at least)

two different roles

played by type information. On the one hand, it is used by the programmer to organise data and to make the task of designing programs easier. On the other hand, types are used by an implementor to organise storage space within the computer. A compiler needs information about the amount of storage space it should allocate, in order to work on a given data item. In most untyped languages, the computer will produce a package consisting of the data itself, information about the type of the data, and possibly information about the overall size of the entire package. The disadvantage here is that all of this information has to be checked at run time. In a typed language, checks on the type of data, storage allocations and so on can be performed at compile time, and the machine need only store the core program data. However, typing can lead quickly to certain disadvantages. om

202

Chapter

Polymorphic

5.

Functional

Type Theory

Consider the following procedure which performs the swapping of the values of

two variables:

Proc

Swapint (var var



very

simple "algorithm" for

Int;





Int);

n,m

Begin t

:=

m;



:=

n;



:=



end; This piece of code contains the

essence

of



swapping the contents of two variables, but it has an obvious drawback. On the machine, it will only perform this swap for variables of type integer. Yet the same "algorithm" will work for variables of any type. We can solve this problem by allowing our code to contain a "variable type" and such a procedure for doing variable swaps might then look like Proc Anyswap ( type X; var





var

n,m



X);

X;

Begin t

:= m;



:= n;



:= t

end; where the type variable X would be

assigned



value at each call of the above

procedure. A second order functional type

theory is a formal system which embodies the principle of variable types as well as providing a formal syntax for writing down functional expressions. We shall now give an informal example of a term (program) of a second order functional type theory. Let us think about the identity function as written in functional type theory, namely Xxia.x. This program has the same disadvantage as the procedure for swapping two integers; it is the identity function at the type a, yet has the same "form" whatever a actually is. Consider the expression AX.Xx: X.x. Here, one should think of x as a program or term variable, and X as a type variable. The idea is that the AX performs the

same

role for type variables

and marks the variable X

as a

as

"hole" in which

Xx does for term variables

we can

plug

any

type. So, if

The

5.2.

we

Syntax

want to

and

produce

Equations of 2Ax-Theories

the

identity function

integers,

we

apply

our

expression

type int and "slot int into the 'hole' X:"

to the

(AX.Xx: X.x)(int) What about the type of the is X

on

203

X.



(Xx: X .x)[int /X]



expression AX.Xx: X.x?

Xx:int.x. The type of Xx.X.x

We would like to formalise the idea that the

expression e AX.Ax: X.x is the identity function for all types X, and that at a particular type a the type of e is a => a. In fact the type of e will be written "iX.X =*> X, where V should be read as "for all" and the symbol X is bound in "iX.X =*> X, indicating that occurrences of the X after the are "slots" to be filled by other =¥>





types.

simple ideas are the basis of a second order polymorphic (functional) type theory. Of course there are many points to be clarified; our aim here is to simply give the reader a feeling for the ideas of second order polymorphic type theory. These

We with



can now

give



summary of the contents of this

chapter.

We

begin

definition of the formal syntax of the so-called second order

polymorphic functional type theory with finite products. We shall discuss the idea of a 2Ax-theory, which is a formal equational system much like a Ax-theory, except that we may now perform abstractions over type variables. Next a categorical semantics is derived, using the same principles as in previous chapters, namely that substitution in syntax is interpreted in a categorical structure by composition of morphisms. With this, we can give a formal definition of the semantics of a 2Ax-theory in a categorical structure known as a 2Ax-hyperdoctrine, which is a particular kind of indexed category. We give the details of both a recursion-theoretic and a domain-theoretic model of polymorphism, by giving an instance of a 2Ax-hyperdoctrine based on partial equivalence relations and domain constructions respectively. We prove that our semantics is sound, and then show that there is a categorical type theory correspondence between this kind of syntactical theory and its categorical semantics; the essence of these ideas is much the same as in Chapters 3 and 4, but the technical details are more complex (see Figure 5.1). This correspondence also shows that the semantics is complete.

5.2

The

Syntax

DISCUSSION 5.2.1 is





and

Equations of 2Ax- Theories

2Xx-signature

2Ax-type signature and Sgtm

is



pair Sg =f (Sgty, Sgtm) where Sgty 2Ax-term signature. The specification is



204

i—

Chapter

5.

Polymorphic

Functional

Type Theory

Categorical Type Theory (

Type Theory

Figure

5.1:



Cl{Th)}>

Th

[Th{C)+

Category Theory



Cl(Th(C))I



CI

fibres

Cl(Th{C))





base

Hyperdoctrinal Category Theory / Type Theory

Correspondence. of

Sgtm depends

specified by ?

the

the

specification following data:

A collection of

on

of

Sgty.



2Xx-type signature Sgty

is

type symbols.

arity for each type symbol which is given by a natural number (possibly 0). A type symbol K with arity 0 is called a constant ?

An

Let

us

define the so-called

We assume that

we are

type variables. The ¥

::=

raw

raw

types. These play



non-zero

In order

variables,

arity



variable,

and unit is

unit







<£>

such notions,



=>





K is any constant type, F is any type a

3>. We leave it

will

as an

require



of

VX.¥

distinguished (constant)

raw

raw

bound).

types for type

give the formal

(recall

from

In order to define

definition of the relation ¥' is

exercise for the reader to

symbol

type.

will need notions of free and bound type variables

we

terms.



Discussion 5.1.1 that the type variable X in VX.¥ is

should be



to be able to discuss the idea of substitution of

we

raw



length

of

similar role to

countably infinite set Varty {X, Y,Z,...} types are generated by the BNF grammar

given

X\K\ F(¥, ...,¥) |

where X is any type



subtype of definition, which a raw

intuitively clear; it may be helpful to read Discussion 4.2.3. We call an expression of the form VX an abstraction. If the raw type VX.ty is a raw subtype of 3>, then # is the scope of the occurrence of the abstraction VX. If the type variable X occurs in the raw term ¥, then X is bound if it occurs in

5.2.

The

Equations of 2\x-Theories

and

Syntax

205

subtype of the form VX.\£. We say that occurrences of X in the raw subtype VX^ are captured by the abstraction VX. If X occurs in ¥ and is not bound, then it is said to be free. If X has at least one free occurrence in 3> it is called a free variable. In fact the set of free type variables of a raw type

a raw

¥ is defined inductively by the following clauses: ?



ftyv(X)*{X}, ftyv(K)d^0, ^flyv^i) U



ftyv{F(¥u



ftyv(unit)



ftyv(¥





ftyv{¥

=>



ftyv(VX.¥)d^ftyv(¥)\{X}.

The

raw

S0))

...,

Uftyv{¥a),

0,



tf)

...

ftyv(¥) Vftyv(V),



tf) =ftyv(¥) Vftyv(V),

type ¥ is said

to be

a-equivalent

to the

raw

type \I> if ¥ and \£ differ

only in their bound variables. The notion of a-equivalence is an equivalence relation, and we shall now regard a raw type ¥ as the a-equivalence class which it determines. This is because the notion of substitution of

raw

types is

only well defined up to a-equivalence—see page 158. Think of a-equivalence the

"being

as

substitution of the raw

up to

same

raw

type ¥, written

occurrences

variables



of bound variables."

change

type \£ for

¥[¥/X],

occurrences

to be the

raw

capture. Formally

Y[V/X] d=

we

term formed raw

X[V/X] d= tf,



K[ty/X]



F(¥i,..., ¥?)[*/X] d= F(¥i[¥/X],..., ¥?[tf/X])

non-zero



arity



unit[^/X]



(¥





(¥

=>





K for



constant

by replacing

all

type \£, changing bound

Y if Y is different from

X,

type K, for



type symbol F of

n,

def =

unit,

V)[*/X] d= (¥[*/*])

(i) (ii)

define the

have:



and

us

of the type variable X in the

of the type variable X in ¥ with the

to avoid

Let

&)[*/X]



{*[*/X\)



(¥'[#/*])>

=>

(V[*/X\),

and

def

(VX.¥)[tf/X] =VX.¥, d= VZ.(^[Z/X][*/y]) (vx.¥)[*/y]d=vz.(¥[ (VX.¥)[tf/y]

where Z

<£ ftyv{§) Uftyv^f),

and Z is chosen to be different from X and Y\

Examples 5.2.2 the structure of

The brackets

syntactical

terms.

"("

and

")"

are

used to indicate

informally

206

Chapter

(1) {(X =>Y)x Z)[¥/X\



(2) (VZ.(X =>Y)x Z)[U



(<f>^Y)^-

Z/X]

The variable Z in the substituted is

captured by

5.



raw

VZ.((C7



Z)

Y)

=?



term U x Z becomes

Z is no* correct.

bound,

that is, it

the abstraction VZ. We should have

<¥ VV.((C/

change



Z){V/Z]{U



Z/X])

W.(((X=>Y)xV)[UxZ/X\)



we

Type Theory

Z.

(yZ.(X^Y)xZ)[U xZ/X] d= VV.(((X =>Y)

where

Functional

Polymorphic



the bound type variable Z to



Z)

=>

Y)





type variable V different from

Z and X and such that V

#ftyv((X ^Y)xZ) Uftyv(U



Z)



{X,Y,Z,U}.

give some rules which generate the syntax of the "well formed types," using the 2Ax-type signature Sgty. First we give a couple more definitions. A type context is a list of distinct type variables A [Xi,..., Xn]. A type-in-context is a judgement of the form Ah¥ where DISCUSSION 5.2.3

We shall

now



¥ is

a raw

type and A is



type

context.

We shall

now

define



class of

judgements of the form Sgty > Ah¥ where A h ¥ is a type-in-context. The judgement Sgty > A h ¥ is called a proved type, and the rules for introducing these judgements are given in Figure 5.2. One should think of the raw type ¥ in a proved type Sgty > A h ¥ as being "well formed" or "well typed."

Remark 5.2.4

Note that all rules for

be well formed. Thus in the rule for is



well formed type context, X does not appear in A. Note also that if

example)





[X, Y]

we

may write

Proposition 5.2.5

We

of type contexts,

with

on

introducing syntax are assumed to Polymorphism Types, because A, X

along

can a

X,7h¥ rather than [X, Y]

(for

h 3>.

permutation and weakening rule of substitution, mimicking the rules found derive rules for the

page 125.

Proof



Induction.

Exercise 5.2.6

Write down the rules of

Proposition

5.2.5 and prove them.

5.2.

I—

The

Syntax

and

Equations of 2\x-Theories

Type Variables

Sgty Unit

A',X,A\-X



Type Sgty

I—

Sgty



Ah¥!

Sgty

Binary



...

Ah unit

Sgty



(K

Ah¥0

AHF(¥lr..,¥0)

Product

Types

has

arity 0)

(where

F has

non-zero

arity a)

Types >

Ah¥

Sgty Function



Ah



Sgty

1—



Type Symbols Sgty

1—

207



Sgty Ah¥

> x

Ah*





Sgty



Ah¥

Sgty



Sgty



Ah*

Ah¥ =>*

j— Polymorphism Types

Figure

5.2: Proved





A,Ih¥

S^*



A h VX¥

Types Generated from



2Ax-Signature.

208

Chapter We will

DISCUSSION 5.2.7

see

later

Polymorphic

5.

on

that

Functional

second order



Type Theory

polymorphic

judgements asserting the equality of raw types and the equality of raw terms (we have yet to give the definition of raw term). However, the equalities which hold between the raw types play a role in the type assignment system for raw terms. This means that we have to give the equational theory of types before giving the type assignment system for raw terms, that is, the theory will involve

rules for introducing proved

terms.

being we shall define a typing theory. A type equation-in- ¥' where Sgty > Ah¥ and context is a judgement of the form A h ¥ Sgty > A I- ¥'. A 2Xx-typing theory Thty is a pair (Sgty, Axty) where Sgty is a 2Ax-type signature and Axty is a collection of type equations-in-context, each equation-in-context known as a type axiom. The type theorems are judgements of the form Thty > Ah¥ ¥', which are generated by the rules of algebraic type theory (see page 128, where one needs to replace judgements of the form Th > r h M M': a with those of the form Thty > Ah¥ ¥'). For the time









A 2 A v.-term signature

Discussion 5.2.8 data from ?



2Ax-type signature

typing theory Thty





Sgty)

is

Sgtm (which the

specified by

is defined

following

using the

data:

{Sgty, Axty).

function symbols, each having an arity a, which is a natural number (possibly 0). A function symbol k with arity 0 is called a constant. ?

A collection of







sorting for each function symbol / of arity a, which type context A-^ and a finite list of a + 1 raw types

written

suggestively

as

/: A^; ¥l5..., ¥>a

for each 1 < i < a and also then

we

Now

write k: we

us assume raw

terms



are

[¥i,..., ¥0,3>] (often ¥>), where we have Sgty > A* h ¥*

A? h ¥>. If A; is



specified by giving



constant function

symbol

Ak; ¥.

define the

that

Sgty

—?

is

raw

we are

generated by a 2Ax-term signature Sgtm. Let countably infinite stock of term variables. The

terms

given



given by the (informal) BNF grammar

::=



| **,,...,*. | /*x,...,*B,(Af,..., M) | () | (M, M) | Fst(M) | Snd(M) | length



\x:¥.M\MM\AX.M\M¥ where



variable, k is any constant function symbol for which / is any function symbol of non-zero arity a for which

is any term

length(Ak) length(Af) of the self





n,

n' and the ^f and ¥

explanatory

notation

are

k¥

any

and

raw

types. We shall often make

/^(M).

use

5.2.

The

Syntax and Equations of 2Ax-Theories

The next task is to define the substitution of

and of

raw

types for type variables

(which

209

terms for term

raw

appear in

terms).

raw

variables,

Such

or-equivalence or "change of bound variables." be familiar, we give sketch definitions. First, it is

substitutions will be well defined up to As these ideas should an

now

exercise for the reader to define the relation R is

term M. Occurrences of the term variable



a raw

subterm of the

raw

in subterms of the form \x:¥.N

captured by the abstraction Ax: ¥. If the term variable x occurs in a raw term M and is not bound, then it is free. If x has at least one free occurrence in M then it is a free term variable of M. The set of free term variables of a raw term M, ftmv(M), can be given explicitly by the following clauses: are



bound.

For the

fv(-) ?

We say that

is

terms which

raw

with



"appear in" Ax-theories,

see

page

158, replacing

ftmv(-),

ftmv(k¥)d=

0,

.ftmv(ft(M)) ^ UiflmvWj), ?

ftmv{AX.M) d= ftmv{M),



ftmv(M¥)= ftmv(M).

and

Occurrences of the type variable X in



subterm of the form AX.M

are

bound, and said to be captured by the abstraction AX. Any type variable X which occurs in a raw term M and is not bound is said to be free. If X has at least one free occurrence in M then X is a free type variable of M. The set

ftyv(M)

of free type variables of

a raw

term M is

specified through

the

clauses: ?

ftyv(x) =f



ftyv{hq)

0,



\Jlftyv{^i)

where A: is

?ftyv(f¥(M)) d= [ftftyv(Vi) non-zero

?/&??? ?





arity =

0,

d^ftyv(M) Uftyv(N), ftyv(Fst(P))d^ftyv(P), ftyv(Snd(P))d^ftyv(P), ftyv{(M,N))

ftyv{\x:¥.M)



ftyv(MN)



constant function

\fiftyv{Mj)

a,









ftyv(¥) Uftyv(M),

d^ftyv{M) Uftyv(N), ftyv(AX.M) d=ftyv{M) \ {X}, and

where



is

symbol, a

function

symbol

of

210



Chapter

5.

Polymorphic

Functional

Type Theory

ftyv(M¥) =ftyv{¥) Uftyv(M).

a-equivalent if they differ only in their bound type and term variables. This gives rise to an equivalence relation on raw terms, and we shall now refer to a "raw term" M to mean the a-equivalence class determined by M. The substitution of a raw term N for occurrences of a term variable x in a raw term M, M[N/x], is defined by substituting the raw term N for free occurrences of x in M, changing bound term variables to avoid capture. More formally we have: We say that two

raw

terms

are



If M



k¥[N/x]



f§(Mlt..., Ma)[N/x] ^ f§(M![N/x],..., Ma[N/x\),



{AX.M)[N/x}

"appears in" =

Ax-theory,

see

page



AY.{M[Y/X][N/x})

M, M[ty/X],

a raw

type \I> for

is defined

by

occurrences

x[*/X\



f*u...,*n(Mi,.-.,Ma)[*IX]^U



<>[*/*]



(M,N)[V/X] d= (Af[tf/X], W[tf/X]),



Fst(P)[tf/X] d= Fst(P[tf/X]),



Snd(P)[tf/X] d= Snd(P[tf/X]),



def =

of

ftyv{N)

and Y



type variable X in

a raw

x,

<>,

(Ax: ¥.M )[*/X] d= Ax: ^[*/X].(M[*/X]), (Mtf)[*/*] d= (Af [*/X])(JV[*/X]), (i) (AXM)[*/I]=AXM, < (ii) (AY.M)[*/X\ d= AZ.(Af [Z/y][*/X])

where Z

and Z is chosen to be different from both X ?



the clauses





<£ ftyv{M)

(M¥)[N/x] d= (M[N/x])¥.

term



where Y

X, and

The substitution of



159,

%,

is different from ?



£ ftyv(M)Uftyv{V), and Y,

(Af¥)[tf/X] d= (Af[*/X])(^[*/X]).

Exercise 5.2.9

Make

sure

you understand the definition of substitution.

{\y\ §.M)[N/x] requires a renaming (AX.M)[N/x\ and (AY.M)[3>/'X] require

Note that the definition of

of

term variable and that



of bound type variables.



bound

renaming

The

5.2.

Syntax

211

Equations of 2Ax-Theories

and

Discussion 5.2.10

We

give

now



collection of rules for

generating the

using a 2Ax-term signature. Of course, the situation is somewhat more complex than was the case for algebraic theories and Ax- theories, and we shall need a few more auxiliary definitions before we can give rules for generating the well formed terms-in-context. A term context, "well formed" terms

is

(term variable,

list of



type) pairs,

raw

be distinct. We shall write A h T to

where the variables

mean

are

assumed to

Ah¥j for each ¥* which appears to mean that Sgty > Ah^ for

in T. We shall also write

Sgty

each ¥i which appears in

T, and if T is empty then A h T will just say that are given a type context A [Xi,..., Xn], and raw

A is

A h T



type context. If we types ¥ and \I>j, then we shall sometimes write a

(obvious)

leave the reader to define the A term-in-context is term and ¥ is

where A

|T



judgement



¥[#/A]

h M: ¥ is



of the form A

|T

term-in-context, is called

generating these judgements

are

<b[i&/X]

and

we

notion of simultaneous substitution.

h M: ¥ where M is

Sgtm

type. A judgement of the form

a raw

for



given by the rules







a raw

T h M:

proved term. The rules in Figures 5.3 and 5.4.

3>, for

Exercises 5.2.11

(1)

Prove that in



variable of 3> appears in A.

Sgtm





|T

of the form

judgement

h M:

¥,

Sgty

Ah¥ any



Prove also that in any

any free

type variable in the

judgement

free type

of the form

set



ftyv{M)



((J/M*i)) Vftyv(*) 1

appears in A

(where the 3>j

appear in

T),

and any free term variable in ftmv(M)

appears in T.

(2)

Look at the rule

Polymorphism

hypothesis and conclusion X 0 Ur ftyvi¥j) where

Terms

introducing

are

assumed to be well formed.

the

3>j

appear in T.

Why

AX.F. This

The

means

is this restriction

that

(very)

sensible? Proposition 5.2.12

weakening

We

can

of type and term contexts,

rules found

Sgtm



on

page 125. For

along with a rule example, the rule

A,X|r,x:¥hM:# Sgtm Sgtm

where

derive rules for the permutation and

r[G/X]

means





of

substitution, mimicking the

of substitution is

A\T\-N:¥

Sgty



A h

A|r[6/X]l-M[JV/a;][e/X]:*[e/X]

substitute 6 for X in all

raw

types appearing in T.



212

I—

Chapter

Term Variables

Sgty

5</ts

Al-r



Sgtm I—





Sgty

Ah¥



A\-T

A|r,s:¥,ri-ar:¥

Unit Term

Sgty Sgtm I—

Polymorphic Functional Type Theory

5.

Function

Sgty

Sgty

Sgtm

A\T\-{): unit







...

Sgty



A h

*n



A|rhfc¥:¥[*/A*]



Vy

Ah*!



A\-^, :

Sgtm

Sgty

A\-T

Symbols Ahr







(fc:Afc;¥)

AH¥n

Sgtm > A \ T h AlrhM^^^/A^] 5ptm > A|rh/#(M1>...,M0):S[tf/A'] ...

Ma:

¥a[4?/A']

(/iA/;*!,...,*.^*) I—

Binary

Product Terms

Sgtm



A|rhM:¥ Sgtm

Sgtm

A|rh(M,iV):¥x#



Sgtm





|Th



Sgtm

Sgtm





| T h Fst(P): ¥

ty**"

Figure

P: ¥

A|n-JV:#





> >

5.3: Proved Terms Generated from

A A



|Th

P: ¥



tf

| T h Snd(P): * 2Ax-Signature.

5.2.

I—

The

Syntax

and

Function Terms

Sgtm

Sgtm Sgtm



Polymorphism

A|n-Ax:¥.F:¥=>#



A\r\-M:¥^y Sgtm

Sgtm Sgtm



A\V\-MN:V



A,X\T\-F:¥



|T

h N: ¥



A\T\-AX.F:VX.¥

|T

h M#:

A|rhM:¥

7VP







Ah¥

¥[#/*]

Typing Sgtm



,%*m Figure



A|rhM:VX¥ Sgtm

Sgtm Term



Terms

Sgtm

I—

A|r,x:¥hF:#



Sgtm I—

213

Equations of 2Ax-Theories





Ah¥



¥'

A|n-M:¥'

5.4: Proved Terms Generated from



2Ax-Signature,

Continued.

214

Chapter We

PROOF

use

induction

Note that

care

where

needs the

one

the derivation of

on



Discussion 5.2.13

term

where A



T h M: ¥ and A

the notion of



theory

A 2Ax-term



|T

h M

pair



Symbols, then

raw







types.

judgement

of the form

M': ¥

proved terms. We can now define polymorphic functional type theory.

T h M': ¥

is

{Xi,..., Xn}



a-equivalence of

in second order

theory Thtm

ftyv(¥)

equation-in-context is



A, X | T, x: ¥ h M: #.



<s>[*i[e/f],..., *?[§/y]]



denotes

equality symbol

Sg

with the rule Function

result that if

¥¥/x][G/Y] where the

dealing

is needed when

general

Polymorphic Functional Type Theory

5.

are

(Sgtm, Axtm)

where

Sgtm

is



2Ax-term

equations-in-context, each equation- in-context known as a term axiom. A term theorem is a judgement of the form Thtm > A | T h M M'\ ¥. The term theorems are generated from the rules given in Figures 5.5, 5.6 and 5.7. We can then define a 2Ax -theory Th to be a pair (Thty, Thim) where the 2Ax-term signature of Thtm depends on the typing theory Thty. A theorem of Th will then be any type theorem or any term

signature and Axtm is

collection of term





theorem. Note that

where

Sg

we

(Sgty, Sgtm)



will sometimes refer to

and Ax

From





2Ax-theory

Th



(Sg,Ax)

(Axty, Axim).

always be working with a given 2Ax-theory Th given by ((Sgty,Axty), (Sgtm, Axtm)). We will usually omit superscripts from such expressions, providing the meaning is clear. So, for example, we will just write Sg > A h 3>: K to mean Sgty > A h ¥: K. This overloading of notation should in fact aid clarity. Remark 5.2.14

5.3

Deriving

Discussion 5.3.1



now

on,

we

shall

Categorical Semantics

Some of the forms of

theory

are

(&)Sg



A h^ where A

(b) Sg



A|rhM:¥

judgement

which arise in

d= [Xi,...,X?], and

where T

=f [zi:¥i,... ,xm:¥m].



2Ax-

5.3.

I—

I—

Deriving

Categorical



Semantics

215

Axioms Axtm



A\T\-M



M':¥

Thtm



A|rhM



M':¥

Weakening Thtm

A|n-M



Thtm

A'|r



M':¥



hM

M':¥



A C A' and T C

(where

T')

I— Permutation Thtm

7Vm

A|n-M



ttA





M':¥



ttT h M

(where

M': ¥



and ir'

7r

are

permutations)

I— Substitution







Thtm

e'



A,X\T,x:¥\-M



Thtm

I—

Ahe







| T[B/X]



Thtm

M':V



M[N/x][0/X]







|T

h JV



JV':¥

M'[N'/x][e'/X]: *[B'/X]

Equational Reasoning Sgtm Thtm



Thtm

A|rhM:¥



A\T\-M >



M:¥

A|n-M



7%*m

I— Unit

M':¥



A\r\-



Thtm



A|T I-

M'

7Vm

A|rhM



Thtm

> =



|T

h M'







M':¥ M:¥

M": ¥

M":¥

Equations Sgtm Thtm

Figure







A\T\- | T h ()

M: unit =

M: unit

5.5: Term Theorems Generated from



2Ax-Term

Theory.

216

I—

Chapter

Binary

Product

A|rhM:¥ Sgtm



Thtm

Sgtm



A|rhFst((M,iV))



7Vm







|Th

P: ¥

|rh







A|ri-(Fst(P),Snd(P))

N: *



AT: *

N:V

* =

P:¥x*

Equations Sgtm



Thtm

Sgtm >



A|r,x:¥hF:^ Sgtm >

A|rh(As:¥.F)M

A\r\-Xx:¥.{Mx)

Thtm

> =

A|n-M:¥=>#

Thtm

Figure

Type Theory

M:¥



A|n-Snd((M,AT))

Sgtm

Thtm

Functional

|Th





a|:rhM:¥ Sgtm



Thtm

Function

Polymorphic

Equations

Sgtm

I—

5.







M:¥=>V

A|r,x:¥hF

A|rhAa;:¥.F



5.6: Term Theorems Generated from



A\r\-M:¥ F[M/ar]:tf

(where



£ ftmv(M))

F':#

Ax:¥.F':¥=>*



2Ax-Term

Theory, Continued.

5.3.

Deriving



217

Semantics

Categorical

Polymorphism Equations Sgtm Thtm

Sgtm Thtm



A\T\- (AX.F)V





A,X\T\-F:¥ Sgty



A\r\-AX.(MX)

Thtm

Term

Typing





M:VX.¥

A,X\T\-F

A\T\-AX.F



(where







£ ftyv(M))

F':¥

AX.F':VX.¥



Thtm



A|ri-M Thtm

Figure

F[V/X]:¥[V/X]

A|rhM:VX¥

Thtm

1—



Ah*







M':¥

a\t\-m

5.7: Term Theorems Generated from

Thty

Ah¥



==

¥'







m ':¥'

2Ax-Term

Theory,

Continued.

The discussion

begins with the semantics for proved types. Suppose that we are given a 2Ax-theory Th (Sg, Ax). Let us begin by recalling the idea of a type a in an algebraic theory. We think of a, very roughly, as a collection of items (terms) all of which have a similar property. In particular, a judgement =

of the form X\.ot,... ,xn:a h M:a says that if xi,..., xn all have the

same

property. Now think about

property

("have type a")

then M has

type-in-context X\,..., Xn h ¥. One thinks of this as saying that if each X{ "is a type" then so too is ¥. If we regard the notion of "being a type" as a property, then we might try to consider the collection of all items having this property. By analogy with the algebraic case discussed above, this collection (written Type) could be thought of as a type: the

same



Xi: Type,..., Xn: Type h ¥: Type. To avoid confusion, in this

setting we replace the word referring to a collection (type) with kind. Thus Type is the kind of all types. Sometimes Type is called the "type of all types." We now have a setting very much like an algebraic theory in which ?

there is

one

type

new

(cf. kind),

denoted

by Type,

218



Chapter

there

function

are

symbols (cf. type symbols) F:

Type,..., Type



where F has arity

Following

an

-+





length

Functional

Polymorphic

5.

with

Type Theory

sorting

Type



(cf. arity a).



argument similar

3.4,

to that in Section

we see

that the kind

interpreted by an object in some category C, which will have finite products in order to interpret type contexts. Let us put [Type] U where U is an object of C. Let A [Xi,..., Xn]. With this, a proved type of the form Ah¥ will be modelled by a morphism [A h ¥]: [Aj UofC, where [A] W}U. In fact we can achieve all this if the objects of C are simply finite products of the (distinguished) object U. We shall write f/n, where n 6 N, to denote a product of n copies of U, where U° 1. Type

must be





—?





meaning of Sg > projection morphism

It is clear that the intended

A, will be interpreted by



Ah 7r:

X, where X appears in

II"C/

—?

U. The idea of



type symbol F of (non-zero) arity a is that it takes a input types, and returns a new type for which we have an intended meaning. So for every such symbol we

specify



morphism [F]: U"U

[A



U in C and then define

—*

F(*!,..., Stt)] d^f [F]



([A



¥J,..., [A



SJ)

types for type variables will be modelled by composition of morphisms in C. Now let us think where

we are

following

the

about how to interpret the

paradigm

that substitution of

raw

remaining forms of proved type. We recommend

the reader to review Discussion 4.4.1. We shall need: ?

For Unit



For

Type,

Binary



morphism Un

Product

Types,

object

U for each



G N.

operation

an

Dun: C(Un, U) for each

—>



C(Un, U)

->

C(C/n, U)

Un of C which is natural in Un. This

means

that if 6: Um

—>

Un,

then

writing C(Un, U) for the collection of morphisms Un C—this is not necessarily assumed to form a set. Note that



we are

For Function

Types,

an

operation

Oum C{Un, U) natural in Un. So for any 6: Um



—?

0Un (cf), iP)o0

C(C/n, U)

Un =

we

-+

C(C/n, U)

have

OUm(4>o9,iJjo0).

—*■

U in

Deriving

5.3.



For

Categorical Semantics



Polymorphism Types,

219

operation

an

Vt/n: C{Un xU,U)-+ C(C/n, U) natural in Un. So for any 9: Um

Vtfn(<£)

Un

—?

o0

we

have

VUm{4)o(0x idv)).



example, we would put [Ah¥x*] d= DlAl([A h ¥], [A h fl). With these definitions, it is possible to show that if A h ¥ (where A has length n) and A' h ^ for 1 < i < n are proved types, then

So,

for

[A' where

[^/A]

Before model

for j

denotes the

we can

proved 1 to



<f>j =f [A

S[tf/A]]





expected more

say any

terms. In the

and

Sg ¥,-] and <j>



argument similar

[Ah¥]o ([A7



> =

*J,..., [A'



about these

operations,

Ah¥. Let us write I



(1)

¥?])

simultaneous substitution.

judgement (b) (page 214),

[A



¥],

thus

have

we

we

we

consider how to

have

Sg

A h

D>

¥j

for Un in C. We also write

fa.fa.I

-+

U in C.

Using

deciding how to interpret proved terms of equational type theory (see Section 3.4), we see that we would like to interpret the proved term (b) by a "morphism of the form" an

to the

[A | T

one

for

h M:

¥]: fa x

...



<f>m

—?

</>,

binary product and <j>j and <j> are objects of a category. How can we make sense of this? Well, we can demand that each of the collections of U index the collection of objects of a category which has finite morphisms I products! We shall write C(I, U) for this category. This gives a framework for giving a categorical semantics to judgements of the form (a) and (b):

where



denotes



—?

I—

Properties

We need products of



an

collection

of



Framework for

Interpreting

Th

category with finite products C whose objects

object U. Proved of morphisms Un



are

all finite

interpreted as morphisms in C. The U in C are the objects of a category with finite C(Un,U), and proved terms are interpreted as morphisms types

are

—>

products, written

ofC(C/n,C/). Now Th. We

we

deduce

begin

with

some more a

facts about

our

proposed categorical

discussion of how to model the substitution of

for type variables which appear in

raw

terms.

Suppose

that J is



model of raw

proved

types term

220

Chapter

of the form A A' h *4 for i



1 to



J1?..., Jn are proved types of the form We shall write ^ d= [A' h *J, ^ =f [A h ¥,-],

n.

how

see

and

=f [A | T h M: 3>J: &



we

should



...



<f>m

—>

interpret the proved

<j>.

term

A/|x1:^1[#/X],...,xm:¥m[#/X]hM[#/X]:¥[¥/X]





Type Theory

T h M: ¥ and that

*S [Ah*],'"[A],/'=[*!

Our aim is to

Functional

Polymorphic

5.

interpretation ought to be a morphism in C(I', U). Clearly, the required morphism depends on the ipi, which are objects in C(I',U), and on m which is a morphism of C(7, U). So we need an operation whose

obC(I',U)



...

Note that C has finite F

Given such

an



obC(I',U)

products, and

C{I'J)



operation F,





morC(I,U)

—?

so

equivalently

we

morC(I,U)

(0)

source

and target.



(V>i,







,ipn)i

This

gives

behaviour of substitution of terms.

It remains to

instance A

and so

we

| x: ¥

shall



x:

and

an

operation

morC(I',U).

...



0m<¥

</><¥



have used equation (1) to compute the a general framework for interpreting the

we us

raw

types for type variables which appear in

what

F must

raw

enjoy. First consider the

want

require

WH) Second, consider A | yim. ¥[ h N: ¥i

two

more

proved

terms

are



h h

J, namely proved terms





X\:§\ h M:¥ and

M[W/xi][¥/X]:¥[tf/X] M[¥/X][JV[¥/X]/a;i]:*[¥/X].

identical

F((4mon)

(2)

^.

instances of

and consider the

A'|yi:^i[¥/X] A'li/ii^i^/X] These two



properties ¥ of J. We certainly see

need

set

we can

[J'J ^ F?¥, m) : &(¥ where

—?

morC{I',U).



by definition,

and thus

F((im)oF(W,n).

we

must have

(3)

Deriving

5.3.

Let

summarise

us

221

Categorical Semantics



deductions.

our

Suppose

that

ip

{ip):I'



—*

/ is any

U is an object of <f>ip where <f>: I F(ip, <t>) / in C, C(I, U), then equations (2) and (3) say that for each morphism ip: I' we must have a functor F(V>, —): C(I, U) C(I', U). Now consider instances

morphism

in C.

If

write

we

—?



—?

—?

of the 7Tj

judgements J* being

[A



Xi\:I



precisely J,

and

A h

X* for



that there

projections £/. In this case, the instance of the judgement J' is

—?

so we must





1 to n,

so

are

have



lJ]



lJ']^F((7r),m)

that is

F(idi,m) Finally

consider the

case

(4)

m.

when J is of the form

X\T

h M: 3>

(son

namely A' h W and yh'J'. It is easy to

and two instances of J\ shall





see



here),

that

we

require

F^o^,m) by considering



F(^,F(^,m)),

(5)

the order of substitution of # and #'. Let

Recall the definition of



C-indexed category and of

us

summarise

reindexing

again.

functor. With

mind, and writing ip*(—) for F(ip, —), equations (4) and (5) (together with the definition ip*((j>) (pip given above) say that id} idc(i,u) and (iP'iP)* V>* o rl?'*. Thus: this in







I—

Properties

We need



of



Framework for

Interpreting

Th

category C with finite products whose objects



are

all of the form

£/n, together with a C-indexed category C'.C0? —? Cat. If xp\ V —? / is a morphism of C, then the objects of the category C (/) are morphisms / —? U \ in C, and the reindexing functors ip*:C(I) —? C (/') send an object <f>: I —> U \ to <f> o -0: /' -* / -+ U. We will usually write C(7,17) for the fibre C (/). Let

given such a C-indexed category. Now we can say more about the natural operations □/ and <>/? If we apply a procedure identical to that of Discussion 4.4.1 to Binary Product Equations and Function Equations we will deduce that each category C(I, U) is in fact cartesian closed and that each of □/ and 0/ may be soundly interpreted by x and =>. The naturality of these operations (recall page 218) amounts to requiring that the reindexing functors are strict cartesian closed functors. us assume

that

we are

complete our analysis of the semantics of 2Ax-theories, we deduce the properties of the categorical model which will provide a sound interpretation of the rules for Polymorphism Equations. As we saw on page 218, there must To

222

be

Chapter

5.

Polymorphic Functional Type Theory

objects Vi'.C(I x U,U) C(I, U) which is natural in the object / of C. If </>, -0: / —*U are objects of C(7, £/), we shall write C(I, U)(<f>, ip) for the collection of morphisms <f> ijj in C(I,U), which is not necessarily assumed to form a set. In order to interpret the rules Polymorphism Terms we shall need an operation an

operation

on

—?

—?

(-):C(I



£/, £/)(<?>), 4>) ^C(/,£/)?>,V7(0))

(where 5r1:/x[/-+/) which is natural in / and ip, and V(p): C(J, t/)(V, Vj(0)) for each

object

p of

C(I, U),



an

operation

C(J, t/)(V, 0K,p? V(p)

such that each

is natural in / and

tp. We

write out the formal

naturality equations. Take morphisms f:-K\(xl)) in C(7 x C/,C/); n:ip' ^ ip and m:<0 V7(0) in C(I,U); and 0:7' £/ in C; then naturality says that /', and p: 7 7rJ: /' x £/ -?

—>

-+

7,



/on

(6)



**(/)

(7)

0*(V(p)(m))



V(0*(p))(0*(m))

(8)

V(p){m)n



V(p)(mn).

(9)

(OxiduWf)

categorical

our

</>

—?

foir{(n)

For

—?

structure to

the

satisfy

Polymorphism Equations,

we

require

where 7r2: I x U to be



v(P)(7)



(id^pYU)

(io)

V(7r2)(7r1*(m))





(11)

projection. These equations force the operation (—) bijection. To see this, define an operation —?

U is

H:C(/,C/)(^,V7(0)) —,C(/

by



(11),



V(7r2)(7rJ(m))

with 7rx and 7r2

as



J7,l7)(7rJ(^),^)

above. Then

clearly







using

and









V(7T2)((7Ti



(id,7r2)*((7Ti

(7Ti,7T2)*(/)

?*)*(/)) x

id)*(f))

tWtfl0(7) using (10)

for (—)*

is

functorial

Deriving

5.3.

Categorical Semantics



In fact it is not

only

necessary that

/, for which there is

is natural in



(-):C(Ix U,U)(7rlW,4>)

we

W(p)(m)

modelling

the

operation Vj

an

on

objects



C(/,C/)(^,V7(0))





Let

which

(*)

given such data, (id,p)*(m), and then check that the equations (6)



do indeed hold.

have

bijection

which is natural in / and ip, but also

define

223

For

sufficient.

we can

(11)

to

refer to these necessary and sufficient conditions for

us

Polymorphism Equations by

NSV.

The reader will

secretly suspect that the operation Vj may lift to a functor the category C(I x U,U), and that the bijection arises because the functor

on

right adjoint Vj, for each J. In fact this is the case, as we now show. <f>' is a morphism in C(I x £/, £/), and we are given the Suppose that I: <f> operation Vj on objects along with the bijection natural in J and ijj. We can lift 7TJ has



—>

V7 to

functor



V7:C{I

U,U)



C{I, U) by setting V7(J) d=

->

oid^y



With

definition, it now makes sense to consider the naturality of the bijection If and lorh= [V/(i) o m]A. These (*) in <f>, which would state that Vj(£) o f equations do hold, for example, this



V/(0 where





(f)

(i)

V/).







idfi^) o J

follows from In



naturality

idvj{<j)) in



ttJ(/)

Of

ip.

=(t) I

°

[^v7(^) J]A

(ii) together



with the

an

is

equivalent

identity,

we



—*

a*

where

do indeed have

to



(6



idv)*

6:I'-+ImC,

specifying

conditions NSV. Let

U is

us

(i) and V// o (0 x idv)*.

refer to conditions

d^ {¥

an

5.4, where



iduYiid^))

we

give





^(V/(^))

exercises.

are

—^

we

may

V//((0



put together

formal definition of

indexed category in which

some

of



at

given by

All of the deductions of this section Section



requirement that the canonical natural transformation





If

course, the existence of such

(ii) by NSH. Note that part of the force of (ii) is that 0* o Vj By canonical natural transformation, we mean that the component (f>: I



Vj),

a:0*oV7 —>Vj, is



fact, specifying

adjunction (7r*

an

=(6) I

which is natural in both (f> and ip implies that

bijection

(7rJ



tdi/)*(^)). at the start of

2Ax-hyperdoctrine, which is soundly interpret a 2Ax-theory. First, a

224

Chapter Refer

Exercises 5.3.2

(1)

Make

sure

(2)

Work

through

(3) Verify why

Polymorphic

5.

Functional

Type Theory

to Discussion 5.3.1:

you understand the notion of

the details



kind of types.

accompanying equations (2)

to

(4).

operations (—) and V(p) and check that they are well defined. Derive some of equations (6) to (9), ensuring that you understand in each case how the associated naturality conditions are modelling we

need the

substitution in the syntax.

(4)

Derive

equations (10) and (11).

(5)

Prove that

sufficient to

(6)

categorical structure satisfying NSV model the Polymorphism Equations. a

Prove that the conditions NSV

5.4

equivalent

to NSH.

Categorical Semantics and Soundness Theorems

DISCUSSION 5.4.1

(i)

are

is indeed necessary and



2Xx-hyperdoctrine

is

specified by

the

following

data:

products, which consists of a distinguished object U which generates all other objects using the operation of forming finite products, which is to say that all objects in C are of the form Un with n G N where U° is a terminal object and Un (for n positive) is the product of n copies of U. We shall refer to C as the base category of the hyperdoctrine. A category C with finite

(ii)

A C-indexed cartesian closed category,

C(—, U): C*9

—?

COCat, where COCat is

the category of cartesian closed

categories and strict cartesian closed functors. Given an object / in C, the underlying collection of objects of the cartesian closed category C(I, U) is indexed by the collection of morphisms I —? U in C, and C(J,U) is called the fibre over the object /. Given a morphism /:/—>/' in C, we shall write /* C(/, U):C(I\ 17) —? C(7,17) for the cartesian closed functor assigned to / by the functor C(—, U). =

(iii)

object J of C we are given a functor V/:C(J x U, U) C(7, U) which is right adjoint to the functor 7Tj:C(J, 17) C(I x U,U). Moreover, / in C, the diagram of functors given any morphism /: J For each

—?

—?

—>

C{I (/



xU,U)^ ̄ C(I,U) r

iduY C(J



17,17)

—*

C(J, U)

Categorical Semantics and Soundness Theorems

5.4-

225

commutes, and the canonical natural transformation 9*oVj is

an

—>

Vjo (0



idy)*

We call the commutation of this

identity.

the canonical natural

diagram and the specification on Beck-Chevalley condition for 2Ax-

transformation, the

hyperdoctrines. 2Ax-hyperdoctrine. A type structure Mty for a U in 2Ax-type structure Sgty is specified by giving a morphism [F]:C/n C (equivalently an object [F] in C(Un,U)) for each type symbol F of Sgty, where n is the arity of F. Using these data we can now give the semantics of proved types. If A is a type context which has length n, then we define Un. For each judgement of the form Sg > Ah¥we specify an object [AJ [A h ¥] of the category C(£/n, U) using the rules given in Figure 5.8. We have the following lemma which embodies the slogan that substitution of raw types Let C'.C*

-+

COCat be



—?



is modelled by composition of morphisms: Lemma 5.4.2 let A h §i be

Let A' I- \I> be

proved types for i

[A PROOF



Induct

tt[*/X]] on

that

[A'



¥]

proved type



[A'



1,...,

*]

([A



that

Suppose =

[A



0] o n

Sg

where

where A'

Then

n.

the derivation of the

Corollary 5.4.3 case







Sg





SJ,..., [A



proved type Sg

n:

[A']

—>

[A]

SB]>



A I- ¥ and A C



[Xi,... ,Xn] and h # [¥/X] and



A' h ^.



A'. Then it is the

is formed from

product

projections. PROOF



Immediate from Lemma 5.4.2.

Sgty

2Ax-type signature. If A h ¥ ¥' is any type equation-in-context, we shall say that Mty satisfies the type equation-in-context if [A h ¥] and [A h ¥'] are equal morphisms in C. Given a typing theory Thty (Sgty, Axty) we say that Mty is a model of Thty if Mty Discussion 5.4.4

Suppose

that

is







satisfies the type axioms, that is Ax We have



Ah¥



soundness



¥'

implies

[Ah¥]



[Ah ¥'].

theorem, namely

typing theory Thty Then Mty satisfies all the type theorems of Thty. Theorem 5.4.5

Let Mty be



model of a



(Sgty, Axty).

226

I—

Chapter

Type

Unit

Type Theory

def



[Al

tt:







[A]



->

Type [A

(where 1—

Functional

Variables

[A',I,AH X\ i—

Polymorphic

5.

1 is the terminal

Type Symbols

[A [A





uni*] d=

1:

[A]

->?

[/

object of the cartesian closed category C([A], U))



K\ d^f [^]o!:[Al^l

(where

-?tf

jFsT has

arity 0)

<f>n : [A] ^ t/ *i] :0i:[Al^l7 [A I" *?1 [AhF(*!, *?)] d= [F] o(<f>u.. .,*?): [A] -+Un^U h







..



?.

?,

(where I—

Binary

Product

[A



F has

ilon-zerc>

Type

*]



0: [A]

->

[Ah¥l

17

[Ah#xfJ=^x 1—

Function

^: [AJ



^:[AH[/

->

Z7

Type [Al- *1



[A

0: [AJ -?tf

[Ah¥=> I—

arity n)

*Jd=

4>

=?



*J

==

tf: [A] ->/7

i>: [A] ->£/

Polymorphism Types [A,Xh§]

[A Figure 5.8: Categorical Signature.





^:[Al

xU->U

VX.S] 1* V|A1 (</?): [A]->I7

Semantics of Proved

Types Generated from



2Ax-

5.4-

227

Categorical Semantics and Soundness Theorems

The proof is

PROOF

with respect to the rules

2Ax-term



specified by giving



given

page 208 for

on

We need

DISCUSSION 5.4.6

given

routine verification of the closure of the semantics



little



model Mty of

Then

Thty, together

term structure



with

morphism





theorems.

Suppose

notation.

more

Sgtm(Thty).

signature

deriving type

that

we

are

Mtm is of the form

[/]:[Ah*Jx...x[AI-¥n]-[AI-¥] sorting /: A; ¥i,..., ¥n —? ¥, and a global element [k] of [A h ¥] for a constant k: A; ¥. Given a type context A, if Sg > A h T for some term context T [x\: ¥i,..., xm: ¥m], then we shall define [A h TJ =f II? [A h 3>J; and we define [A h rj d= 1 if T is the empty where



is



function

with

symbol



list. Then for every judgement Sgtm

[A | in

T h M:





3>J: [A



|T

T]

h M:

[A



C([A], U) by the clauses given in Figures 5.9,

Let A

Lemma 5.4.7 and let A

|T

that A







morphism

The

remaining

specify

¥]

syntactical substitutions

are

soundness theorem for term theories.

|V

T h





we

5.10 and 5.11.

results of this section show how various kinds of

modelled and include

3>,

My. ¥j be N[M/x\: ^ is

proved term, I" [xi: ¥i,..., xm\ ¥m] 1,..., m. Then it is the case proved terms for j a proved term, and that its categorical semantics is h N: # be







given by

[A|ri-JV[M/£]:#J



[A|r/hAr:^]o([A|rhM1:¥1],...,[A|rhMm:^ml). Proof

Induct

on

the derivation of the

Let

Corollary 5.4.8

Sg







judgement Sg

T h M:





|V

h N: #.

¥, and T C T' where F





[yi: ¥[,... ymi: ^'m,] such that Sg > A h ¥>j where 1 < j < m'. Let us write T [x\m. ¥i,..., xm: ¥m] where 1 < i < m, for the sublist T of F (and so each ¥i is a OJ, and each o^ is a y^). Then it is the case that Sg > A | F \- M: ¥ =

and

[A | r where

n:

Proof

II?'[A



¥£]

—>

h M:

II?

[A

3>]





¥J

Follows from Lemma 5.4.7.

[A | T

h M:

¥J

is formed from

o tt

product projections. □

228

i—

Chapter



tt:

[A

T'J





[A



¥J



[A

[A



rj

-?





T]

->

[A



¥J

Unit Term

[A | T (where 1—

Type Theory

Term Variables

[A|r,ar:¥,rhar:¥l ,—

Functional

Polymorphic

5.

1 is the terminal

Function



(): unit]

=!:

object of the cartesian closed category C([A], U))

Symbols

[Ah¥j





th:[A]->tf

[A

?-.



*?]



W [A]

->

U v""

[A|rh%:¥[*/Afc]]1i:f(^)*([fc])o!:[Ahr]->l->[Ah¥]o(v;) r

[A



*j1

[A | T









!Ahfn]= </>n: [A]

^: [A] -+U

Mi:

*![*/A/]]



mi:

[A



T]

->

[A



¥J



-+

"'I

tf

<¥

SB[*/A']] ma: [A h T] -> [A h *J <¥ (^>*([/l)o(m1>...>ma>: [A|ri-/?(M):^[*/A/]] [A h rj -> (nj[A 1- SJ) ¥) -+ [A h ¥1 <¥ [A | T



Ma:











(/iA';*!,...,*.-**) Figure 5.9: Categorical Signature.

Semantics of Proved Terms Generated from



2Ax-

5.4-

I—

Categorical Semantics and Soundness Theorems

Binary

Product Terms

[A | T





I—



h M:



h N: tf ]

[A | T

h P: ¥

Fst(P): ¥1

[A | T

[A | T

f [A | T (M, AT): ¥

[A | T [A | r



h P: ¥

Snd(P): ¥1



tf]



*J

7T

op:



*]





[A

[A

n:

[A

p:

[A



m:





r]



TJ

T]



[A

p:

[A



T]



TJ

[A

->

[A

->

-?

([A

->

¥]



#]



([A



¥J



[A

¥J



[A



*J)



([A h¥]x[Ah *])

-+



TJ



(m, n): [A



tt' op:



¥]

([A

¥1

[A

-)?

->

([A h¥]x[Ah *])



*])

[A

->



¥J

#J)

TJ







[A

->



tf]

Function Terms

[A | T, x: ¥ [A | T

h Ax: ¥.F: ¥

h M: ¥



h AT:

[A | T

T h MAT:

#J

[A

Polymorphism



*]

h F:

f [A | T [A |

I—

229

¥] =

r]

#]

=>

=> =

*1 n:

ev o

-+





[A

[A | T

h M*:

r]

[A

rj





->

[A



¥])





rj

->

([A

rj

->

([A

[A





->

[A

h tf J



¥1

=*

[A

¥1

=>

[A





#])

*J)

¥1

(m, n>:

(([A H¥l^[Ah ¥])



[A



¥1)

->

[A



*]

Terms

h AXP:

[A |



A(/): [A m:



[A,X|r h F:¥] [A | T

/: ([A

VX.SJ

T h M:

*[¥/X]l





VX¥1





/: [A m:



[A

r]



/: [A,X

T\



-+

r]

[A,X

->



¥1

VIA]([A, X

->

[A





¥1)

VX¥]

<?*,*,, [A



*l)*([^v(iA,yH*[y/x]i)]A)

[A



r]

(where

->

[A



Y does not appear in

VX¥]

->

[A

° m:



¥[*/*]]

A)

Figure 5.10: Categorical Semantics of Proved Terms Generated from Signature, Continued.



2Ax-

230

Chapter

[A | T

¥J

h M:

m:



[A | T Figure 5.11: Categorical Signature, Continued. Lemma 5.4.9 and let A h A

semantics is

Let A'

[A

h M:



T]





Functional

Type Theory

¥1

|T

\- N: <¥? be

AT[¥/X]:#[¥/X] h

is

N[¥/X]: #[<£/X]J

The

AT: \I>. We

A'

[A

rj



->

[A

A h ¥





¥'

¥]



Semantics of Proved Terms Generated from

([A PROOF

m:



7%**

¥]

proved





term where A'

1,...

proved



,n.





2Ax-

[Xi,..., X?]

Then it is the

term and that its

case

that

categorical

given by

[A | r[<£/X]



[A

->

¥j be proved types for i

| T[¥/X]

Sg

Polymorphic

Typing

Term

I—

5.





SJ,..., [A



*?])'([A' | r

the derivation of

proof proceeds by shall give an example

induction for the

case

|r

Sg

A' | T h TV: *



[A | T[¥/X]

Fst(AT): * h

where



on

where N is

h AT:

Sg

Fst(iV).

*]). A' | T h



Let

us

take

*'. We have



Fst(iV)[<£/X]: #[<?/X]J [A | r[¥/X] h Fst{N[¥/X]): tf [¥/X]] [A | r[4>/X] h iV[4>/X]: (# x tf')[¥/X]] =

6y

induction



7T o



n o



([A







SJ,..., [A

and



I- ¥





h AT: #

*?]>*([A' | T



*!],..., [A



¥nl)*(7ro [A'|T

([A



SJ,..., [A



<S>n]}*([A' | r



#']=[A'



we

have

#J



strict cartesian closed category

([A

¥?])*( [A' | T

([A

Note that in the above calculation

[A'





#'])

([A hSJ,..., [A h^B]>*(7f)o ([A



¥J,..., [A

SJ,..., [A





[A'



h N: *

h 7V:#

#']



[A'



*]

morphism

<S>n])* : C{Um, U)





C(C/", £/)

*'])

#'])

Fst(iV): *]).

projection





5.4-

Categorical Semantics and Soundness Theorems

from which

we can

the

exactly

deduce that the

deduce that

[A'J

7r:

Proof

¥nl)*{n)

#[<?/X]J



[A

I-

V[¥/X]])



[Ah

Once

suitable

satisfied

is

tf [¥/X]].

Sg

A'



—?

[A]

Sg > A | M: 3>, and

T I- M: ¥ and A C A'. Then

that

|T

h M:

\-

¥]



is formed from

tt*([A | T

h M:

¥])

product projections. □

Immediate from Lemma 5.4.9.

theory. a



Suppose

Discussion 5.4.11 in





[A' | r where

¥1],..., [A

Lemma 5.4.2.

Corollary 5.4.10 we can



projection

[Ah(¥x *")[¥/X]]=([A by using

morphism ([A

231

by

We

can now

define the notion of

again, the idea is to give



model of

interpretation of such

an





2Ax-

2Ax-theory

categorical structure, such that the axioms of the theory Suppose that Mtm is

the interpretation.

2Ax-term structure

Sgtm{Thty)

in





|r

h M

is any term equation-in-context,



term structure for

2Ax-hyperdoctrine C:C°p

we



are

-+



OOCat. If

M': ¥

shall say that Mtm

satisfies

the term

equation-in-context provided that [A | T h M: 3>J and [A | T h M': ¥] are equal morphisms in the cartesian closed category C([A]) C([A],f/). A model Mtm of a 2Ax-term theory Thtm (Sgtm,Axtm) is a term structure =



signature Sgtm in a 2Ax-hyperdoctrine CiC^ which satisfies each of the term axioms, that is Mtm for the

Ax We



can

which

term

A|TI-





M':¥

implies

[A | T

following soundness theorem assigned to 2Ax-term theories.

prove the

we

have

h M:

Theorem 5.4.12

2Ax-hyperdoctrine.

Let

Thtm be

If Mtm is

the term theorems of Thtm.





2Ax-term

model of Thtm

¥]

for the



[A | T

-+

h M'\

categorical

OOCat,

*].

semantics

CCCat a theory and CiC^ in C, then Mtm satisfies all of -*

232

Chapter

PROOF

The proof is

respect to the rules



Polymorphic

5.

Functional

Type Theory

routine verification of the closure of the semantics with

given

on

page

215,

page 216 and page 217 for

deducing

Mtm satisfies any of the equations-in-context which appear in the hypotheses of the rules for generating the term theorems term theorems. We show that if

of

Thtm,

then it satisfies the

rule. We shall give

The Th

is satisfied by Mtm. Let we

have

[A71T

h M:

¥]

calculations:

example

some

(Case Weakening):

Then

equation-in-context which is the conclusion of the

us

is that the theorem

assumption

A\T



write

\-M

[A'J

tt:



M':¥

[AJ

-*

and



tt*([A | T

h M:



7r*([A IT

h M':



[A'lr hM':f],

<£>J ¥J



Function

Equations): m

the definition of the



T'] ^[Ah Tj.

tt)

by Corollary 5.4.8

jt)

by hypothesis



us

Weakening

rule.

put:

[A|rhM:¥]



/ d^f

Using

Let

[A

by Corollary 54.10

7T*([A \T'\-M: ¥])



which shows that Mtm satisfies the conclusion of the

(Case

tt:

[A|r,x:3>hF:tfJ.

categorical

semantics

we

have the

following

calculations:

[A I T



(Xx: ¥.F) M: tf]



Lemma 5.4.7

([A | T

h Ax: 3>.F:



evo(X(f),m)



ev o



using

ev o



(X(f)



id)



¥=*>¥], [A | T

(id, m)

fo(id,m)

[A | T



F[M/x]

(Case Polymorphism Equations):

Let

us

make the

definitions:

^ d^f

[Ah*]

<f> d^f

|A,Xh¥l

/ d^f [A,X|rhF:¥] 7r:

[A, X]

—>

h Af:

[AJ



the obvious

projection.

following

Categorical Semantics and Soundness Theorems

5.4-

Then

we

[A|T



have

(AX.F)*:*[*/X]]

(td[Ai,^>*(**v<*))



(?J[A],^)*(tdv(*))



(n



tmnp Lemma

For the final

V)



5.^.0



[A | T we





—?

{idiA,xh [A, X







Beck-Chevalley



Beck-Chevalley



(t[a] -*V[Aj)





subscripts

Exercise 5.4.13

of substitution."

the

following

sure

definitions:

|A,Xh¥l

[A|rhM:VX.¥]





the obvious

projection.



the obvious

projection.

categorical

[A,X |T



semantics

we

have

MX:¥\ °

[A, X | T

h M:

VX.S]

<td,7r£;>*[(idv,AlxU((irIA,xwu)*(^)))A] *"[A](m) °

(^,7rt/)*[(^7r*A1(vIA](^)))A] °^(m) (^,7r^)*[(7T[Aj



^c/)*(^vIA](^))] 07r[A](m)



m, /it,

have been omitted to

Make

Chevalley conditions: interpretations of VX

use

X]>*[(idV([A^,yh*[r/JCi]))A]

Cor's 5.^.5 and 5.^0

where certain

F[V/X]: ¥[*/X]].



to the definitions of the

[A|rhAX.(MX):VX.¥]

<*rf[A],^>*(^*(7))



7TJAJ- [A] x[/-+ [AJ Appealing



shall

<f> ^

[A]

°

(zd[Ai>V,)*(/)

example calculation,

7T{/:

h AXF:VX

<?<*[A],^)*[(?*V(*))o7T*(7)]



because

[A|T



(?*[A],^)*(?*v(*))°7





233

save

space.



that you understand the role of the Beck-

the informal

categorical model, the and AX abstractions commute with the interpretation slogan

is that "in



234

Chapter Let

Discussion 5.4.14

Polymorphic

5.

Functional

Type Theory

complete this section with the following definition. A structure M in a 2Ax-hyperdoctrine <C\Corp —*■ COCat for a 2Ax- signature Sg (Sgty, Sgtm(Thty)) is a pair (Mty,Mtm) where Mty is a model of Thty and Mtm is a term structure. The specification of Mtm depends on the specification of Mty. A model M of a 2Ax-theory Th (Thty, Thtm) (Sg, Ax) in a 2Ax-hyperdoctrine is specified by a structure (Mty, Mtm) for Sg where Mtm is a model of Thtm (and Mty is a model of Thty). We have us







Theorem 5.4.15

The

hyperdoctrine given by



categorical

semantics of

model M is



2Ax-theory

Th in



2Ax-

sound, that is, M satisfies all theorems

of Th. Proof

5.5

This is





restatement of Theorems 5.4.5 and 5.4.12.

A PER Model

example of a 2Ax- hyperdoctrine. Before commencing with the technical details, we pause to consider, in an informal fashion, the meaning of polymorphic types. Consider judgements Sg > X h ¥ and Sg > h VX¥. We have seen that <f> [X h ¥] should be interpreted as a morphism of the form U U in a category C, and of course [ h VX¥J: 1 U. Let us suppose that the object U is a "universe of sets." Then the interpretation of any proved type h ^ will be a set [ h ^] in U. Intuitively, VX¥ is an expression which acts like ¥ for all values of X. Thus one might postulate that x G [ h VX.3>] just in case x G \X h ¥1(0 for all sets £ G U. Thus we might set In this section

Discussion 5.5.1

we

shall present

an



—?

—?

[hvx.s]^n[*>*](o which will make now

with



formal

Discussion 5.5.2 to say the

provided the presentation.

sense

universe U is not too

We shall describe

model of the pure

Let

us

continue

2Ax-theory,

that is

2Ax-signature and no axioms. This model will be based on the notion of a partial equivalence relation, or a PER. A PER on a given set X is a binary relation on X which is symmetric and transitive. We shall just consider the case when X is the set N of natural numbers. So now let A be a PER (on the set N). We define the domain of A, Dom(A), by setting Dom(A) d= {a G N | aAa}. 2Ax-theory

with empty



large.

A PER Model

5.5.

It is easy to

Dom(A).

see

235

that A C

Recall that

Dom(A)

usually

we

equivalence

Ve

that

{Ve |



N}

G E C

is

We shall write

An./(n)

Vm G N.

(Note

equivalence

relation

on

A}





partial

recursive functions N

N.

—?

N where coding of such functions Ve: N N given by the code e G N. If An./(n): N



—?

partial recursive function partial recursive function then

Xn.f(n).

{[a] \



of the

use

is the

is any

an

classes of A.

We shall also need to make

Suppose

is

write

Dom{A)/A for the set of

Dom(A)



—?

there is

for such



VAn./(n)M

code



N for which



Ve



code e, thus =

f{m)e

N.

implicit use of the S-m-n theorem). If e and functions Ve and Ve/, then we shall write e'.e for

that this definition makes

e' code the the code

We

partial recursive of the composition of Ve and Ve>,

can now

natural

define

numbers).

a new

First



that is e'.e



An.Ve/(Ve(n)).

category VSR whose objects

little notation. If

/: N

—?

are

N is any

PERs

(on

the

partial endofunc-

/ is defined on a subset X C N if f(x) is defined for each x eN. If f(x) is defined, we shall sometimes write /(#) j to indicate this. Let A and B be PERs. If e G N, we say that e tracks from A to B if Ve is defined on Dom(A) and whenever aAa' then Ve(a)5V£(a'). We write tion

on

N,

Tr(A, B)

we

shall say that

for the set of those

equivalence



G N which track from A to B.

an

e' just in case a G Dom(A) Tr(A, B) by setting e B in Ve(a)i3Ve/(a). With this, the collection of morphisms A

relation

implies

that

VSR, is

given by

on



—>

VSR{A, B)

(Note

We define



Tr{A, B)j

that





triple ([e],A,i?), but we shall is any PER, then the identity on A is id a [An.n]. Composition in VSR is given by taking the code of the composition of the corresponding partial recursive functions, that is if [e]: A strictly speaking, a morphism not be fussy about this). If A



—?

B is





—?

B and

[e']: B

-?

C then

Exercise 5.5.3 Discussion 5.5.4

[e']

Verify



[e]



[e'.e]: A^C.

that VSR is



well defined category.

It will be useful to

identify some elementary constructions on PERs. Let us recall how to encode the pairing of natural numbers via partial recursive functions. The partial recursive function p:NxN-+N

(n,ri)

?-*

{n,ri) d= (n + l)(n'







1)

236

is

Chapter

bijection of sets. If the inverse is denoted p_1: N



Functional

Polymorphic

5.

—■*



Type Theory

N, then



we

will

write 71"!

op-1





—?



m i—>

mi



7r1(p-1(m))

7r2

op-1





—?



m i—?

ra2



7r2(p-1(m))

where 7TX, 7r2: N x N

—>



are

coordinate

projections. This will allow

Km.rrii for the code of the partial recursive function 7Tj op-1: N will prove to be

(i)



convenient notation. We

Given PERs A and B there is

rii Ami and

(ii)

n^Brrii (for

any n,

and Ve/

are

defined

on

Dom(A)



give

our

PER Ax B defined

this,

we

have the

PER A

e{A

B where

=?

and also whenever aAa!

Theorem 5.5.5

Proof

Define

following

by n{A

PER 1

terminal

7T!

=f [An.ni]









-*







as

=>

tt2

d=

[An.n2]

—*■

—?

([e], [e']> d^f [An.(Ve(n), Ve,(n))] The

exponential of A and B is A. ev

If





is



[e]: A





—?



PER

f)iei Ai

=>

category.

n,m G N. —>

Then 1 is

1 for any PER A.

:AxB^B. is easy to

see

B. The evaluation

morphism

—?

is

B.

morphism of TER then the exponential

given by A(/) d=lf [An.Am.Ve((n,m))]: A

that the

:C-+AxB.

[An.Vni(n2)] :(A=>B)xA

C is any



defined in Discussion 5.5.4. The

A and [e'j: C B, then it morphisms [e]:C unique mediating morphism for the binary product is

Given

iff

B)e' iff both Ve then Ve(a)5Ve'(a').

cartesian closed



by setting n\m for every unique morphism [An.n]:A

object, with a The binary product of A and B is A projection functions are a

B)m



crucial theorem:

The category T^SR is



N, and this

—?

constructions.

(hi) If (Ai | i G /) is a non-empty family of PERs, then there is given by n(f]ieI Ai)m iff nAiVfi for each i G /. With

to write

N).





Given PERs A and B there is



can now

us

->

(B

=?

C).

mate of

A PER Model

5.5.

Let

us

237

show the universal property of

diagram

£—*

AxB

\(f)



First

exponentials.

we

show that the



idB

(B=>C)xB commutes. We have ev o

(A(/)



idB)

[An.Vni(n2)]



[Ax.VAm.Ve((xim,))(a:2)]



[Ax.Ve((xi,x2))]



W-



Next

we

[e]: A

—*■

uniqueness of the mediating morphism; (B =*> C) and that ev o (h x idB) /, that is show

V£R(A







£>om(^4);





(*)

[Ax.Vv.(xi){x2)]



B, C). We wish to prove that h

[e] Let

suppose also that h



[e] in

[Ax.(Am.Ve((xi,m)),x2)]





A(/),

that is

[An.Am.Ve((n, m))]. Ve(a)(B => C)Am.Ve((a, m)). Take b G Dom{B). Ashe VSJl(A, B => C) C)Ve{a) implying that Vv-(a)(^)l- One can

it remains to prove that

Recall the definition of B

=>

C.

we

have

Vg(a)|

Ve(a)(B =¥> check similarly that VAm.Ve((a,m))(&)l- Finally take bBb' for which it remains to show that Vv?(a)(&)C'Ve((a, b')). From (*) and that (a, b) G Dom(A x B) we

have

Vv-(a)(&)CVe((a, 6)). Also,

and

Ve((a, 6))CVe((a, 6')).

as e

tracks from A



B to C

The result follows from transitivity of C.

we

have □

Exercises 5.5.6

(1)

Work

(2)

Prove that V£R, has

try

to prove that any slice of VSR, is cartesian closed.

through the proof of Theorem 5.5.5. Prove in full detail that VSR, has finite products—be careful to verify all the details. In particular, check that all morphisms you specify are well defined. equalisers

Discussion 5.5.7

Now

In this discussion

shall

we

have indeed defined



we can

and

binary coproducts. If you feel ambitious,

present

an

of

2Ax-hyperdoctrine. structure; the proof that we

example



give the details of the 2Ax-hyperdoctrine C:Cop —? OOCat will follow.

238

Chapter

(i)

The

object

Polymorphic

5.

Functional

U which generates the base category C is



{A



C N x N



A is

PER



on

Type Theory

set, defined by



N}.

Let Un be the finite

product of n copies of the set £/, that is, a finite product in Set. Then the objects of C are of the form Un by definition, and a morphism Un Um is simply a set-theoretic function f:Un Um. —?

—*■

(ii) Let us write I for Un. We define the fibre CI C{I, U). The objects of C(7,17) are (by definition of 2Ax-hyperdoctrine) set-theoretic functions I —*U. =

Let



G / be any element of the set /. If F: I

objects

of the fibre

of the function F

over

/, then Fx and Gx

applied

to

PERs:

are

Hence there is

x.

U and G:I

—?



-+

here,

PER R





are

any two

Fx is the result

f]x i{Fx

Gx).

=?

We shall define

C(I, U)(F, G) d= Dom{R)/R. It will be

helpful to introduce the following convention: if we talk of a morphism G then it will be implicit that the equivalence class [e] is taken with [e]: F respect to the equivalence relation flxe/C^ ^ @x) on ^ie se^ D°m(C\x i(Fx ^ Gx)) and that for the morphism to be well defined, e G Dom(f]x l(Fx =¥> Gx)). —*

F in C(J, 17) is [An.n] G C(7,17)(F, F). Given identity morphism F H in. the fibre over /, then G and ip morphisms <f> [e]:F [e']:G set V ° <f> H. Recall the convention—[e]:F G refers to [e'.e]:F an equivalence class in H to an equivalence class in C(I,U)(F,G), [e']:G H to an equivalence class in C(I,U)(F,H). C(I,U)(G,H), and [e'.e]:F One needs to verify that these are good definitions.

The

->

—?■



-^



—*■



—*■

—*■

—>

We define



functor

C(—, U): 0°?

H:I'-+I where H sends

In

postulate

fact, such

C(7, U) see

us

an



—?



specified

structure

can

is the function 1:1

—?

morphisms 7T

by (F



by

the

assignment

C(7, U) G [e]:F

U of =

—>

to the

of

object

C(I,U)

FH: I'

be

given "pointwise."

U which sends each are

G)x



objects Fx



of



The terminal

and

of

G / to the PER 1 G C/"—

C(7, U)

Gx for each

V d=



C(7, £/).

object

then F



G: /

I. The



[An.n2]











—>

£/ is

projection

are

d= [An.nJ :FxG^F

—>

morphism

to the

cartesian closed structure for the fibre

Discussion 5.5.4. If F and G

the function defined

OOCat

H*:C(I,U)^C(I',U)

h-i.

object F:I of C(I',U), and the morphism <j> [c]:FJy-*GfTofC(/,,J7). Let

—?

G.

A PER Model

5.5.

exponential F => G: I —> U is defined by (F => G)x I and ev =f [An.Vni(n2)]: (F =^ G) x F -> G.

The x

239



(iii) Finally,

let

us

give

specified right adjoint



to 7Tji

Fx



C(7, U)

=>

—>

Gx for each

C(IxU, U),

say

V7 If F: I



defined

[/

£/ is

-?

an



C(/

object

of



£/,£/)

C(I

C(/, £/).

—?

£/, £/), then the function VjF: I



U is

-?

by A

for each



G I.

If

<£



[e]: F

—?

G is



t7

morphism of C(I



U, U) then \/j(f>



[c]:VjjP->V/G. The structure defined in Discussion 5.5.7 is indeed

Theorem 5.5.8



2Ax-

hyperdoctrine. Proof

We check that the concrete structure described in Discussion 5.5.7

satisfies the criteria

(i), (ii)

(iii)

and

in the definition of

2Ax-hyperdoctrine

in Discussion 5.4.1.

given

(i)

It is easy to

see

It is easy to

that C is the base of



2Ax-hyperdoctrine.

identity morphisms are as stated. Let us see that composition of fibre morphisms is well defined. Using the notation of Discussions 5.5.7, we first need to verify that e'.e G Dom(( ̄)x l(Fx => Hx)). Let x G / be arbitrary, and let n(Fx)n'. Because [e]:F G, it follows

(ii)

that fibre

see

—?

that

H,

Ve is defined

one

can

see

on

Dom(Fx)

that Ve'.e



Ve>

Ve/(Ve(n))(Jf/'x)Ve'(Ve(n/)) and so if [e] [e]:F^G and [e'] [e']:G =

is left To



as an

exercise. It is

simple

Ve(n)(Gx)Ve(n').

and

to

Ve is defined



we are

Dom(Fx)

[ef]:G

—>

and that

done. We also need to check that

#, then [e'.e] [e'.e]:F -> H and this check that composition is associative.

-+



verify that the functor C(—, U)

[e]:F [e']:FH

on

Because

is well

defined,

need to

see

that if

G then [e] [e']:F GH. First, if e G Dom{C\x l{Fx => Gx)) then it is clear that e G Dom(f)y l,(FHy => GHy)). Second, if e{C\x l{Fx => Gx))e' then it follows routinely from the definitions that e{{\y l>(FHy =¥> GHy))e'. It is immediate that C(—, U) is a, functor. The details which show that C(7, U) is a cartesian closed category for our -+

specified

G then

[e]:FH

-?

GH and that if

[e]

we

-?





-??

structure

are

essentially the

verification that VSR, is such



definitions. For this reason,

same as

those which appear in the

category, provided that we

shall

only show that

we

our

given sensible definition of binary have

240

Chapter

Functional

Polymorphic

5.

Type Theory

product projections is well defined, and leave all the remaining details exercise. To

that

see





[An.ni]: F

An.ni e





Dom{f]{{Fx x



—>

we

Gx)



as an

need

=>

Fx)).



So for any iG/we need to show that

An.rii((Fx Let a'.

a(Fx x Gx)a!. Also a1(Fx)a/1,

Then



Gx)

=>

Fx)An.ni.

certainly VAn.m {a)

from the definition of Fx



^i is

defined, and similarly for

Gx, and



we are

done.

(iii) We shall check that (Vj H 717). First we see that Vj is well G in the fibre C(7 x U, £/) we need morphisms). If <f> [e\. F Vj</> [e]: V/jF V/G. Let x £ I. We need to show that —?



defined

to

see

(on

that

—?



e(f| F(x,A)=^> fl^^))6- nf)A UF(x,A)n'. Hence for any A G U, nF(x,A)n'. Thus Ve(n)|, G by hypothesis, and with Ve(n')| and Ve(n)G(x, A)Ve(n/) because [e]:F this we are done. To complete the proof that (Vj H 717) let us use the Let

—>

characterisation of all

adjunctions given by Proposition 2.10.24. We shall now omit verifications that any morphisms we specify are well defined. We have to

define



counit

(natural transformation) c :

and

we

set e^



transformation. its mate

across

—?

id



C(I



U,U)

—?

C[I



U,U)

G. It is simple to verify that e is a natural [An.n]: 7Tj(V/G) If </> G is a morphism in C(I x 17, U) we define [e]: 7TjF the (asserted) adjunction to be <j> V/G in C(7, C/). [e]: F

We check that the

commutes:

71-; o Vj

—?■

—?





diagram

_

eGoTr}((f>)



[An.n] o7rJ([e])



[An.n]



W.



[e]

—?

241

A Domain Model

5.6.

It is easy to

commute,

see

and

Finally verify that verify that

that

<j>

have the

so we

to the

we come

unique morphism making the above diagram

is the

if H:J—*I in

required adjunction. condition. It is

Beck-Chevalley C, then H* o Vj



Vj



(H





simple

idu)*.

exercise to

We also need to

the canonical natural transformation

ariToVj —>Vjo(Hxidvy is the

identity, aG

and

^ (H

(H



check that its components

idu)*(idvliG))



identity morphisms

are

as

so we

in

JT (V,(G))



C( J, U).

idu)*(idvjG)



Vj((H



iduY(G))

We have

(H



idu)*{eG



(H



idu)*{[An.n])



[An.n]





7ij(tdV/G))



required. Refer to the

Exercises 5.5.9

(1) Complete

proof

the verification that

of Theorem 5.5.8.

composition of fibre morphisms

is well

defined and associative.

(2) Verify (3)

in detail that each fibre

C(7, U)

Check that the counit for and mates

is



cartesian closed category.

across

the

adjunction (Vj



717)

are

well defined.

(4) Verify

that H*



V7



Vj



{H



idu)*.

A Domain Model

5.6

Discussion 5.6.1

We shall

the pure

that is to say the

and

no

2Ax-theory,

axioms.

give

In order to do



this,

example of a model of 2Ax-theory with empty 2Ax-signature

domain-theoretic

we

shall set up

some

domain-theoretic

machinery which will use ideas from both Chapter 1 and Chapter 2. Before beginning, we give another informal discussion of possible interpretations of Sg > VX3>. As in Discussion 5.5.1, let U be some kind of universe of "sets." Write F [X h ¥]. If we regard [ h VX3>] as a uniform display of the interpretations F(£) where £ G U we might try to set [ h VX.¥] U^ UF(^). However, if U is too large, then the product will not be a member of U. A =



242

Chapter

way around this is to find



represented as a "union" or U, enough to make U^eSuF(0 U

example,



U will be

Polymorphic

subuniverse of

U is

our

5.



Su, in "colimit" of sets in Su, and

£/,

uUi SuF(0

where

—*■



S) A (\/{Fr,x(tx) |

In fact in

Su will be







S)

X G



set

can

be used to

where

Z/(X, £>)} |

f?x

is small

colimit of domains from §.



UxesFX G U and such colimits (rjx'- X induce an "isomorphism" i: Tlx<z§FX HrjeuFD

Su

ne t/F(£)."

category of domains and §

Then

X G



Type Theory

which every set in

say

of domains for which any domain D (EU will be

(tx |

Functional

D G

W).

We continue with the formal discussion. DISCUSSION 5.6.2

pair (e,p):



Let D and D' be

dcpos.

Then

an

D' consists of two continuous functions

—*■

e:

embedding-projection D

—>

D' and p: D'

-^

idrj, and ep < idry (the latter inequality holding in the exponential dcpo D' =¥> D', an object of the cartesian closed category VCPO). Such an e is called an embedding and such a p a projection. We will usually write just f:D —? £>' for such an embedding-projection pair, denoting the embedding by /e and the projection by fp, and will abbreviate embedding- projection pair to e-p pair. Note that e and p regarded as monotone functions between posets form an adjunction (e Hp). It follows from Theorem 2.10.6 that if a pair (e,p) satisfies the definition of e-p pair except that e is only required to be monotone, then e is automatically continuous. D for which pe



embedding-projection pairs, SDomep, has for objects the Scott domains, and a morphism (e,p):D D' between Scott domains D and D' is an e-p pair (where of course we note that any Scott domain is indeed a dcpo). The composition of (e,p): D —? D' and {e',p'): D' D" is given by the e-p pair {e' o e,p o p'): D D". The category of Scott domains and

—*

—?

—?

Before giving our domain-theoretic example of need to state and prove a number of results. Here is action: ?



2Ax-hyperdoctrine, we summary of our plan of

We prove that SDomep has all directed colimits—SDomep

the ?



distinguished object are

the role of

U. This is Theorem 5.6.3.

We show that there is

SDomep

plays



set of domains S of which all other domains in

directed colimits—S is the set Su described in Discussion 5.6.1.

This is done in Lemma 5.6.5 and Theorem 5.6.6. ?

Next

we

give

some

technical

results, namely Lemmas 5.6.8, 5.6.9,

5.6.11 and

5.6.13. Note that Lemma 5.6.11 shows that SDomep is closed under

indexed

by S.

products

A Domain Model

5.6.



Finally

243

show in Theorem 5.6.17 that the structure described in Discus-

we

sion 5.6.15 is indeed

2Ax-hyperdoctrine.



The category SDomep is directed cocomplete. Moreover, the directed cocompleteness is characterised by the following criterion. Given a Theorem 5.6.3

directed poset / and a diagram D: I —> SDomep, a cone (ki: D{i) —? C \ i G a (directed) colimit in SDomep iff the set of continuous functions {kfk% \i

regarded

as a

subset of the Scott domain C

idc We shall

PROOF Let / be

write



D,

explicit

an

say

D(j) (rii:D{i)

for the

—?

—?



I}.

i e

—?

SDomep be

i G

/),

as



diagram

l under D. Let

image ofi<j

limD

C is directed and

=¥>

construction of directed colimits in SDomep.

directed poset and D:I

fiji D{i)

under

give

[J{^&f |



/) is 1}

/. We shall

on us

define

a cone

follows. IvrnD consists of families

Si holds whenever i < j. The /) for which Si G D{i) and ffj(sj) elements (s^ | i G /) of limD are ordered pointwise. The e-p pair 7^:D{i) limD is defined by setting the continuous function rjf:D(i) limD to have ViWj ffkfikW where i,j G /, d G D{i) and k G / is any element satisfying S{ £)(i) is given by rjf(s) {h j} < k. The continuous function rfi: limD

(si |

i G



—>

—>



—>

where



G ^m D.

We claim that the

the

diagram

D. Let

nonempty meets i G

/) |

(t^: Z)(i)



/imD

—??

first check that such

i G

/)

family



is in fact



colimit for

is well defined.

cocomplete dcpo. Directed joins and given pointwise; we give the details for the latter.

are a

cone

us

The poset lim D is

{(sf |





A}



be

bounded



non-empty subset of lim D. If

we

set

provided (sf |

i G

Let

?d^ AK \°<eA}e D(i) (which

exists for

must be the

/??

is



Scott

domain)

then

required meet; but this is the

f!M) where

D(i)



/8(AW I





A})

preserves meets because it is

Scott domain

we





need to prove that it is

case

proof

that the

embedding

G Ztm D it

for

AU£K) I





A}





right adjoint. To see that lim D algebraic; this is done shortly.

We omit the easy details which show that rji is indeed

for the

J)

function

rjf

an

e-p

is



pair, except

is well defined. So suppose that

244

Chapter

{hj} and

{k, k'} in / (where that {k, k'} < k" in /. <

at least

Then

ni(d)i

one

proved

directed)

D(i):

fjkfkk"fkk"ffk\°) fjk fkk" fk'k" fik' (°) fjk'fk'k" fk'k" fik'W



have

Type Theory

ffJUd)





we

Functional

choice of k exists because / is

have for any d G

we



Now that

Polymorphic

5.

each

rjiiD(i)

limD is

—?

an

pair between

e-p

dcpos, we can show that Urn D is algebraic. We shall need a little more machinery. Let us show that {t]frf{ \ i G /} is directed in the dcpo Urn D =*> Urn D. Given i and j in / choose k such that {z, j} < k. Without loss of generality, it is enough to show 77*77? < ^%rj^. So pick any s G Urn D and show that for each r

G /

and

we

have

{k,r'}



77f(sj)r

Choose r' and r" in / for which

rjl(sk)r'



frr"fkr"fikfik\Sk)

f^fUSk)



Vk(Sk)r-



But

given Si

Ulvfrfi |?

any =

that is zd <

r'

frr"fir"\Si)









r". Then

Vi{si)r

In fact id

{i,r}





/}.

The

only thing

G Urn D and i G /

tfijfw,

Ufaf'/f |



we

UWMi /}.



Now

UivfVi \i



-0-

have

I ie -0

we

to prove is id <



KLKtftf I i e'})(?)]?

show that limD is

algebraic using

these

results. Note that

{ql(e) | because

embeddings

for some A; s







/, e



preserve

£>(z)°, e



satisfying {z,jf}











7,e



id(s)

D(i)°,e =

St}



{*

compact elements

Vt{e)j U{vf(e) |



i7?

(*i)i



k in /. <



(Zzm Z))° |

(why?),

JjkfikM We will



and

s}

t <

rjf (e)

SJ

have shown

algebraicity

sj. Now,

UtatfM \iel}



< s because

UWW |i



/}.

if

A Domain Model

5.6.

But si



U{e

D(i)° \





and

through

Now that it makes are

245

Si}

e <

|_KLN(c) Ie



we

know each r?f is

verify that (t^:D(i) us complete the details

—>

E \ Suppose that (hi'. D{i) mediating e-p pair h: Ivm D —?

/}.

/)

i G



—?

is

a cone

Finally

and that h is the

unique such morphism;

1*6



25

directed



cone; the details



he a

diagram

Ul^f7^ |



we

is

cone

i G

colimit.



D. Define

1}

and /ip

a =

definition of /i, that is,

good

we

have

just verify that herj}

hi





horji

/if:

/,i>o

*??



follows

is

under the

UWIi



Thus SDomep is indeed directed

/)

(UW I i e/})tf UWtflie/} \_\{h%r/jTjf \ j E I,j > i}





as

i G

that for any i G /

h is well defined.

see

done.

which show that the

by setting

need to

/},

pair between Scott domains,



limD

so

< e

we are

We omit to check that this is we

*} I



well defined e-p



to

sense

i G

^(OV



and

algebraic

is

rearrangement of directed joins



omitted. Let

Uivth? |

D(i)

for

cocomplete

and the characterisation

now

easily:

(=>) Given



directed

D:I

diagram

SDomep and

—>

a cone

(ifei:D(*)-*C|i l) for which idc define



using

an



|_l{&f&f |

mediating

e-p



/}

pair k:C

then the

—?

cone

identical construction to that in the last



—?





Exercises 5.6.4 Prove that 77*:

family

forms

(2) Verify limD.

With reference to the

D(i)

a cone

—>

lirr^ D

for the

is

an

diagram

in detail the universal



E for any other

(<£=) Conversely, given a colimit (kf. D(i) C and certainly &* isomorphism 0: lim D 07^; the

(1)

is

e-p

D:I

colimit because

cone

(ft: D{i)

—>



we can



i G

/)

paragraph.



i G

/)

there is

an



result follows.

proof

of Theorem 5.6.3.

pair for each i G /, and that such —?



SDomep.

property of the

(asserted)

colimit t^:

D{i)

—?

246

(3)

Chapter Make

implication (=*>)

you understand the

sure

Lemma 5.6.5

Let

Functional

Polymorphic

5.

of the

Type Theory

proof.

pairs between Scott domains where X and Y are finite. Then there is an e-p pair (i,h): Z —*■ D with Z a finite Scott domain for which {fefp, gegp} < ih in D => D, and moreover there



are

(i,h)



pairs I

e-p

ol and g

The set Z

/e/p

and

the inclusion i: Z

D and

(hfe,fpi):X (i, h) o m.



<7e#p

—?



PROOF < id

f:X

=f {fefp{d)



g:Y

D be e-p

—?

Z and

—*■

gegp(d) \

< id. The set Z is a



d G



(hge,gpi):Y

D}

—■*

Z where

is well defined because

poset with order induced from D and

clearly monotone. Now consider a function h:D-+Z defined by /i(d) d= /e/p(^) V gegp(d) for d G D. By definition, i/i < idD. It is routine to verify that h is indeed continuous and that hi idz', we just give some of the details for the latter equation. Suppose that d G D and that fefp(d) V gegp(d) is a typical element of Z; it remains to prove that —?

D is



fefPUeF(d)



g<gp(d))



gegp(fefp(d)



^(rf))

/e/p(<*)





PV(d).

equality follows quite easily from the definition of binary join, together with the observation that fefp < fefp V gegp in the Scott domain D => D implies This

/?/p(d)

Z is



existence

(that



fefp{fefp(d))



fefp(fefp(d)Vgegp{d))



fefp{fefp(d)

finite poset and is therefore

of the functions i and is it has non-empty

non-empty subset Z' of Z. for which e-p



{fefp, gegp}

Finally,

that





an

gegp{fefp{d)





gegp{d)).

algebraic dcpo. Further,

it is easy to

see

that Z is bounded

cocomplete

meets) by defining f\zZ' h(l\Di(Z')) for each Thus (f, /i): Z D is indeed an e-p pair in SDomep =

—?



to

see

that lple

fp(fefp)fe

(i, h) o I

and g







id

we

fp(ih)fe d^

(j,/i)om

is

m are

have

lple < id.

just simple calculation from the □

definitions. Theorem 5.6.6 domains whose

from the

<ih. It is routine calculation to show that I and

pairs. For example, id

h,

gegp(d))

Let D be

underlying



Scott domain and write S for the set of Scott

sets have finite

cardinality

and

natural numbers N. The set

{fefp\Se§,f eSDomep{S,D)}

are

subsets of the

A Domain Model

5.6.

is



247

directed subset of compact elements of the Scott domain D

idD



\_\{fefp |

S G

§, /

D.

Further,

SDomep{S, D)}.



Hence it follows that any Scott domain D is

=¥>

directed colimit of finite domains



inS.

Proof

Appealing

to Lemma 5.6.5

that

we see

{fefp\Se§,feSDomep(S,D)} is directed. Recall from page 68 the characterisation of compact elements in

exponential domain D

[—,+]. Considering

Scott domains and the notation

=¥>

D and the

simple fact that embeddings

it is clear that F



element of D

D whenever S is

function F:D

=> —>



V{[fe{x),fe(x)] \ To



equals fefp.

see





5}

preserve

compactness,

is well defined and

finite Scott domain.

the Scott



compact

This continuous

this, let d G D and set xo



fp{d)

G S.

Then

F(d)









and

so

fefp

y{{fe(x),r(x)](d)\xeS}

\f{fe(x)\xes,nx)<d} V{/e(*) \xes,x<x0} fe(x0)



fefp(d)

is compact in D => D.

Finally, we wish to see that idD U{fefp I S G S, / G SDomep(S, £>)}. As embeddings and projections are strict functions (why?), it is enough to prove =

that for any non-bottom d G D

d <

we

have

\_\{fefP(d) \SeS,fe SDomep(S, £>)}.

Consider the function

e:



—■*



(where

_l_







point lattice in N) defined by -/



e(x) and also the function p: D

—*

def =













_L otherwise

Q defined /

p(l) *!

if

by

1 if



< /

0 otherwise.

d,





D°, and Q is



two

248

Chapter

Note of course that p depends is

an

e-p

pair. We

\_\{fefP(d) |



now

S,/

on

Polymorphic Functional Type Theory

5.

e, and for any

given

e, the

pair (e,p): Q,

—>



have

SDomep(S,D)}

> =



|J{ep(<0 \



D°,± ^



e <

d}

\_\{e \eeD°,±^e<d} d.

=f {fefp \ S G §,/ G SDomep(S,D)}, and define a (directed) diagram F:I —? SDomep by sending fefp < gegp to (9pfe,fp9e)'X -?- y (where /:X -? £> and ^y -+ £>). Then we have a directed cone (/: X —*■ .D | /e/p G /) and £) Zira F follows from appeal to To

the

complete

theorem,

set I



Theorem 5.6.3.



With reference to the

Exercise 5.6.7

each

(e, p)

is

an

e-p

pair. Make

sure

proof

of Theorem 5.6.6. Show that

you understand the final

paragraph

of the

proof. Lemma 5.6.8

Let £>:/—> SDomep be

{r)i\D{i) be the

colimiting

then there is

Proof we see

cone

some

under D. If

i G I and e-p

Appealing

-?



directed

diagram

and let

UmD\ie I)

/: X pair h: X

—?

to Theorem 5.6.3 and

pair with X finite, D(i) such that f rjiO h.

Urn D is —?

an

e-p



carefully rearranging indexing sets,

that

fefP



UivMFFvtrJ! \ieI}:UmD^lzmD

fefp < fifr/? p Prjfr/i (call this inequality (*)) because Theorem 5.6.6 shows that fefp is a compact element. Let us put he rfiP ^d hp prjf. We have to check that (he,hp) is an e-p pair and that / rji o h; we just do the latter: and hence there is i G / for which









hpr¥





priirIZ P

(*)



fPofefp



Prfirg P P^rg



PvM



h'rg

A Domain Model

5.6.

249

fe Vfhe

rgrgF



(*)

fe



fefp°fe





Vfriffefpvfriffe



Vfvffe Vfhe



D Lemma 5.6.9

Let D:I

in

just

—■*



UmD

C be

directed



colimits, and F:C

category with directed

(fa D(i)

—?

/)

i G

is



where C is any

diagram

SDomep any functor.

—*■

Suppose

colimit in C. Then F preserves such



that

colimit

case



Proof

(=*>)

Let £>:/—> SDomep be



diagram

(fiiD(i) Then

by hypothesis (F(fi):FD(i)

-*

on

/ with colimit

UmD\ieI). F(limD) \

—*■

/)

i G

is



colimit and the

result follows from Theorem 5.6.3.

(<=)



Clear from Theorem 5.6.3. Let F: SDomep

Discussion 5.6.10

—?

directed colimits. Recall that § is the whose

underlying

sets

S-section of F to be ?

each ts is



if

/: S

The

an



are

SDomep be

(countable)

set of finite Scott domains

indexed

by

set of §-sections of F will be denoted

Lemma 5.6.11

The set

the set

S,

an

where

F5, and

S' is any e-p pair where 5, S' G S, then

-*

functor which preserves

subsets of the natural numbers. We shall define

family (ts \ S G §)

element of



V§(F)

preserving functor F:SDomep

—>

F(f)e(ts)



ts*.

V§(F).

of such §-sections for

SDomep is



directed colimit

Scott domain for the



pointwise

order. Proof

It is easy to check that

V§(F)

is



constructions

bounded

cocomplete dcpo: all algebraicity. Suppose that t

is any

happen pointwise. We just check element of V§F, that I6S. and x G (FX)°

define

an

S-section

is such that

[X, x] by setting

[X,x]s ^ y{(FfY(x) | /



SDomep(X,S)}

x <

tx- We

250

Chapter

Functional

Polymorphic

5.

Type Theory

where the join exists for each (F/)e(x) is bounded by tg. This definition is

good

Let

one.

g:S

—>

S' and

(F9y([X,x}s) for ((FgY



(Fgf)

(FgY(y{(FfY(x) I / \J{(Fgy(FfY(x) | /



\/{(FfY{x) | /



such, given that



is



finite,

are

so



SDom'p(X,S)})

SDom*(X, S)}

SDomep{X, 5')}

too is the set of e-p

compact element of FX,





[^",z]s'-



Note that because X and S

have

we





[X,x]s

is



pairs X

S. As

—*■

compact element

oiFS. The collection of such

[X,x]

forms



basis of compact elements of

V§(F).

[X*, xj, where i 1,..., n, for n elements of V§(F); we shall show that yflXiiXi] is compact. Suppose that {ta \ a G A} is a directed subset of V§(F), and that Vi[X<,*i] < U{*a \ <* e A}. Then Vi[X*,*i]s < U{*s I ? e A} in FS which implies [Xf, xi\s < £5 for each i (as each [Xf, Xi]s is compact as noted above). From directedness it follows that there is some a G A for which [Xi,Xi]s < tg holds for any i; hence V"[Xi,£i] < ta as required. The Let

write

us

proof

is



completed by showing t



\/{[Xi,*i]



...

that any §-section t satisfies

[Xn, x?] I Xi



S,a*





(FIi)°,a*



tXi}. D

Exercise 5.6.12 every

Complete

the

proof of

Lemma 5.6.11; be careful to

verify

step of your calculations.

Lemma 5.6.13

Let

F, G: (SDomep)n

SDomep be directed colimit

->

preserving functors where (SDomep)n is the product category formed from n copies of SDomep. Let ttf: G(F) -* SDomep and ttg: G(G) -* SDomep be the Grothendieck fibrations of F and G.

(Recall

that this

means

G(F)

is the

objects (X, t) where X is an object of (SDomep)n and £ G FX, X' in (<SDomep)n satisfying morphisms /: (X, t) (X', *') are /: X

category with

and

(F/)e(£)

-*



£')?

Then

colimits and makes the



functor

->

ju:G(F)

-+

G(G)

diagram G(F)



(<SDomep)n

G(G)

which preserves directed

A Domain Model

5.6.

Hx- FX

(i)

If

—?

/: X

GX is



Y is



-+

(ii) If fa:X(i) {SDomep)n, then

continuous

morphism

UmX

—>

family (fix \ X G (SDomep)n) where function satisfying the following conditions:

determined

exactly

commute is

251



i G



/^x

by

in



(SDomep)n,

/)

is

(Gf)e(fix)

then

directed colimit for







My(^/)e,

diagram

and

X:/

—?

U{(G/i)V*(i)(*7i)p 1^/}.

Proof

(=¥>): Suppose that we are given a functor )Lt: G(F) directed colimits and for which ncfi

(X,t)J-(X',t')



fix'FX

—>



in



assignment

an



G(G)

These data determine a function

^f-



(*)





G(F) fi(f)

which preserves

(X,Mjt(t))^*(X')Wf.(t))



/ for ncfi GX. Considering that /

course

7i\p. So // defines





in

where of



G(G)

—>

fi(f)

is



morphism

in

G(G),

we see

(*) yields

that

(G/)e(MxW) (i)

which shows that thus t <

(and

t')

holds

by taking t'

iixW) (Ff)e(t),



and

by taking /



idx

fix{t') which is to say that the function fix is monotone. It remains to prove (ii) and that fix is a continuous function for each X. Suppose that P: I G(F) is a diagram where / is a directed poset. Then so too is D 7i> o P: I J, where we have written X for G(F) (SDomep)n. It is an exercise to check that a colimit for the diagram P is given we

have

fix(t)





—>

—?



by

the

—>

cone

fa: (D(i), t(i)) where t =f

(77^: Z)(i) appeal sees

—■*

-*

U{(Fr)i)e(t(i)) \i ^ J}> we have written (D(i),t(i)) for P(i) and lim D I i G /) is a directed colimit in Z" for the diagram D. By

to Lemma 5.6.9 and the fact that F preserves directed

that for any

X: I

diagram

—>

X and t G

fa: (£>(?), (WW) is



(lim D,t)\iel)

colimit for the

G(F)

Now,

fi:

(f)),

and

so

—*

particular diagram

G(G)

is



it follows that

functor



colimits,

FX, that

(!iin D, t)\ie I)

P: I

one

—>

G(F)

(t)

where i < j is sent to

preserving directed colimits (in particular

252

Chapter

Polymorphic Functional Type Theory

5.

which is exactly (ii). We show that [ix is continuous. directed subset t



U{U |





Let X be

{U | i G /} in FX (so here /}. Then there is a colimit

object of 2", take a indexing set), and put

an

/ is any

(idx:(X,U)^(X,t)\ieI) G(F)

particular diagram P:I directed poset by requiring i < j ia. I just in

for the

i < j to zdx-

(X, ^)

—?

(X, tj).

Then

in



was

proved

take

—?

we

family {nx'-FX



(i)

functions for which the conditions

G(F)

FX, and P sends

in

tj



have used

instance of

an

(ii)

above. Hence fix is continuous.

(<=): Conversely fi:





as

UW**) Me/}

because jtz preserves directed colimits and which

case

where / is viewed

deduce that

we can

vxiUfr I* /})

G(F),

—?

G(G) by

the

and

(ii)



GX

—?

hold.

X G Let

us

X)

of continuous

define



functor

assignment

(X,t) -A (X',f)

(X^x(t)) -i. (XW(f))

h^

which is well defined because

{GfY(jix(t)) where to

have used

we

verify

(i)



iiX'((Ff)e(t))

and the fact that fix' is

that \i is indeed





nx>{t') function;

monotone

functor. We have to show that fi:



Suppose

preserves directed colimits.

that P: I

—?

G(F)

is



it is easy

G(F)

—■*

directed

G(G)

diagram

with colimit

(ifc:(X(t),<(t))->(X,t)|i J) where

(X(t),?(i)) =f P(t). MJcW

Thus t =



U{(^)e(*(0) I



/}.

We

are

done if

U{(^)e^(o(*(0))l< /},

that is

toO W(*W) I

* e

/})



U{(G*)'(mx(o(*(0)) Me/}.

We have

?x(\J{(FniHt(i)) |?e/}) (i) U{?x((FmY(t(i)))\i i} =

(2)



(3)



U{U{(G%)%W(^H(^)e(<?)))) I j M{(<**)*0W*(0)) I * e/}



J} |

i e

/}

A Domain Model

5.6.

(1)

where

uses

253

(2)

the continuity of \ix->

is

an

instance of

(ii)

and

(3)

is



rearrangement of directed joins. Verify the characterisation of directed colimits P:I

Exercise 5.6.14

G(F) given

in the

proof of

theoretic

example of

Lemma 5.6.13,

The

object U morphism F:Un



can now

Um is

—?

has

objects the directed G morphism \i\ F —*



-kq

°

by finite powers is U. A product categories which

which generates the base category a

preserves directed colimits.

7i>

page 251.

on

{SDomep)n.

X for



—?

give a rather lengthy definition of a domain- 2Ax-hyperdoctrine. We shall write U for SDomep and

We

Discussion 5.6.15



C(X,U)

We shall write

for the category which

colimit

preserving functors F:X —? U and in which is given by a functor \i: G(F) —> G(G) for which

G(F)

M, where 7i>:

functor between the

X and -kq'-

—?

G(G)

—>



are

the Grothendieck

fibrations of F and G—see Remark 5.6.16. We shall

specified cartesian closed structure for the category C(X,U). C(X,U) has finite products. The terminal object is the functor 1:X U which sends a morphism /: X Y in X to the morphism id{*y. {*} {*} in U. C(X,U) has binary products: if F and G are objects of C(X,U), their X' in X binary product FxGis given pointwise. More explicitly, if /: X postulate



—?

—?

—?

—*■

then

we

define

(F

G){f): (F





G){X)



(F

G)(X')



to be FX x GX

=^

(F/)p The

remaining

C(X,U).

easy details

are



FX'

=*

omitted. It remains to define

Take

H)(X) d=

functions GX

—>

GX

i/X,

(G

=*

=>

GX'.

{GfY

objects G and H, let X be an morphism of X. We define the exponential G

(G



EX where GX

=>

exponentials in object of X and f:X -+ Xf a =>

H:X

-+



=^>

EX)

-*

(GX'

=>

EX')

by setting ((G ((G

follows: set

EX is the set of continuous

and define

if)(/): (GX

as

=?

H)fY(g) ^ {HffgiGSY

=>

H)fr(g') ^ (Hffg'iGfY,

254

for

Chapter

Polymorphic

5.

Functional

Type Theory

g' G GX' => HX'. Recall Lemma 5.6.13. We define the evaluation morphism ev: (G =>? H) x G H by the family any g G GX => HX and

—?

(evx: {GX where if X is

an

=?

HX)



of J, then evx'

object

GX

—?

{GX

=*>

HX

HX)

evaluation in the cartesian closed category SDom. Given



I)

X G

GX



iiTX is

—?

H morphism fi:{FxG) in C{T,U), the morphism X{fi):F {G =¥> H) is also defined pointwise; more precisely A(jLt) is given by the family {\{fj,x) | X G 2") where each component of the family is the exponential mate of the continuous function ifX in SDom. This completes the specification of the fix- FX x GX a

—?

-^

—?

cartesian closed structure of Let COCat

us now

through

define

the

C{T,U).



C-indexed cartesian closed category

\C( ̄'U)

(with appeal

in which if* is defined

Let

us

now

—?

U, and fi:F

write

7Ti:Z





—>

an

?rj : C{T,U)



C{Un,U)

to Lemma

morphism

J and

—>

5.6.13) by

(ijlhy:FHY

G is any

-+

projections. It remains to define

Firstly

H*

M- ̄

{fix:FX^GX\XeUn)

F, G: Wn

—?

assignment

H:Um^Un

where

C(—,W):Cop

tth'.T



->

of



C{Um,U) the

assignment

GHY



Y G

Um)

C{Un,U). W for the obvious

—?

adjunction

z=Z

C{1 xU,U): Vj.

objects. Take F:IxW^Wan object in C{X xU,U). Then we have to define the functor VjF: J W. If /: X X' in 2" we define W and appeal to VjF(X) d= VS(F(X,-)) (here we note that F{X,-):U we

define Vj

on

—?

—?

->

Lemma

5.6.11)

and

ViF(/):ViF(X)->ViF(X') is defined

by setting

MnXt_)} and

fa I 568} *^ ((*(/,?.))■(<.) | 5 6q

Vg(F(x, _)}

A Domain Model

5.6.

where

ts

255

F(X,S)



and

t's

F(X',S).



G morphisms. Suppose that fi:F VjG is given by defining Vj/Lt: VjF

is

—?



Now

we

have to define Vj

morphism of C(J



U,U).

on

Then

—■*

(Vim)a-

V§(F(A, -))



V§(G(A, -))

2", where of course ts G F(A", S) and M(A",s): ■FC-X'j 5) G(A ̄, 5). This completes the definition of our domain-theoretic model of second order polymorphism. for each

X of

object

Remark 5.6.16

Refer to Discussion 5.6.15. This remark may

the definition of

explain



morphism

\i\ F

—?

G in

C(X,U)

FX



as

that

[A]

functor /i:

—*■

| x: ¥ J, F d= [Ah¥]:I-?W

runs over



G{F)

X G

X. Now let A

h M: ^ be and also

to

(directed colimit) definition of G(F) and as a

G{G). First, look at the work out why we can think of G(F) as the "disjoint union" preserving

help

—>

of the Scott domains

proved term. Suppose that G d= [A h *J:X U. a

-+

meaning of A h ¥ when A is interpreted by A", and G{F) is the union of all possible interpretations of A h ¥—similarly for G. Now, the intended interpretation /z [A | x: ¥ h M: ty]:F —> G should be a uniform interpretation of A | x: ¥ h M: \I> over all possible interpretations of the type variables in A. If fj, is given by a family (fix- FX —> GA ̄ | A" G X), we can think of \ix as the meaning of A | x: ¥ h M: ^ when A is interpreted by X Then FX is the



(and

hence Ah¥ and Ahf

Draw

some

are

interpreted by

FX and GX

respectively).

pictures of these ideas. The structure defined in Discussion 5.6.15 is indeed

Theorem 5.6.17



2A x-hyperdoctrine. Proof

We check that the concrete structure described in Discussion 5.6.15

satisfies the criteria

given

and

(iii)

in the definition of 2A x-hyperdoctrine

in Discussion 5.4.1.

(i)

It is very easy to check that the base category C with

powers of U are

(i), (ii)



SDomep satisfies the structure described in

objects

(i)

the finite

and the details

omitted.

(ii)

There

To

begin,

only give a small number of examples of the kind of calculations which have to be performed in order to completely verify (ii), but will point out explicitly which details are missing. are

we

category with finite



lot of details to check here.

We will

leave all technicalities which show that

products

to the

reader;

one

needs to

verify

C(X,U) that

is



given objects

256

Chapter

F,G:I

(such

as

C(X,U), FxG:I->Wis x G F) given by

U of

—?

7rp: F

defined,

well

Let

well

defined,

Type Theory

that the

projections

—?

((*>)*: FX are

Functional

Polymorphic

5.



GX





FX

and that these data do indeed

exponentials

to the

us move on

in

J)

A" G

yield products

C(X,U). Suppose

in

that

C(X,U). G, H: X

—?



U is indeed an object objects of C(X,U). We shall check that G =¥> H: X of C(X,U), that is, it (is a functor and) preserves directed colimits. Let us use Lemma 5.6.9. Suppose that (/,-: X{i) X \ i G I) is a directed colimit for a diagram X: I Z. With appeal to Lemma 5.6.9 and noting the following are

—>

—?

—?

calculation

(in

which g: GX

HX is

—?

(|_|{((G =* H)(fi)n(G =* tf)(/*))" I =



we are

(1)



(2)



done.



function)

continuous

i e

/})(<?)

LJ{((G =*HM)n(G =?ff)(/,))?(s)] Me/} U{W<)eWOMG/iWG/O' lie/} \_\{(HfiY(Hfi)"\i l}ogoH{(GfiY(Gfi)P\ieI} 9

Here, (1)

is

rearrangement of directed joins and



(2)

follows

because G and H preserve directed colimits. We omit the routine calculation

showing show

that the action of G

ev:(G

satisfy

=>

H)





H is

—?

the criterion of Lemma

directed colimit

fa:X(i)

-?

morphisms is well defined. Next we well defined: the family (evx | X G Z) should 5.6.13. We just check that (ii) holds. Take a

=*>











on

I)

in Z and

(p,t)



(GX

=*

ifX)



GX

and calculate:

U{(tf7?i)ee^(i)(((G =? H) =

(1)



(2)



(3)





Here, (1)

and

because g is



(3)



G)fa))"(p,<) |

i G

/}

U{(#^)eeW((G =* #)*)" U^((^)e((^)PW)) I tfOWWW I





(G*)p](<M) I



/}

/}



/})

9(t)

evx(g>t).

follow because H and G preserve directed colimits, and

continuous function. Given

fj,:F





—?

if

we

(2)

just check that

A Domain Model

5.6.

A(jLt): F

(G

—>

=>

H)

257

satisfies criterion

(ii)

of Lemma 5.6.13:

LJ{((G =? H)my\(?Xi)(Fniy(t) lie/} |j{((G =* H)Viy(mi)((Fmy(t), -? | i e /} U{(tf%)e/W(f %)"?> -)(^)p lie/} =



U{[(^)eMx(o((^



(ii) for

usm*/

Y is

some

G)%)"](*. -) I?e /}

fix (t)



(We

where t G FX.

(where

fi



have used the notation

object of X and f



FY")

A(/zy)(f)



in the above

//r(£, —)'? GY calculation).

#Y

—*■

It remains to show that these data

C(X,U)



cartesian closed category;

satisfy the correct properties to make everything follows immediately from the

pointwise definitions and the fact that SDom is cartesian closed. We

require the reindexing functor H* to be a strict morphism of cartesian closed categories for every morphism H:X —? X' in C. This is more or less immediate from the definition; we check preservation of binary products. Take ir:F x G -? F and tt':F x G -* G in J. Then certainly jf*(F x G) =

(H*F)



(H*G)

and if X G X then

(H*7r,H*7r')x



(hi) Suppose that is

((H*7r)x,(H*7r')x) F: X





—?

£/ is

an



{^hx^'hx)



(^//*(FxG))x-

object of C(J x U, U)

and

/: X

—?

X'

morphism of X. We omit the verification that VjF is a directed colimit preserving functor. We know that V§(F(X, —)) is a Scott domain as this was proved separately in Lemma 5.6.11. The following computations show that (VjF(/))e and (VjF(/))p are well defined, that is, they map ^-sections to a

§-sections:

F(id,9y(F(f,idy(ts))





for any e-p pair g:S

->

S' and

(ts \

F(id,9y(F(f,idy(ts))

< =



for any e-p pair g:S

fi:F

—>

G is



verifications that

-+

Vj(/Li)

in

F(f,idY(ts,) S)



Vs(F(X, -)),

and

F(id,9y(F(f,idyF(id,9y(ts,)) F(id,gyF(id,gy(F(f,idy(ts>)) F(f,idy(ts>)

(ts | S G S) G V§(F(X',—)). Suppose C(I x U,U). Again we omit most of the

S' and

morphism

S G

F{f,idy(F{id,gy{ts))

that

is well defined and that it satisfies the conditions of

258

Chapter

Lemma 5.6.13, except for details of criterion

km: X(i)







/)

i G

in J and * G

VjF(X)

(UWMvi))eW?)x(i)(ViF(m))p I =

using (ii) for/i





where

we

note that

S,



(ii). Take a VS(F(X, -)):

Type Theory

directed colimit

i}](t))s

i e

\_\iG(^ id)efi{x(i),s)F(rii, id)p(ts) |

/}



H(x,s)(ts) (Yr(/iMt))s

((77*, ids): (X(i),S)

mX xU for every S G

Functional

Polymorphic

5.

in order to

—?

{X,S) \

apply (ii)

i G

/)

is



directed colimit

of Lemma 5.6.13 to /z.

remaining task consists of showing that we have an adjunction (71-j h Vj) satisfying the Beck-Chevalley condition. Let us use the characterisation of adjunctions given by Proposition 2.10.24. This means we have to define a Our

counit

(natural transformation) e :

ttJVj

such that if \i\

n^F of C{X x U,U)) then which the diagram

commutes,

where

—*■

—?



id

C(I



(where

there is





UM)



U,U)

object of C(X,U) and VjG unique morphism p,:F F is

an

—?



ttj

-?-

G: J



In order to define the natural transformation



family

object

in

an

object

C(X,U),

for

U.

-??

e we

have to

give

C(I x U,U). Each such component category C(X xU,U) and we appeal as ever to Lemma

cg at each

G is

by definition eG: VjG

the

C{I

—?

G of

its components

morphism in 5.6.13 and give a is



of continuous functions

(( G)(XjD):Vs(G(X,-)) ->G(X,D) | (X,D) lxU). Each such continuous function

(ts I S G S)



{ec)(x,D)

is

given by

(*'Di LK*3^ /)6fe) I



S, /

W(5, D)}

5.6.

A Domain Model

wherein

ts

{ec)(x,D)

259

G(X,S)



and

(ts \

is well defined. First

we

S)

S G



V§(G(X,-)).

Let

us

see

that

check that the set

{G(idxjy(ts)\SeS,feu(s,D)} is indeed directed. Consider

there is m:

5'

->



G(id, f)e(ts)

and

finite Scott domain S" and e-p

5" for which /

G(id,f)e{ts)

pairs f":S"



/"J



G{id,f")eG(id,l)e(ts)

and

/'

G(id, f')e{ts')- By

/"m.



—?

Lemma 5.6.5

D, l:S

—>

S" and

Now <

G(id,f")e(ts?)

S-section; a similar argument applies for /', Sf, proving direct- edness. It is simple to verify that {ec)(x,D) is monotone. To see continuity of because t is

(eG)(x,D),

an

take



directed subset

{ta |





A}

VS(G(X, -))



and note that











Next

we

show that

LKGW f)e(U{tas \aeA})\Se§,fe u(S, D)} LKLK^W /)e(*S) I





A} |

5 G

S, /



U(S, D)}

LKLK^W f)e(tas) \SeSJe U(S, D)} I |J{( gW)(*s I LK^W)^) |

{cg)(x,d)

satisfies

5 G

S) I



A}.



(i)









A}

A}

of Lemma 5.6.13. Take



morphism

(7,/):(X,£>)^ (*',£>') inlxW and

an

§-section * G

[G(7, f)eo(eG){x,D)](t)











V§(G(X, -)).

Then

G(7, /)e(U{G(w> Ws) I

|J{G(7, W(*s) |

5 G

S, /i

5 G

S, /i

W(5, £>)})

W(5, £>)}

(cG)(XMy)(Gf(7,W)e(*s)|5' S) [( G)(^^)o(VzG(7))e]W

[(cG^MyjoCCVjGo^Cf,/))?](<)

260

Chapter

which shows that

(i)

holds. To

Polymorphic Functional Type Theory

5.

verify (ii),

let

((Tji,rJi):(X(i),D(i))^(X,D)\ieI) be



directed colimit in J

(*gW) Suppose

that t





(ts \

U. We need to show that



LKGfo^)e(^)(x(i),D(i))(VIG(^))p \iel}. S G

S)



V§(G(X, —))

Note that if /i: 5



i G / for which there is

A moment's

thought

pair h:S

—?

an

e-p

pair 6(h): S

reveals that the

—*

by

it



(U{Gfa>*Yte)M)Mi))<yM*W I

D in W where 5 G § then

—?

(1)

is any S-section. To prove

is sufficient to prove that for any S G S and e-p

G{idXlhy{ts)

(1)

/})(?)?



Lemma 5.6.8 there is

D(i(h)) satisfying





some

?7t(/i)O0(/i).

family

((f)uids):(X(i),S)-+(X,S)\ieI) is



colimit in T



U for each S G

continuity of the functor G

idG(x,s)



we

and hence

S,

by Theorem 5.6.3 and the

have

UiGfc idsYG(f)i, idsf |

(2)

/}.



We have

U{G(nurii)\eG\x^D^xG(f\i)Y I =







/}(*)

LK^fe^i)6^)^),^))^^^))^^) |



|J{Gr(^'^)e[(eG)(X(i))D(i))(G(^, ^S)pfe) |

/} S G

S)] I





/}

LK^fe rkYUiGWxwjyGiiH, idsYfa) I 5





6S^6W(5,D(i))}] |t /}

UiUiGi^niYGiid.eYGifk^idYGifk^Yits) I SG§,0GW(S, £>(*))} |? /}



ty W



> =

\J{{G(id, ViYGiid, 9YUiG(% idYG{% idY(ts) I 3

J}] | SgS,0GW(S,£>(z))} |i 7}

U{{G(M, TkYG(id, 0y{ts) I G(td,ifcW)eG(td^(fc))e(?s) G(id,hY(ts)

S G

S, 0 G W(5, £>(*))} I



/}

and e.

261

A Domain Model

5.6.

so we are

If fi:

7ijF

done. Now

G then

—?

mate P:

7ijF

Px

define

mate



across

VjG is defined from

—?

(m,s)(s) I

x  ̄

5 6

adjunction for the counit the family

the

S)

Vg(G(JC> _)}

functions, where X is an object of X. If G is given by a family of functions

v:



—>

VjG then its

—>

FX



JL:F

px

_x of continuous

we

x ->

where

(X, £>)

things

to do to

U{G(idx, f)'Cx(x))s |

runs over see

5 e

S, /



M(S, £>)}

objects of X. Once again there are a number of everything is well defined. All of the calculations

the

that

quite routine (and certainly should be now after the last few pages of examples!); let us simply verify that /Z satisfies criterion (ii) of Lemma 5.6.13. are

Take



colimit

fa: X{i)



—?



i G

U{(^Gfa)Y GEZ)x(i) (FthY I o





(?,) /or fi





case

V us

/}(*)

yield

an



adjunction (7ij

Vj)

which will

if

eGo7rJ/Z Let

G FX. Then

 ̄Px(x)-

We have to show that the above data be the



(fi(X,s)(x) \S eS)





in X and element

U{(V^(^))e(M(xW)s)(Ffe)p(x)) | S G S) | i G /} (\J{Gfa, idY^x^S)FfaY(x) | i G /} | S G S)



usmp

/)





n qO TTj-V.

just verify the first equation; take fi(x,D): FX

—?

G(Xt D)

and



G FX:

(eG)^x,D)({^xP){x,D){x)) =







{eG)(x,D)0Ix{x))

[}{G{idx, f)e^x,s)(x) |

S G

S, /



U(S, D)}

\JiG(idx, fY^x,s){[{^F){idx, f)]p{x)) |

S, /

5 G

((idx, /): (X, S) a

this

colimit in 2" case

W(5, £>)}

t*{X,D)(x)

where the final step follows from the fact that Theorem 5.6.6

is





->

U, and

(X, D) | /e/p once

again

we

{/7P I have

5 G

S, /

applied (ii)



implies

that

W(5, £>)})

of Lemma 5.6.13, in

to the above colimit. The verification of Beck-Che valley is omitted.



262

Chapter

Polymorphic Functional Type Theory

5.

Prove the Beck-Chevalley condition for the 2Ax-hyper- doctrine of Discussion 5.6.15. Exercise 5.6.18

Classifying Hyperdoctrine of

5.7

We

DISCUSSION 5.7.1 hyperdoctrine of

begin by constructing



2Ax-Theory

the so-called

classifying a correspondence between

2Ax-theory. This will be used to prove 2Ax-theories and 2Ax-hyperdoctrines, along the same lines as those category theory / type theory correspondences of Chapters 3 and 4. We shall use a notion of a "morphism" between 2Ax-hyperdoctrines, which is basically an OOCat and indexed functor which preserves categorical structure. Let C: Cop D D: V OOCat be a pair of 2Ax-hyperdoctrines. A 2Ax -functor (a, F): C is a morphism of indexed (cartesian closed) categories for which a

—>

-??

-+



the functor F:C —*V sends the

and preserves finite ?



DF/ object / of C, ai'.CI objects agrees with F, and

on

for each

—?

object

/ of

Z>,

is



strict cartesian closed functor

C, the diagram

C(/



U)





<*IxU

D(F(J commutes, where

U of C to the V of

products;

for every

which

distinguished object

=:

FI

C(I) <*/





U)) V

=*

B(FI xV)

F(I

—?



U)

—-

vFI

D(FJ)

is the canonical

isomorphism.

classifying category given in Chapters 3 and 4 are very general, involving categories of models. Here we content ourselves with a more restricted notion which is analogous to the universal properties enjoyed by the canonical classifying categories of the last two chapters, but now we work with hyperdoctrines instead of categories. Before defining a classifying 2Ax- OOCat and D: V°p OOCat hyperdoctrine, we need some notation. Let C: 0°^ be 2Ax-hyperdoctrines, and let Th be a 2Ax-theory with model M in C. The definitions of

->

Further,

suppose that

(a, F)*M ?

of Th in D defined

Pl((a,F).M)*

=f ^(PW)

distinguished objects n, and

(a, F): C

—?

by



2Ax-functor. Then there is



model

the clauses

o =:

of C and

D is

-+

Vn

-+

F(Un)

-*

V where U and V

are

the

D, and T is any type symbol of Th with arity

Classifying Hyperdoctrine of

5.7.



[/]((o,F).M)*?

/: A; ¥1}..., ¥a

—*



¥ of

-??



2A x

(<*£/? (I/]m*?))



for any function

77i, where A has length

Prove that the structure

Exercise 5.7.2

Given

Discussion 5.7.3

263

Theory

and Vn

(a, F)*M

2Ax-theory Th,





symbol with sorting =

F{Un)

is indeed



as

above.

model of Th.

Cl(Th) is a Cl(Th) is said to

suppose that

2Ax-

be hyperdoctrine in which there is a model G. Then classifying 2Ax-hyperdoctrine for Th, and the model G generic, if the following universal property holds: given any other 2Ax-hyperdoctrine C:Cop OOCat and model M of TA in C, there is (up to isomorphism in the



—?

C [Cl(Th),C]— see page 109) a unique 2Ax-functor {a,F): Cl{Th) for which (a, F)*G M. Note that this determines Cl(Th) up to equivalence (of indexed categories). Let us now prove that such classifiers exist for all ->

category



2Ax-theories.

given 2Ax-theory Th 2Ax-hyperdoctrine Cl(Th) with a generic model G Theorem 5.7.4

For any

there exists

of Th in



classifying

Cl(Th).

Suppose that Th (Sg, Ax). To keep the notation in this proof as clean as possible, let us write C: C0* OOCat for the classifying hyperdoctrine. We begin by defining the base category 0. The objects of 0 are in bijection In with the natural numbers, and will be written as 1, Type, Type Type order to define the morphisms of C, we will introduce a little more notation. PROOF



—?

,...



given fixed natural number. We shall write (A | ¥) equivalence class of pairs of the form (A, 3>) where Let





A is

be





type

context of

length

n, and ¥ is

a raw

to denote

type for which Sg



an

Ah¥,

and ?

the

equivalence

relation is

derive the theorem Th



given by (A, ¥) Ah¥





(A', ¥') just

^'[A/A'] using

an

in

case we can

obvious notation for

simultaneous substitution.

morphism Type71 —*■ Typem in C is given by a list [(A | 3>i),..., (A | ¥m)] of m such equivalence classes, where the length of A is n. Composition of morphisms in C is given by substitution of types for type variables. More formally, if we are given morphisms A

[(A | ¥0,..., (A | Sm)]: Typen



Typem

and

[(A,|^1),...,(A/|^)]:r^e--,Typei

264

Chapter

5.

Polymorphic

Functional

Type Theory

then the composition is given by

[(A | ¥i[<S/A']),..., (A | ¥;[<S/A'])] We have to define

of the functor C



functor (C:Cop



Typen

CCCat. First

—?



we

Type1.

deal with the action

objects of C. The definition of 2Ax-hyperdoctrine says that at an object Type71 of C, we have to give a cartesian closed category Type in the base category C(Typen) whose objects are morphisms Type71 on

—>

C, and we shall write C(Typen, Type) for this (cartesian closed) category. In order to define the morphisms of C( Type71, Type), we shall once more introduce some

notation. Note that because

(A' | \£)



(A | ^[A/A']),

without loss of

just consider morphisms (A|3>)—?(A|\Ef)in the fibre C(Typen, Type). Consider triples of the from (Ai,a;i:¥i,Mi) where Ax is a type context of length n, Xi is a term variable, ¥1 is a raw type and Mx is a raw term. Then we define an equivalence relation on such triples by setting

generality

we

may

as

well

(Ai, xi: ¥1, Mi)

just

in

case we can

Th where of

Sg

Ai





(A2, x2:3>2, M2)

derive the theorem

Ax



| aii: ¥i

| Xl: ¥i h



Mi



Mi: ^i, and

M2[Ai/A2][xi/x2]: #i

we

shall denote the

equivalence

class

(Ai,Xi:¥i,Mi) by (Ai|xi:<S>i|Mi).

morphism (A | ¥) (A | \£) in C(Typen, Type) is given by an equivalence class (Ai | x\. ¥i | Mi) where (say) Sg > Ai | x\. ¥i h Mi: ^i and also we A

—?

derive Th

can

Composition formally,

if

is

we



Ah¥



¥i[A/Ai]

and 77i

given by the substitution of raw are given morphisms



A h



terms for term



#i[A/Ai].

variables;

more

(A|ar.¥|M):(A |¥)-*(A | tf) and

(A|y:tf | JV):(A|tf)->(A|0) then the

composition

(A Now

we

morphism /

is

given by

| x: ¥ | N[M/y\): (A | ¥)

define the action of the functor C =

[(A | ¥i),..., (A | ¥m)]: Type71

->

on —?

(A | 9). morphisms.

Type771

Let

us

take



in the base category

Classifying Hyperdoctrine of

5.7.

C. Then the functor

the

C/



2A x





265

Theory

f*:C(Typem, Type)

C(Typen, Type)

-?

is denned

by

assignment (A' |

a;:

| M): (A' | ¥)



(A | x: ¥[<£/A'] | where A and A' denotes the

Next

we

Let A be



raw



M[<£/A']): (A | ¥[¥/A'])

contexts of

type

are

(A' | tf)



length

and



—>

(A |

#[<S/A'])

respectively,



and ¥

types ¥i,..., ¥m.

C(Typen, Type)

show that

type

length

context of

is indeed



cartesian closed category.

object is (A | unit). The given by (A | ¥ x #), and the

The terminal

n.

binary product of (A | ¥) and (A | V) is exponential is given by (A | 3> =¥> \£). It will be left to the reader to fill out the details here.

give the adjunction between the fibres which interprets abstraction of type variables. Let 7T7^pen: Typenx Type —> Typen be a projection Our final task is to

in the base

category C.

Formally 7TTypen

where A

[Xi,..., Xn].

It is easy to



"Type* is



C(Typen, Type)

see

—>

[(A,X | Xi),... ,(A,X | Xn)]



that the functor

C{Typen



Type, Type)

given by the assignment (A

| x: <£> | M) : (A | ¥)

—?

(A | tf)

,—.

(A,X|a?:¥ | Af) (A,X | <£>) :

—?

(A,X | *).

It is because of this fact that

often referred to a

as

reindexing functors obtained from projections are weakening functors. For each object Type71 of C we define

functor

VT,pen : C{Typen

by

the



(A | now

each

z:

VX.¥

have to check that

object Type71.

C(Ts/pen, Type)

We have to

give

C(Typen



we

—>

(A,X | tf)

AX.Af [zX/a:]):



have defined

an



(A | VX.¥) adjunction

—?

(A | VX.¥).

(fl^pe"



^Typen)

for

We shall write

0 =f (A, X | ¥): Type71

category

—?

assignment

(A,X|z:¥ | Af):(A,X | ¥) We

Type, Type)



Type

-+

Type

and

^ d= (A | tf): Type"

-+

Type.

bijection between morphisms 7TTyPen WO " ̄* 0 m the Type, Type) and morphisms ip —> ^Typen{4>) m the category a

266

Chapter

C(Typen, Type), rules

which is natural in

Polymorphic

5.

<f) and ip. Let

(A,X\x:V | F) : (A,X | *) (A | *: ¥ | AX.F) : (A | tf)

—+

—?

us

Functional

define the

Type Theory

bijection by the

(A,X | 0)

(A | VX.¥)

and

(A | re: # | M) : (A | ¥)

—?

(A | VX.¥)

-^

(A,X|x:# |MX): (A,X |#)—>(A,X|¥) Polymorphism Equations that these rules to verify that the bijection is natural in <f> and \jj for the case of the mapping (—). Let us write

Now it is immediate from the

define and



we

bijection. It remains shall just give details m

4t n



def

(A,X|x:<l>|M):(A,X|<l>)->(A,X |¥'),



def

(A,X| <*>'),



=f

(A|y:*'| JV): (A | *')-? (A | tf),

=f (A|*'),

/ d^f (A,X|tt:*|F):(A,X|¥)-*(A,X|S). Then

have to

we

picture

that the

verify

naturality equation given

in the

commutes:

-7

/i

mo

fo

7r^pen(n)



mo





Tr*Typen(n)

V7Vpen(m) of on







v ̄





Then

we

have R



(A\y:W\((AX.M[zX/x])[AX.F/z])[N/u\)



(A | y: #' | (AX.M[(AX.F)X/x])[N/u\) (A | y: W | AX.M[F[N/u]/x])



It remains to

we

Let

us

give



arity



following

in



(A, X | y: #' | M[F[JV?/x])



L.

verify

the

Beck-Chevalley conditions, and

we

omit the details.

give the generic model G of Th (Thty, Thtm) structure for G in the 2Ax-hyperdoctrine. If F is =

Sg,

then

we set

[F]Gty ^ (A I F(X))



Typen

—+

Type,

in a

Cl{Th).

First

type symbol of

Classifying Hyperdoctrine of

5.7.

giving

Gty in

structure

type



induction that Gty is in fact ¥ is

function



symbol

in



267

Theory

Cl(Th)—what

model for Thty in



Sg

2A x



then

if n=0?

Cl( Th).

One

If

can

prove

/: A; ¥1?..., ¥m

by —>

put

we

[/la- =' (A | z: nr*j | /(Proj^z),..., Projm(z))) : (A 1ny*f) and if k:

Again,

A; ¥ then [fc]Qtm

it is

an

(A |



exercise to prove

by

x:

unit

\ k) giving





(A | *),

term structure

induction that Gtm is



model of

Gtm.

Thtm

in

Cl(Th). Now let D: V0*

D. We define F: £>

—>

-?-

OOCat be

(a,F):C

—?





as

2Ax-hyperdoctrine and M a model of Th in follows: the finite product preserving functor

by the assignment (where [—] refers to M)

C is defined

[(A | ¥!),..., (A | *m)]



Typen



,m

T^e7

([A h<&J,...,[Ah<&m]>: The component of the D-indexed functor

D is



which is defined

(A



£>(7^en, Type)

—?■

C F07' at

an

object Type" of

C(C/n, C/)

—?

by the assignment

| x: 0 | M) : (A | ¥)

—>

(A | ¥)

[A | x: ¥ a



functor aTj,pen

It is

a:

rm

CP-.CT



h M:

*J : [A



0] —>[Ahfl.

though lengthy exercise to verify that (a, F) up to isomorphism in [C,D], and that (a,F)*G

routine

determined

Refer to the

Exercises 5.7.5

(1) Verify

proof

2Ax-functor

is





M.



of Theorem 5.7.4.

that you understand the definition of

composition

in C and that the

composition is well defined. Show that C has a terminal object and binary products, working out the details of a binary product of two objects in detail.

(2) Complete the

details which

verify

that

C(Typen, Type)

is indeed



cartesian

will, of course, have to define binary product projections and check the universal property of both the terminal object and the binary product, to see that the category has finite products. You will also need to define the evaluation morphisms and exponential mates to check the category closed category. You

is cartesian closed. Finally verify that C^

—?■

OOCat

C(—)



C(—, Type)

by checking that the reindexing functors

cartesian closed categories.

are

is indeed strict



functor

morphisms of

268

(3)

Chapter

Write down the

essence

5.

Polymorphic Functional Type Theory

of the details of the

proof

of Theorem 5.7.4.

Try

involving awkward manipulations of syntax, but that the basic ideas of the proof are quite simple. In particular, do make sure that you understand the definitions in the proof which involve a number of syntactic equivalence classes. Complete a verification of the Beck-Chevalley condition. to

see

(4)

that most of the details

Prove that G is indeed

and that

(a, F)+G



M.



are

routine verifications

Verify that (a, F) is a 2Ax-functor yourself that (a, F) is determined up to

model of Th.

Convince

isomorphism.

Categorical Type Theory Correspondence

5.8

Let

2Ax-theory from any 2Ax-hyper- doctrine, which is Theorem 5.8.2. We then show that any 2Ax-hyperdoctrine arises as the classifying category of such a 2Ax-theory in Theorem 5.8.3. Discussion 5.8.1

Theorem 5.8.2

define

us

For any

first construct



given 2Ax-hyperdoctrine C:C°p

2Ax-theory Th(C) for which there is





—?

COCat,

canonical model M of

we can

Th(C)

inC.

Proof

For each

morphism <j>:Un

type symbol <t> of arity



(possibly

U in the base category

—>





0).

This gives

us

C,

we

data for

take a



2Ax-

signature Sgty, and hence we can we can derive judgements of the form Sgty > Ah¥ using the rules on page 207. We can define a type structure Mty <f>. We can then use the rules on page 226 to define [A h ¥] by setting {</>] type



proved type Sgty > Ah¥. From this we can define a collection axioms Axty by requiring that a type axiom be any type equation-in-

for each of type

context A h ¥

is



¥' for which



[Ah¥]

typing theory Thty

model of the



[Ah ¥']. (Sgty, Axty).



It is immediate that Mty

signature Sgtm. For the typing theory we Thty as described above. For every morphism of the form m: (f>i x x cf>a in the fibre C(Un,U), we take a function symbol m which has sorting Now

we

define



2Ax-term

...

take —*■

<f>

miAj&CX),...,^)—>0(X) where, say, A [X\,..., Xn]. (Recall that for this sorting to be a good definition, each of the raw types appearing in the sorting must be proved types in the context A, that is Sgty > Ah <f>i(X) for each 1 < i < a, and Sgty > A h <f>(X). This is of course immediate because each fc and <f> is a =

269

Categorical Type Theory Correspondence

5.8.

type symbol of arity n). For each morphism

m:



<f>

—*?

in

C(Un,U)

there is



A; <j>{X). In addition to these type and function symbols, for each type context A and raw type ¥ for which Sgty > Ah¥, there are function symbols IA^ and JA'* of arity 1 with sortings

symbol

constant function

m:



JA'*: A;



JA'*:A;¥^ [AhOj(X). Let

us

depends

[A

¥](X)



define

term structure



[A



m:

[JA'¥]



0]

<j>a



^(X)) —*■

for which



i^[Ah?]- Using

for each

proved

[A |

T h M:

¥]

[A



0O(X)]



can

we

—*

set

[A

<f>(X)l



<p(X)] structure Mtm, h

|T

we

have

<f>. We also set



we can

then define

h M:

^>, using the rules on define a term theory Thtm {Sgtm, Axtm) by M'\ ¥ any equation-in-context A | T h M

Sg









[A |



[A

course

the term

term

term axiom to be



...

<j>i for each z, and of =

The term structure Mtm

<f>. This makes sense, because certainly

228, 229 and 230. We

demanding a

...



T h M:

pages



0?(X)J

[jTa'*] [A |

<£i



Sgtm.

Mtm for

Thty given above, and

the model Mty of

on

H d^f m: [A where

¥, and

-?

T h M':

¥],

and it is immediate that Mtm is

model of Thim. We

finally

take

Th(C)



{Thty, Thtm)

for which there is



canonical model

M=(Mty,Mtm). Theorem 5.8.3

□ Let C:C°p

-+

(/?, G): Cl(Th(C))

2Ax-functor

—?■

COCat be



2Ax-hyperdoctrine.

Then the

C which arises from the universal property

of the

classifying 2Ax-hyperdoctrine applied to the canonical model M of 77i(C) in C is one half of an equivalence Cl(Th(C)) C of indexed categories.  ̄

To

Proof

and B):T>op

save on —?

notation,

we

category of

write V for the base

COCat for the functor

giving

rise to the

Cl( Th(C)) 2Ax-hyperdoctrine

C. Cl(Th(C)). We have to show that there is a choice of equivalence, D First, we define a 2Ax-hyperdoctrine morphism (a, F):C D; recall that (/?, G) is defined in the proof of Theorem 5.7.4. Let us write U for the V is given distinguished object of C. The finite product preserving functor F: C by the assignment  ̄

—?■

—*■

(f)



Tjn

_,

Tjm



[(A | 7rl(f>(X)),..., (A | nm4>(X))] where A is



type

context of

ith component for 1 < i <

m.

length



and 7r?: Um

—??



Typen



Type?

U is projection

The C-indexed functor a:C

—?■

on

B)Fop is

the

given

270

Chapter 5.

by defining its components at a

functor otu-a

C{Un,U)



object Un of C. Such

an

V(Typen, Type)

—?

Functional

Polymorphic

which

component

a^n is

shall define

by the



we

Type Theory

assignment m:<f>

<p'

-+

i—?

(A | x: 4>{X) | m(x)) In order to show that C

First

D,



we

(A | <f>(X))



shall define

(A | <f/(X)).

—?

isomorphisms

O0,G)(a,F)<*idc

in

[C,C]

(1)

(a,F)((3,G)^idD

in

[D,D].

(2)

we

define the

isomorphism (1) (p, 77)

(idc, %dc)



[C,C], by giving morphisms

in

{Pf

—?

°

a,

GF)

and

(<5,77-1) (ft.





Let

us

define

(p, 77).



idc

—>

specified by giving Pun

for each

(tdc, idc).



rjun

id(jn: Un



C/n. The modification p is

—*

by

C-indexed natural transformation of the form



p and

GF)

The component of the natural transformation 77 at the

object Un of C is given by definition

a,

idc{u?,u)

'?

(*?(-))* ft o





o a :

—>

C iC^

—?

OCa*

natural transformation

(^t/n

—?



PTypen



aun) :C{Un,U)

—?

C{Un,U)

object Un of C, whose component at the object 0 of C(C/n, C7")

is

given

by

{pun)<t> It is trivial to



see

?<^



idc{yn,U){4>)

that pt/n is





4>

—?



we

components at Un of C

given by %n

defined

natural transformation

Sun





Pvype*



define

a^

Vfu^Typen{ocun{.4>)))'

natural transformation and that p satisfies the

intreid condition. Next

by specifying



—?

(6, r/-1). =

The natural transformation

idt/n.- ?7n

—>

has

Un. The modification 6 is

(%i)* C(C/n, 17) :

—?

C(C/n, 17)

for each is

77-1

object £/n of C, whose component at an object <p: Un —? U olC(Un,U) given by {6un)<t> id¥: <f> —? 0 where in order to see that this makes sense

we note



that

Pvype^un^))



(3Typen((A I <f>(X)))



[A



0(X)Jm



<£

271

Categorical Type Theory Correspondence

5.8.

(%i)*(0)

and

Now inverse



id*un{(f))

isomorphism (2)

turn to the

we

<f>.



in

[D, D ].

So let

us

define two

mutually

morphisms

(//, e)

(aG





/?, FG)

—?

(tdD, zrfp)

and

(i/, e"1) in the category



(idD, t'dp)



D ]. The component of =

7Vpew

The modification // is

(aG

—?

e at

idrypen'- Type71

by definition





/?, FG)

7fypen

—>

is

Type71.

XMndexed natural transformation of the

form

H'.aGo(3 and is

( (_))*

—?

specified by giving

fl>Typen

'?

for which if

aUn





°



2'dD

for each

0Typen







DFG

—?

object Type71 of V

e7typen



V[Typen, Type)

[(A | ¥i),..., (A | ¥m)]: Type"

X>, then the intreid condition holds, that is the OLum

V(Typem, Type)

V{Typen, Type)

at

an

some

we

shall set

GCCat,

natural transformation

—?

V(Typen, Type)

Type171 is any morphism in following diagram commutes:

(5Type?

(FGfY



Prypen

V{Typen, Type) j Mrypen idz>(Typen ,Type)

object (A | 3>) of V(Typen, Type)

morphism (/zTypen)(a|¥)

by



—?

—?

? CKc/n

component of HTypen



V09

V{Typem, Type) j ^^ idj)(Typem,Type)









(A | [A

(MJ*.-W) =' (A I x: [A





¥](X))

*J(X) |

—?

will be

(A | ¥)

given

and indeed

#?(x))-

completes the definition of the modification //; let us check that the diagram (*) commutes. Let (A' | ¥) be any object of V(Typem', Type), let /

This

272

be

Chapter

as

above, and define [A'



0]



5.

0 and

Polymorphic

Functional

[A

fc. Then



¥j]



Type Theory

we

have

(VTypen)f*(A'\e)

(MTypen)(A|0[f/A'])



(A\x:eo(¥)(X)\If(x))



(A\z:0(MXl...^m(X)) | IMx),...,Mx)(z)) [(A | fc(X)),..., (A | <f>m(X))}*(A' | z: O(X') \ I#(z))





C^Wl.



Type71



0m)))*((M7Vpem)(A'|e))



superscripts have been dropped from the /'s.

the definition of

at



{FGf)*((HTypem)(A>\e)),



where the



(i/, e"1).

is defined to be

Now

we

turn to

The component of the natural transformation e_1

e^n

d= idTypen: Typen

The component of the modification

at



an

FG(Typen)

-?

object Type71 of V is





Type71. natural

transformation ^7Vpen



idx>(<Typen,Type)



( 2Vpen)*

°

aTJn

°

&Typen

'?

V(Typen, Type)

—?

V(Typen, Type)

simple to check that the component of this natural transformation object (A | ¥) oiV(Typen, Type) is precisely a morphism

and it is an

(^Pe*)(A|*): (A | *) and

we



(A | [A

at

*](X)),



shall set

(^3Vpew)(A|*) =f (A | re: ¥ |

j£'*(a;)).

complete the proof of Theorem 5.8.3, we shall verify that the isomorphisms (1) and (2) on page 270 are witnessed by the morphisms (6, rj-1), (p, 77), and (n, e-1), (1/, e) respectively. In fact we shall just give two calculations which show how the verification goes. For the isomorphism (1) we shall show that

To

(M At

an

^(P,*?)^ ((f7(-))*<¥(-)°P(-),f7 l,n)

verify

by taking



that

we

component

^((tfc/n)^)

{ididc

,ididc).

rj^lrjun (idi(ic)un idu*, as required. We also rftjnb ̄un Pun ididc{un v), and we can see that this holds

object U71 of C

have to





have

at

°



an

object 0:

(pc/n)^







U71

iduniidj,)

—?





id^

as



follows:





(ididc{un>U))<i>'

273

Categorical Type Theory Correspondence

5.8.

For the

isomorphism (2)

we

shall

verify

that

(M,e)(i/,e-1) =f ((e^JV)0^-),""1) It is easy to

verify

that if

see

that

(A | ¥)

an





(eTypen)*((M7Vpen)(A|*)) {^Typen)(A\^) °

verifying {nrypen)(a|¥)

which amounts to

calculation is easy and is left

as an

We

Discussion 5.8.4

(t^^^.i^J.

{ididx>)Typen idrype"-- We also need to object of the fibre V(Typen, Type), then we have

^Typen^ypen is



can



°

{ididv(Typen>Type))(A|*)

(vTypen)(a|<i>)



^(a|¥)-



^(A|*) This □

exercise.

summarise the thrust of Theorem 5.8.3 in the

following slogan: I—

Categorical Type Theory Correspondence



2Ax-hyperdoctrine is is syntax independent.





representation of the notion of a 2Ax-theory which

2Ax-theory Th(C) derived from a 2Ax-hyperdoctrine C is known as the internal language of the 2Ax-hyperdoctrine. We can use it to reason about the categorical structure in much the same way as illustrated for the internal language of cartesian closed categories. The

Discussion 5.8.5

We

can

show that the

categorical

semantics which

we

have

presented for 2Ax-theories is complete. Such a semantics is complete for a 2Ax-theory Th if an equation-in-context of the theory is a theorem just in case it is satisfied by all models of Th. This follows more or less immediately from the existence of generic models in classifying categories. Theorem 5.8.6

2Ax-hyperdoctrines yield



complete

semantics for 2Ax-

theories. PROOF

Let Th be



2Ax-theory.

A theorem is satisfied in all models because

Conversely, if an equation-in-context is satisfied by all models then it is satisfied by the generic model in Cl(Th). It is a simple exercise to show that this implies the a

2Ax-hyperdoctrine

semantics is sound—see Theorem 5.4.15.

equation-in-context is in fact Discussion 5.8.7

Let

us



theorem of Th.

end this

chapter by remarking

definition of translation of 2Ax-theories Th

Cl(Th'). an

We leave it

"equivalence"

Th

as an  ̄



—>

Th'

as a

one can

2Ax-functor

exercise to formulate this idea

Th{Cl{Th)).

that

formally,

give

Cl(Th)



—>

and to prove

274

Chapter

5.9

5.

Polymorphic Functional Type Theory

Pointers to the Literature

The book

[AL91] by Asperti

Longo provides a detailed account of second order polymorphism. However, the syntax of polymorphic theories is not presented quite as formally as in our Chapter 5 and the Scott domain model is not discussed. Asperti and Longo do present categorical models which make use of internal category theory, an important topic not covered in "Categories for Types." For a discussion of polymorphism in real programming languages see

[Car86]

order

and

[Car89].

polymorphism

material of

our

can

and

A full account of the Scott domain model of second be found in

[CGW89].

This contains much of the

Section 5.6, except that the domain model is not

presented very general

2Ax-hyperdoctrine. See also [CGW87]. A account of polymorphism appears in [Gir86] which includes a discussion of domain-theoretic semantics. This paper provides references to Girard's original work on this topic. A description of categorical semantics of second order polymorphism appears in [Pit87], along with a full account of topos theoretic as an

instance of

models.



Higher Order Polymorphism



Introduction

6.1

Let

Discussion 6.1.1 in

take stock of the type theories

so

far introduced

began with algebraic type theory, which gave us a basic framework in which to write down syntactical theories involving equational reasoning. This was extended to functional type theory in which there is a formal syntax for the representation of functions. We then noted

"Categories

for

us

Types."

We

that it would be desirable to work with



syntax in which certain programs

(terms) yielded instances of a uniform procedure at differing types, known

being one

as

well

into

as

levels, let

two

terms, and one

us

say level 1 and level 2.

thinks of the types

one

thinks of

These two levels which is

extend this latter kind of type

theory



Analogously

property. and

now

syntax for describing functions "at the level of types" functions at the level of terms. In this new system, the syntax splits

in which there is

to

We

polymorphism.

as

this feature



are

of

thought

be referred to

as a

types and

are

"collections" of terms with

at level 2 there are

kind

(so-called)



similar

kinds and operators,

"collection" of operators with similar properties.

connected as

as

At level 1 there

by



distinguished kind,

often denoted

the collection of all types. This

new

by Type,

formal system will

polymorphic functional type theory. In the second order system we could quantify over type variables, for example VX.^, which would be written here as WX: Type.¥. In the higher order system, Type is a ground kind from which we generate higher order function and product kinds (see page 276), and we may quantify over all kinds: VX: K.¥. as

higher

order

example, let us think about the datatype of lists. The operator list has kind Type =>? Type. When applied to a type X (so the kind of X is Type), it yields the operator list X which has kind Type, that is list X is the As

an

informal

type of "lists of type X." The term so rev a

X is



term which may be

applied

reversed list. All of these ideas

6.2

The

Syntax

and

rev

are

has type VX



Type.(\\stX

to a list of terms of

illustrated in

Figure

type X

=>?

to

listX), produce

6.1.

Equations of ouXx-Theories

Bearing in mind the informal description of a higher order polymorphic functional type theory, we now give a formal definition of such a Discussion 6.2.1

system which has "products" and "functions"

at both level 1 and level 2.

276

Chapter

Order

Illustrating Higher

I—

Higher Order Polymorphism

6.

Polymorphism

X: K h 6: K'

Level 2 X: Kx h ¥:

Level 1

X:

| x: ¥ h



Type

X:

M: *

Figure 6.1: In this figure, 6, kinds; and M is a term.



¥ and \£

are

X:

Type

Type

h list X:

\ x: listX

Type

h revXrr: listX

operators; K, K', K\ and Type

are

wAx-signature is a pair S# (Sgop,Sgtm) where 5^op is an u;Ax- operator signature and Sgtm is an u;Ax-term signature. The specification of Sgtm depends on the data which specify Sgop. An uXx-operator signature Sgop is specified by the following data: An





A collection of

ground

kinds.



G\

The collection of kinds is then

given by the

BNF grammar

where G is any ?

::=

ground

Unit

\ Type \KxK\K^K

kind.

A collection of operator

symbols each having

an

arity which is



natural

number. ?



sorting for each operator symbol which is

operator of arity



list of



+ 1 kinds for each

If the operator

symbol F has non-zero arity F:Ki1...1Ka —?■ K for this. An operator symbol C of arity 0 constant operator symbol and we write C: K for its sorting. We

can now

signature and

::=

give the

we assume

variables. The ¥

a.

raw

raw

that

operators generated from

an a;

a we

write

is called

Ax-operator

given a countably infinite stock of operator specified by the (informal) BNF grammar:

we are

operators

are

X\C\F(¥,...,¥)\()\(¥,¥)\Fst(¥)\Sn4(¥)\\X:K.¥\¥¥\ length

unit I ¥



¥ I ¥



=>



¥ I \fX: K.¥

6.2.

Syntax

The

where X is any

of

symbol

and

Equations of uXx-Theories

277

operator variable, C any constant kind and F any operator

non-zero

arity

a.

We shall need the notion of substitution of

a raw

variable. The concept of substitution should by details

sketched. There is

are

an

operator for

now

obvious notion of

operator

an

be very familiar

a raw

suboperator

so

the

^ of



operator ¥. If the operator variable X occurs in the raw operator ¥ then X is bound in any raw suboperator of ¥ of the form XX: K.W and \fX: K.ty.

raw

For each

raw

known

the

as

operator ¥ there is

free operator

in ¥ which

appearing



fopv(¥)

finite set of operator variables

variables. This set consists of all operator variables not bound variables of ¥—do not

are

forget

that

an

operator variable may be both free and bound. Then the substitution of the raw operator \£ for occurrences of the operator variable X in ¥, ¥[\P/X], is the raw

given by replacing each appearance of X in ¥ with # and changing

term

bound variables

so

that

no

free variable of ^ becomes bound when substituted

into ¥. In order that substitution is well defined up to

a-equivalence,

An operator context is written

as

distinct.

A is

an



that is, up

finite list of

[X\: Ki,..., Xn: Kn],

defined, we regard each raw term to a change of bound variables.

as

(operator variable, kind) pairs, usually

where the operator variables

are

required

to be

operator-in-context is a judgement of the form A h ¥: K where operator context, ¥ is a raw operator and K is a kind. A proved An

Sgop > A h ¥: K, and one thinks of the raw operator ¥ in such a proved operator as being "well formed." The rules for generating proved operators from an a; Ax-operator signature are given in Figures 6.2 and 6.3. An operator equation-in-context is a judgement of the form Ah¥ ¥':A: where Sgop > A h ¥: K and Sgop > Ah¥': K. An wAx-operator theory Thop is a pair (Sgop, Axop) where Sgop is an ^Ax-

operator

is



judgement

of the form



operator signature and Axop is



each equation-in-context known

as an

judgements of the form the rules in Figure 6.4. are

Discussion 6.2.2

collection of operator equations-in-context,

Thop



An u\x -term

operator axiom. The operator theorems A h ¥



¥': K, which

signature Sgtm

is

are

specified by

generated by

the

following

data:

u;Ax-operator theory Thop



An



A collection of



(Sgop, Axop). a

natural

sorting for each function symbol /, which is given by an operator A^ and a list of a + 1 raw operators (where a is the arity of /) usually

context

function symbols

each

having

an

arity which is

number. ?



written

278

1—

Chapter

Operator

Variables

Sgop Unit

A,X:K,A'

D>

\-X:K

Operator Sgop

1—

Higher Order Polymorphism

6.

A h



<):

Unit

Operator Symbols (C- K\

Sgop Sgop

Ah^:^



Sgop ■—

Binary

Sgop

...

AhF(¥!



Product



Figure

^n



—>

^)

Ah



Sgop

Ah¥:I

D>

(¥,*): K

xi

D>

AhO:irxL

Sgop



A\-G:Kx

Sgop

D>

AhFst(0):ir

Sgop



AhSnd(O):



D>





VP

(F' K v--"-

Sgop

Function >

A\-¥n:Kn

¥?):Jf

Ah^X

Sgop

Sgop

D>

Operators

Sgop

1—

A\-C:K



Operators

A,X:in-¥:L

A\-\X:K.¥:K^L

6.2: Proved

Sgop



Ah

¥:#=*£

5^op

Operators Generated from

an

D>

S5op

D>

Ah*: A"

Ah¥#:L

u;Ax-Operator Signature.

6.2.

I—

The

Unit

Syntax

and

Equations of wAx-Theories

Type



Sgop I—

Binary

Product





A\-¥:Type D>

Sgop

A h



Ah¥x¥:

*:

Type

Type

Type Sgop





A I-

<VP I—

Type .

Sgop Function

A h unit:

Type

Sgop

I—

279

¥: >

Type

Sgop

A h



=>

A h



#:



Sgop 5pop

> D>

A,X:A:i-¥:7Vpe A h

VX: K.¥

Figure 6.3: Proved Operators Generated from

Figure

Type

Type

Kind Abstraction

Continued from

*:

6.2.



Type

an

u;Ax-Operator Signature,

280

i—

1—

Chapter

Axioms

Operator

Unit

Axop



Ah ¥



¥':#

Thop





!-¥



¥': AT

Equations



Sgop Thop

I—

A h



Ah¥



¥ [/mi

<):



[/mi

Operator Binary Product Equations Sgop tvp



Sgop



A 1-

Sgop

Function

Sgop







==

¥:#

Ah¥:L



hSnd?¥, #))

A,X:ifl-¥:L A h



t>



#:£







Ah*: A"

¥[V/X]:L

Ah¥:A=^L

Thop >

5^op

(AX: K.Q)

AhAX:ir.(¥X)

T/iop

e:jft:xL

Ah#:Z,



AhFst((¥,#? VP



Equations

77iop

Thop

Vp

Ah¥:ii:





Sgop

AhO^xL

<Fst(0) ,Snd(0)>

D>

7VP

Operator



Ah^A



Thop

1—

Higher Order Polymorphism

6.

D>



A,X:in-¥

A\-\X:K.¥

(X£/opt/(S))

¥:ii:=> L



==

*': L

\X:K.¥ ':A=>L

expected rules for Weakening, Permutation, Substitution and Equational Reasoning.

Together

Figure

with the

6.4:

Operator Theorems Generated from

an

wAx-Operator Theory.

The

6.2.

Syntax

and

Equations of wAx-Theories

/: A^ ;¥!,..., 3>a satisfy Sgop > Af

¥ if

—>

the



where

symbol, The

by

that

case

raw

is



write Ar.

Sgop

demand

terms

Afc; ¥

S#op

and

required ¥: Type.

are

Af h



and say that & is



to

In

constant function

signature Sgtm

u;Ax-term

an

specified

are

BNF grammar:

| **,,...,*? | /^,...,^n/(M,...,M) |() | (M,M) | Fst(M) | Snd(M) | length

Xx.Q.M where



operators

Afc h <1>: Tfype.



from

generated



raw

::=



term

These

non-zero.

¥f: Type for 1 < i <

zero we

we

(informal)

the



is



281







MM

AX.K.M

(we

is any term variable

variables),

explanatory

M¥ that there is

assume

k is any constant function

is any function

the ^i and ¥





symbol of

are

raw

any

notation

arity

non-zero

operators.

and

k¥

symbol a

length(Ak) n' length(A^)

for which

for which



We shall often make

use



n,

and

of the self

f¥(M).

The abstractions Arc: ¥ and AX: K bind

occurrences

The reader is left to define the

within their scopes.

infinite stock of such

an

of x and X

free

respectively

term variables of a

term, ftmv(¥), the bound term variables of a raw term, the free operator variables of a raw term, fopv(¥), and the bound operator variables of a raw raw

We also omit the definition of the substitutions

term.

M[N/x]

and

M[¥/X],

being essentially the same in principle as for second order polymorphic functional type theory—see Discussion 5.2.8. these

Let

us now

give the "well formed"

raw

terms

generated

from

an a; Ax-term

signature Sgtm. We need the following definitions. A term context is list of

(term variable,

raw

where the term variables

judgement term

of the form A

context, M is

judgement

operator) pairs, usually are



required

of the form

Sgtm

to be distinct.



and ¥ is A

\T

a raw

finite

[x\:¥\i...ixm: ^E>m],

A term-in-context is a

operator context, T is operator. A proved term is

T h M: ¥ where A is

a raw term

written



an

h M: ¥. Note that



a a

consequence of the

generating such proved terms is that necessarily Sgop > Ah¥j: Type for each ¥* appearing in T, and Sgop > Ah¥: Type. We shall abbreviate Ah¥: Type to Ah¥ when no ambiguities are likely to arise, with a similar rules for

convention for A h ¥



¥'. If A is

an

operator

context and T



then the judgement A h T will simply be shorthand for Ah¥j the ¥i appear in T. The

Figures

6.5 and 6.6.

proved

terms are

generated

term

context,

(each i)

from the rules

where

given

in

282

1—

Chapter

Term Variables

Sgop



Ahr



Sgtm i—

Sgop

AH¥

D>



A h T

Unit Term

Sgtm Symbols

Function

Sgop

Ahr

D>

f Sgop

5pop



S</tm

[>



D>



AhT

A\T\-():unit

Ah*!

S¥op

...

Sgop



Sgtm D> A|rhMa :*?[*/A/] A|rhMi: ¥i[*/A'] Sgtm D> A|ri-/tf(M1,...,M0):*[*/A'] ...

Product Terms

Sgtm



->

¥)



A|ThM:¥ 5^tm

Sgtm

D>



A| r h Fst(P):

Sgtm Sgtm







6.5: Proved Terms Generated from

|rhJV:* *



|rh

P: ¥



A|rhSnd(P): an a;



Sgtm





A| rh?:¥x





D>

A|rh (M,N): ¥ *

Sgtm

Figure

(fc:A*;¥)

Ah*n

(/:A';*!, ...,¥o Binary

Ah*n

t>

A|rh% ¥[*/Afc]

Ah*i

D>







Sgtm

■—

Sgop

A|r',x:¥,ri-x:¥



Sgop

1—

Higher Order Polymorphism

6.

Ax-Signature.

6.2.

I—

The

Syntax

and

Equations of loXx-Theories

Function Terms



Sgtm

Sgtm Sgtm

D>

Polymorphism

A|ri-Ax:¥.F:¥=>#



A|ri-M:¥=># Sgtm

Sgtm

Term

A\T\-MN.V







D>



A,X:K\T\-

A\T\-

F:¥

AX:K.F :VX:K.¥

A\T\-M:VX:K.¥ Sgop Sgtm

I—

A\r\-N:¥



Terms

Sgtm

Sgtm

A|r,x:¥hF:#



Sgtm I—

283



D>

A\-*:K

A|ThM*:¥[*/X]

Typing



Sgtm



A|rhM:¥ Sgtm

Figure 6.6: Proved from Figure 6.5.

D>

7VP



Ah¥



#'

A|TI-M:¥'

Terms Generated from

an

u;Ax-Term

Signature,

Continued

284

Chapter

Those rules which

Figures 5.5, 5.6 and Polymorphism Equations replaced by:

rules



Higher Order Polymorphism

6.

5.7 in

appear in

Chapter 5,

with the

Polymorphism Equations Sgtm



A,X:K\T\-F:¥ Sgop

Thtm



A\T\- (AX:K.F)V

Sgtm Thtm





A\T\-

K.(MX)

Thtm Thtm

Figure

F[V/X]:¥[V/X]



A\T\-M:VX:K.¥ AX:

D>



A,X:K\T\-F =



£ fopv(M))

F':¥



AX:K.F' :VX:K.¥

6.7: Term Theorems Generated from

Let

(where

M :VX:K.¥

A\T\- AX:K.F



A\-V:K

D>

an u; Ax-Term

Theory.

begin with some definitions. Suppose that we are given an u;Ax-term signature Sgtm. A term equation-in-context is a judgement Discussion 6.2.3

| T h M A|rhM':¥.

of the form A

Sgtm



Now

us



M'\ ¥ for which

Sgtm







T h M: ¥ and

give the notion of a higher order polymorphic functional type theory. We define an u\x-term theory Thtm to be a pair (Sgtm,Axtm) where Sgtm is an u;Ax-term signature and Axtm is a collection of term equations-in- context, each equation-in-context known as a term axiom. A term theorem is a

we can

judgement

of the form Thtm

The

A|ri-M





M':¥.

generated by the rules in Figure 6.7. An w\x-theory, Th, is then a pair (Thop, Thtm) where the u;Ax-term signature of Thtm depends on the operator theory Thop. A theorem of Th will then be any operator theorem or any term theorem. Sometimes we may refer to an a; Ax-theory Th

term theorems are



(Sg, Ax)

in the obvious way.

working with a given ^Ax- theory Th given by {{Sgop,Axop), (Sgtm, Axim)). We will usually omit superscripts from such expressions, providing the meaning is clear. So, for example, we will just write Sg A h ¥:K to mean Sgop A h ¥:I This > > overloading of notation should in fact aid clarity. Remark 6.2.4

From

now

on,

we

shall

always

be

Categorical Semantics and Soundness Theorems

6.3.

Categorical Semantics and Soundness Theorems

6.3

DISCUSSION 6.3.1

(i)

285

An

uXx-hyperdoctrine

A category

C, called the base, which is distinguished object U.

containing



(ii)

A functor

C(—,U):Cop

—>



is

specified by

the

following

data:

cartesian closed category

COCat where CCCat is the category of cartesian

closed

categories and strict cartesian closed functors. For each object / of C, the objects of C(I, U) are by definition the morphisms / U in C, and C(I, U) is the fibre of the u;Ax-hyperdoctrine at /. Given a morphism /:/'—>/ in C, we shall write /* C(/, U):C(I, U) —*? C(I', U) for the strict cartesian closed functor assigned to / by C(—, U)\ if g: I —*? U is an object of C(7, £/), then by definition f*(g) go f where the composition o is in C —>





objects / and K of C we are given a functor Vf: C(I xK,U) C(I, U) which is right adjoint to the functor (rf)*:C(I, U) C(I x K,U) where IT?: I x K / is projection in C Moreover, given any morphism /: J —?■ / in C, the diagram Vf C(I xK,U)^+ C(/, 17)

(iii)

For

—*■

—?

—?

(/





idKy

C(J xK^U)—* C(J, U) VJ commutes and in fact the canonical natural

a:

is the

for

a;

identity.

/*

We call these



V?



transformation

V? (/ o

requirements

on



idK)*

Vf

the Beck- Chevalley condition

Ax-theories.

We define

wAx-signature in an u;Ax-hyperdoctrine. As usual, the idea is to give an interpretation of the data of an a; Ax-signature in an appropriate categorical world; in this case a certain kind of indexed category with structure. More formally, suppose that we are given an u;Ax- CCCat and an a; Ax -operator signature Sgop. An hyperdoctrine C:Cop operator structure Mop is specified by giving an object [G] of C for each ground kind G of Sgop, a global element [C] of [K\ in C for each constant operator x C: K, and a morphism \F\: [Ki] x lKn] —> [K] for each operator symbol F: jfifi,..., Kn —> K oi non-zero arity n. Here, for each kind K, we define [K] a

structure for

an

—?

...

inductively through ?

{Unit]



1,

the clauses

286

Chapter



[Type]



[K





[K

=?

where

define

a^

17,

K'\ ^ \K\

{K'j

=?

proved operator Sgop

h ¥:

the

following

jfif]: [A]

—?

Sgop

[if] using

Induction

Corollary 6.3.3

7r:

Proof

[A']

given

in

C of the form

6.9.

We have



given an [X^ Ku

one

Ax-operator signature Sgop, Xn: Kn], and that S#op >

a;

...,

may deduce

Sgop



A h

#[¥/A']: L.

lA'h*:L]o{[At-*1:K1l...1[A\-*n:Kn))



show

on

([A

—>



*i:

tfj, ...,[Ah¥n: #?]>'([A'

the derivation of

Sgop

[A]



lA\-¥:K]oir



tt*([A

is defined from the obvious

h ¥:

L]).

A' h #: L.



Suppose that we have Sgop > that Sgop > A' h ¥: K. Further,

[A' \-¥:K] where

we are

From this

n.

d^f

we can

morphism in Figures 6.8 and

deduce that

[Ah*[<S/A']:L]

Then

[Xim. Ki,... ,Xn: Kn] then we shall is the empty list). We now define

A h <£: K a



A' h #: L where A'



we can

Proof



1 if A

the rules

that

Suppose

¥f: J^ for 1 < i <

Further

If A

lemma:

Lemma 6.3.2

A h

and

[G] has been given in Mop. [A] =f U^[Ki] (and [A] d=

[A

that

\K'l



tf'] *f [*]

for each

Higher Order Polymorphism

6.



Ah^Jf and A C we can

h ¥:

A'.

prove that

K\)

product projections. □

Follows from Lemma 6.3.2.

u;Ax-operator signature. Then if A h ¥ ¥': K is any operator equation-in-context we say that Mop satisfies the operator equation-in-context if [A h ¥: K\ and [A h ¥': K\ are equal morphisms in C. If Thop {Sgop, Axop) is an u;Ax-operator theory, then Mop Discussion 6.3.4

Suppose

that

Sgop

is

an





is



model of Thop if it satisfies the operator axioms. As ever,

Theorem 6.3.5

Let Mop be



model of Thop



we

have:

(Sgop,Axop).

Then Mop

satisfies the theorems of Thop. PROOF a;

A routine verification that the rules in

Ax-operator

theorems

are

closed under

Figure 6.4 satisfaction by Mop.

for

generating □

6.3.

I—

Operator

Variables

I I—



[A, X: K, A' \-X:K} Unit



[A



gi: jifj



[A

\K\



[A']





\K\

-?





<>: Unit]

=!:

[AJ



->

h C:



T7 Kj d^f [CIo!: [A]

fr: [AJ

[Kx]

-?

F(¥): iq





[Fl

Binary

Product

[A

I- ¥:

[A



K\





4>: [A]

<*,¥): K



h 0: if

Fst(9): iq

[A [A

(C:K)

[K\

-?

[AH¥B: JTJ

(0l5..., cf>n): [AJ

....

-itn

—^

■**



</>n:

[A]

->

[iTB]

[X]

->



Operators

[A [A





-?

...

(.T; jVi,



[A]

Operator Symbols [A

I—

it:

Operator

[A I—

287

Categorical Semantics and Soundness Theorems

[KJ



LI





L]





h 6: if

Snd(9): LJ

->







0:

7T o

LJ *>

Figure 6.8: Categorical Semantics a; Ax -Operator Signature.





0:

[A

h tf:

(0, V>: [A] fl:

->

[tfJ

-?

([KJ



->

of Proved

{\K\







-?

[L]

\L\

[L]

[L])



[A]-> [KJ

[A]

^: [A]



[A]-> [ifj

[A] 0:

L]

->

[Jfl

-?

[L]

[LJ

[LJ)

Operators Generated from

| an

288

I—

Chapter

Function

Operators



[A, X: K [A [A

[A

I—

Unit

LI

h ¥tt:

<\>: [A]



L]



et; o

->

([XI

Binary

Product

[A

\K\)

\(<f>): [AJ



[LP

=?

(</>, V>): [A]

([ifj

-?

([#J

-?

[A

h tt:

=>?

[L]

-?

=>?

K]

[L])



[L]) ^: [A]

[ifj



-?

-?

jK]

[LJ

h ¥:

Function

[A

Type]

I- unit:

1:



1 is the terminal

[A]

object

->



of

£/

C([AJ, U))

Type

TypeJ [A





<£: [AJ

h ¥



->?

[Ah*: TypeJ



TypeJ

#:





V: [A]

->?

£/

0x^:[A]->U

Type h ¥:



%>e]



(f>: [AJ

->

[Ah*: Type]

£/

[Ah¥=>*: TypeJ ■—





(where

I—

d>: ([A]



Type

[A

I—

L]

h S:

K.¥:K^L\

h XX:

h <£:# =?



Higher Order Polymorphism

6.



<f>

=*

^: [AJ



->?

i/>:[A]->U U

Kind Abstraction

[A, X: K [A



TypeJ

h *:

h VX: #.*





TypeJ

0: [A]





\K\

VJ£J(0): [A]

->

17

->

Figure 6.9: Categorical Semantics of Proved Operators a;Ax-Operator Signature, Continued from Figure 6.8.



Generated from

an

Categorical Semantics and Soundness Theorems

6.3.

appearing in Figures

Instances of the rules

rules for

I—

[A, X: K |

[A | r

h M

¥]

VX:



VX:



*[¥/*]]

I- M*:

K*]

#.¥]





(td|A], [A



(where

K h

/: [A, X:



[A

T]

/: [A



V\

[A



T]

m:

h *: I-

->

->

-?

[A, X: K



¥J

VJf}([A, I:ifh *]) [A

h VX:

AT.SJ

iH>*([Wv(|A,y:JCH*iy/x]i)]A)

TJ

->

[A

I- VX:

#.¥]

[A

-?



o m:

¥[*/X]J

A)

Y does not appear in

Figure 6.10: Categorical Semantics of Proved Terms Generated from Term Signature.

an

ljXx-

Sg tm{ Thop) be an u; Ax-term signature. A term is specified by giving a model Mop for 2VP, a morphism in C([A], U) Let

Discussion 6.3.6 structure Mtm

with the



T h F:

h AX: KF

[A | T

Chapter 5,

Terms

Polymorphism

[A | T

5.9 and 5.10 of

replaced by

Terms

Polymorphism

289

of the form

[/]:[Ah¥1]x...x[Ah¥n]-+[Ah<S>] where



element

Sgop

is

[k]



define



function

of

[A

A h T

[A



T]

for =

¥]



sorting /: A; ¥l5..., ¥n —*■ ¥, constant k: A; ¥. Given an operator

symbol for



with

some term

n^[A

list. Then for every judgement

C([A], Z7) by

Lemma 6.3.7

Sgtm



Sgtm



h M:

the clauses

given

Let

Sgtm





\ T[¥/A']



¥]: [A in





T]

Figure



[A

->



0]

6.10.

A' \ T h N: V be

be proved operators, where A' term

we

|r

[A in

and

global context A, if a

[xim. ¥i,..., xm: ¥m], then we shall define [A h T] d= 1 if T is the empty A | T h M: ¥, we specify a morphism

context r

¥J;



and



proved

\X\. Ki,...,Xn: Kn].

N[¥/A']: #[<£/A']

and

term and let A h

Then

we

moreover

have



¥f: K{

proved

its semantics is

given by

[A | r[<?/A']

([A Proof

Induction

I-



on

JV[<£/A']: #[<?/A']]

*i:



ffj, ...,[Ah¥n: Kn])*(lA' \T

the derivation of

Sgtm



A'

\T

h N:

*]).

h N: V.



290

Chapter

Lemma 6.3.8

Sgtm

Let







Higher Order Polymorphism

6.

V h N: # be

proved



term and let

Sgtm > A | T h Mj-: ¥j be proved terms where the term context T' is [xi: ¥i,..., zm: ¥m]. Then there is a proved term Sptm > A | T h JV[M/r']: # and

moreover

[A|rhiV[M/r]:*l



[A|ThiV:^]o([A|rhM1:^1],...,[A|rhMm:^m]). PROOF

Induction

on

the derivation of

[A7| T' [A']

—?



Sgtm > A | T h M: ¥ be a proved term, certainly S#tm > A' | F h M: ¥, and moreover

and T C V. Then

7r:

A\FhN:V.



Let

Corollary 6.3.9

where

Sgtm

[A]

h M:

and 7r':

¥]

[A

tt*([A | r





T']

[A

—?

h M:

T]



0]



tt') formed from

are

A C A'

product

projections. Proof



Follows from Lemmas 6.3.7 and 6.3.8.

Suppose that Sgtm is an u;Ax-term signature and that OOCat. If structure for Sgtm in an a;Ax-hyperdoctrine CiC^

DISCUSSION 6.3.10

Mtm is







term

T h M

satisfies



M'\ ¥ is any term equation-in-context,

shall say that Mtm

we

the term equation-in-context provided the morphisms

[A | T C([A],*7). and



->

structure



M':¥]

are

equal

A model Mtm of

in the cartesian closed

u;Ax-term

an

Mtm for the signature

Sgtm

in

[A | T h M: ¥] category C([A])

theory Thtm {Sgtm,Axtm) an u;Ax-hyperdoctrine CiC^ =

COCat, which satisfies each of the term axioms of Axtm. We soundness theorem for

Theorem 6.3.11 an

u; Ax-term

Let

u;Ax-hyperdoctrine.

If Mtm is

an a

u;Ax-term

theory

model of Thtm in

A routine verification that the rules in

u; Ax-term

theorems

Exercise 6.3.12 Theorem

6.3.11.

—*■

prove the

and C: C°p

C,

-?-

CCCat be

then Mtm satisfies

Thtm.

Proof

are

can now

is

theories.

Thtm be

all of the term theorems of



closed under satisfaction

Complete

some

Figure 6.7 for generating □ by the structure Mtm.

of the verifications of the

proof of

A PER Model

64-

291

Let

DISCUSSION 6.3.13

definition. A structure M in

signature Sg

us

an

complete this section with the following

of Thop and Mtm is



term

—?

CCCat for

an

a;Ax-

pair (Mop, Mtm) where Mop is a model structure. The specification of Mtm depends on

(Sgop, Sgtm(Thop))



C:Cop

u;Ax-hyperdoctrine is



specification of Mop. A model M of an u;Ax-theory Th (Thop, Thtm) (Sg,Ax) in an u;Ax-hyperdoctrine is specified by a structure (Mop,Mtm) for Sg where Mtm is a model of Thtm (and Mop is a model of Thty). We have

the



The

categorical a;Ax-hyperdoctrine given by a model THEOREM 6.3.14

theorems

semantics of

M is

an a;



Ax-theory

Th in

an

sound, that is, M satisfies all

of Th. This is

Proof

a restatement

of Theorems 6.3.5 and 6.3.11.



A PER Model

6.4

Discussion 6.4.1

Our first

of

example

u;Ax-hyperdoctrine

an

is based

on

PERs.

(i)

The base category is the category Set of sets and functions. The

distinguished object

U is the set of PERs

on

N,

C/d={ACNxN|Aisa PER

on

N}.

(ii) Let us write J for Un. We define the fibre CI C(J, U). C(I,U) are (by definition of u;Ax-hyperdoctrine) set-theoretic

The



U. Let



G / be any element of the set /. If F: I

objects of the fibre over /, then Fx and PER R d= nx i(Fx =^ Gx). We shall define

two

C(/, U)(F, G)



Gx

functions /

U and G:I

—?

are

objects of

—>



are

—>

any

PERs. Hence there is



Dom(R)/R.

Note that this definition is

essentially the same as for the PER example of a 2Ax-hyperdoctrine; identities and composition are given in a similar manner too—see Discussion 5.5.7. We define



functor

C(—, U):Ccp

H:I'-*I where H sends

CCCat

by

the assignment

H*:C(I,U)—* C(I\U)



object F:I of C(I',U), and the morphism <f> [e]:FH-+GH of C(I',U). an

—?

C(J, U) G [e]:F

U of

—>



—?■

to the

of

object

C(7, U)

FH: I'

to the

—>



morphism

292

Chapter 6.

(hi)

We

give



specified right adjoint

to

Higher Order

(-Kf)*:C{I, U)

—?■

Polymorphism

C(I



K,U),

say

V?:C(IxK,U)^>C(I,U). UF:IxK-*Uisim is defined

object of C{I

K,U),



then the function

Vf F: J

->



by keK

for each

G /. If



(f>



[e]: F

—?

G is



morphism of C(J



A', Z7) then

Vf cf>



[e]:VfF-+VfG. Exercise 6.4.2 in Discussion 6.4.1

Verify that the indexed cartesian is an u;Ax-hyperdoctrine.

closed category described

A Domain Model

6.5

DISCUSSION 6.5.1 in order to present

We shall need a

some more

definitions from category

concrete model of the pure

Ax-theory.

locally small category. Then we shall say that an C is finitely presentable if the representable functor HS:C Set preserves filtered colimits. To spell this definition out a little more, if D:I —?■ C is a filtered diagram where I is small, and has filtered colimit

Suppose object S of

that C is

a;

theory

(fcj: DI

-?

lim D

->





I G

I)

in C then

(C(S,k!):C(S,DI) is



filtered colimit in

a:I-+J where

a:



—?■

J is



limC(S,D(-)) \

I G

Set, where the functor C(S,D(—)):I

C(S, DI)



morphism

A category C is called ?

-?

of I and

/: S

f"Daof —?

—*

Set is

given by

C(S, DJ)

DI in C.

locally finitely presentable

C has all limits and all filtered

I)

if

colimits, and

finitely presentable objects of C such that for any object C of C, there is a filtered diagram D: I C and colimit (&j: DI —?■ C | / G I) for which each D/ G S. S is called a set of fp-generators for C. ?

there is



set S of

—?

Informally, we could presentable objects. (C,§).

say that every We shall talk

object of C is a filtered colimit of finitely of a locally finitely presentable category

6.5.

293

A Domain Model

We shall need the

ACCatlr,

and the reader should compare this to the category SDomep of Scott

domains and

Suppose

embedding-projection pairs.

that X and Y

and

r:



also



is continuous

joins)

category of algebraic complete lattices and l-r pairs,



—?

then

we

are

are

monotone functions.

(by

which

shall say that

lattices and that I: X

algebraic complete we

(l,r)

shall is



If

(I

just



r)

is





poset adjunction and

that

mean

—?■



preserves directed

left-right-continuous pair or just an l-r the algebraic complete lattices and the

pair. So the objects of ACCatlr are morphisms are the l-r pairs. If /: X —?■ Y is an l-r pair then we write fl for the left adjoint and fT for the right adjoint. If g: Y —?■ Z is another l-r pair then the frgr- composition gf: X —? Z is defined by setting (gf)1 glfl and (gf)r =



Exercise 6.5.2

Verify

that ACCatlr is



category; what

are

the

identity

morphisms? Discussion 6.5.3

which will play



With these central role in

definitions, our

we can

consider

formulation of



a new

concrete

higher order polymorphic theory. The category CFP has objects finitely presentable categories and morphisms isomorphism classes which preserve filtered colimits. Let

of

an

In fact

u;Ax-hyperdoctrine.

we

us

sketch

shall

see

our

model of the





locally

of functors

domain-theoretic

that CFP is

category

example

cartesian closed

u;Ax-hyperdoctrine. We will show that the category ACCatlr is in fact locally finitely presentable, and we will interpret the kind Type by ACCatlr. If A is a locally finitely presentable category, the fibre of the hyperdoctrine at A will be given by a certain category whose objects are isomorphism classes of filtered colimit preserving functors A AC£atlr; we omit the precise definition of the morphisms at this point. The strategy for presenting this example of an a; Ax-hyperdoctrine is as follows: category and this will form the base category of

an

—?



We state that CFP is We prove that



cartesian closed category; this is Theorem 6.5.4.

ACCatlr is

locally finitely presentable category. First, Lemmas 6.5.5, 6.5.6, 6.5.7, 6.5.8 and 6.5.9 provide some technical machinery, and are used in Theorem 6.5.11 which shows that ACCatlr has filtered colimits, and in Theorem 6.5.13 which shows that ACCatlr has all (small) limits. ?



Propositions 6.5.14 and 6.5.15 show that ACCatlr has Theorem

a set

of

fp-generators.

6.5.16 concludes the result.

give a characterisation of the morphisms in the fibre CFP (A, ACCatlr) for each object A of CFP. This is done in Lemmas 6.5.18, 6.5.19 and 6.5.20. ?

We

294



Finally

Chapter

state

we

of the form



Higher Order Polymorphism

6.

theorem which says that there is

CFP(-,ACCatlr):£FP

-?-

GCCat, and

u;Ax-hyperdoctrine sketch the proof. This is an

Theorem 6.5.21. The category £FP is cartesian closed.

Theorem 6.5.4 Proof

The formal

of this book, relying

proof

that £FP is cartesian closed is

beyond

the scope

machinery known as Gabriel-Ulmer duality. It is clear that the one point category is a terminal object. Given locally finitely presentable categories (A, §.4) and (5, §#), their binary product is given pointwise: a set of fp-generators for A x B is given by the set §.4 x §5. The exponential is given by the functor category [§.4, B], where §,4 is regarded as a full subcategory of A. This functor category has all filtered colimits and all (small) limits because B is locally finitely presentable and such (co)limits are computed pointwise. What is difficult to check is that [§.4,#] has a set of fp-generators and we omit the proof. Provided that [§.4,#] lives in CFP then £FP will be cartesian closed, because it is routine to verify that isomorphism classes of filtered colimit preserving functors A x B C correspond bijectively □ to isomorphism classes of such functors A [Sg,C]. on some

technical

—*■

—>

Lemma 6.5.5

morphisms



Let I be

and

(3

as



filtered category and suppose that

in the

given

we are

diagram: K

y I

K' Then there

PROOF

are

It is

morphisms a

simple

7: K

—*?

K" and

7':

K'

—*?

K" for which 7a

exercise to prove the lemma

using



7'/?.

the definition of □

filtered category. Lemma 6.5.6

join-semilattices whose morphisms are the (monotone) functions which preserve finite joins. This category has all small products and in particular the forgetful functor U: JSCat Set creates them. Recall that X is the set of ideals of a join-semilattice X. If {Xa \ a A} is any set of join-semilattices, and if Ma G Xa is a given ideal Recall the category JSCat of

—?■

295

A Domain Model

6.5.

A, then TlaeAla is an ideal in TlaeAXa, where we are taking the product of the underlying join-semilattices of the ideals IQ in the category for each





JSCat. A routine verification. That the functor U creates products amounts statement that products in JSCat are given by pointwise order of the

PROOF to the

product of the underlying sets of the Xa in Yla A^a is immediate; all the properties are Lemma 6.5.7

/: X

—>

Proof

Y is

an

Let 1-r

Set. That

defined

Y be a morphism /: X pair in ACCatlr

in

—>

Use Lemma 1.5.14,

Proposition

Ila Ala

is

an



pointwise.

JSCat. Then the ideal lifting

Proof



1.5.18 and Theorem 2.10.8.

operation of taking ideal liftings is functorial. precisely, if we have morphisms X —? Y -^ Z in JSCat, then g o / where of course f:X —> y and  ̄g:Y —> Z Lemma 6.5.8

ideal of

More

The

Suppose

that M

e ̄X.

We have to

see

that

 ̄gf(M)





gJ(M),







that

is

[j{gf(x)i \xeM} If



X.



\J{g(y)i \

y G

\J{f{x)l \





M}}.

7jf(M), then z < g(yo) for some yo eY where yo < f(xo) for some xq G So z < gf{x0), implying that z G  ̄gf(M). So we have gJ(M) C  ̄gf(M) G

and the

reverse

Lemma 6.5.9

morphisms (5:1

—?■

Then there

are

inclusion is

equally



easy.

Suppose that I is a filtered category and we are given K'', a': J i^, a and /3' as pictured in the diagram below. 6'(3'. morphisms 6 and 6' for which 9a 0'/? and 6a' —?





296

Chapter We shall give

Proof

Higher Order Polymorphism

6.

informal

description of the proof, which is in principle quite easy, but tedious to describe. Appealing to Lemma 6.5.5, choose morphisms 7, 7' along with 7 and 7' whose composites with a, (3 and a', (3' are equal. By filteredness of I, choose a pair of morphisms, one morphism with source equal to tar{7) tariff') and the other morphism with source equal to tar (7) tar(7'), and both morphisms having a common target. Call these 6 and 6'. Again by filteredness, choose e: tar(8) —?? tar(e) which equalises <¥V and £'7', and e': tar(6) tar(e/) which equalises 67 and 6,7y. Finally, again appealing to Lemma 6.5.5, choose p and p' whose compositions with e and e7 respectively are equal. Then the morphisms pe8j and p'e'S'j' will do for 0 and an





—>



6'.

Exercise 6.5.10

Verify

the details of the

proof

of Lemma 6.5.9—draw



diagram! The category ACCatlr has

Theorem 6.5.11

Proof

Let D: I

We define

a cone

—>

ACCatlr be

(rjr.DI as

follows: Let lim D be the

elements

(si \

I G

I) where sj

(sj I <*



/ G

I)

1—?

G DI and

(U{D(PYD(a)l(d) I

limD is





filtered.

el)



D(o:)7"(5j)

A"

I, a

number of

complete lattice (we



sj holds whenever a: I

the function

by giving

sj, and also the function

where d G Di\ We have

(small and)

object of ACCatlr which consists of families of

J in I. The 1-r pair 77/ is defined which



limD



filtered colimits.

where I is

diagram



(small)

77J: D/

—?

I(/, A"), 0

points

to

77J:

&ra D

—?

D/ for

—>

Zzra D for which

I(J, #)} I

I)



verify.

prove that it is

algebraic

later

on).

Let

{(sj I J G I) I a G A} be any non-empty subset of limD. Setting sj A{sj I a G ^4} (which makes sense for DI is a complete lattice) then provided (sj I / J in I, I) &m .D it must be the required meet. Taking a: I =

—*

we

have

D(aY(Sj) where of

course



D(?)'(AW I

the



A})

right adjoints D(a)r



empty subset,

so

a e

preserve all meets,

element given by the "constantly top" family; T is the meet of the

AW<*)"(*5) \

this is

note that a

A}

s,

lim D has

D(a)r(T)

well defined





family



top

T because

in lim D.

6.5.

A Domain Model

Now

we

verify

297

{rfj.rfj)

that

is well defined. Let d G

Vli(d)j



7)7;

form

an

1-r

the component of

UWP)rD(a)l(d) |

A-

?7j(<i)

this is

see



D(7p)rD(7a)l(d) with

similar



at J G E is

E( J, K)}.

1(7, K),0

I, a

directed]om take D((3)rD(a)\d) Choose 7 and 7' as per Lemma 6.5.9, and note To

r}\

pair. We begin by checking that

and

D((3')rD(a')l(d)

in

r^{d)j.

that

D(PYDWD(7)lD(a)l(d)



D(p)rD[a)l(d)

for a' and

ff, proving directedness. We also need to check that if 6: J J' in I, then D(8)r(r]lI(d)j>) r)lj(d)j. Using the continuity of D(6)r, this amounts to proving a

inequality —*



\J{D(6YD((3YD(a)l(d) \KeI,ae E(7,K),0e E(J',70} L

[J {D(7)rD(a)l(d) I



A-

1(7, A), 7

I, a



I(J, A)}. '





It is immediate that L C element prove

£ \JR

R, that is \JL



U-R- We shall show that for each

G 7? there is an element of L which is <

greater than £, which will

\_\L. Consider the following diagram, where



and 7

are

given

J' and

we

have defined

a', 7'

and K' from filteredness of

E, and

and e'

by appeal

to Lemma 6.5.9. We have

D(8)TD{e'i)TD(ea)\d) where the left hand side is element of 7?.

Now let

us

an see



D(ej)rD(ea)l{d)

element of that

(77J





D{1)rD{a)\d)

L, and the right hand side is an 77J). To show tfrfj > idr>i, take

d G DI and note that

vWi(d)



\jWPYD(a)l(d) I

K G

E, a



E(7, K),0e E(7, A)}.

Chapter 6.

298

Higher Order Polymorphism



R"

R'



Figure To

see

we

have

and

that

?7j(sj)j

(3: J

K,

—?

take

id^mD,



r)Ir)rI

6.11: A Commutative

< sj. It is we

have

lim

s G

D;

clear that this

D((3)rD(a)l(si)

we

Diagram.

need to show that for each J G I K given a: I this latter inequality does

happens just < Sj. But

in

case

—?

indeed hold:

D(PYD(a)l(sj) To



D(PYD(a)lD(a)r(sK)

summarise, it is easy to

see

that

rfj

and the above calculations show that

rfj is continuous,

pointwise,

(US)i



Now

as

is

we

o G

shall

A}.

verify



So

{sa \ we



that the set

—?

\J{D(8YD(7)l(Sl) | <

—>

J?

being given,

and 7

as

So

have

we



R"

diagram

and 7 and p

D(6YD(/y)l(si)

an

^4} an



1-r

{rfjrfj \

sj.

both monotone functions,

are

form



poset adjunction. Finally,

limD and

in lim D

5 is

are

given

directed,

then

pair. I G

1}

is directed.

Given / and

by filteredness of I. We claim that This amounts to proving that for any



I(J, R'),6e l(Rt R')}

1,7

\J{D(6YD(j)l(sK) I

Consider the commutative



do have

K and (3: J I, pick a: I Virf ^ VkVki and similarly for J. object R of I J in

they

rfj

D(p)r(sK)

easily verified because directed joins

that is, if S

U{sj I

and



as



1,7

I(jRT, fl") J



I(jR, i?'7)}.

(*)

Figure 6.11, in which we regard a, 6 being chosen according to Lemma 6.5.5.

of

element of the set

on

the left hand side of the

A Domain Model

6.5.

then

inequality (*);

we

299

may deduce

DiSYDfrYM





D(8YD(pYD^)lD(a)lD(aY(sK)



DtfYDipyDftyDiayM



hand set of the

D(6YD(pYD(p)lD(j)lD(aY(sK)





in which the final element

D(6YD(y)lD(aY(8K)

D(8yD(PyD(j)l(sK)

D(p6yD(j)l(sK) inequality is in the right analogous argument applies to J and this in the above

appearing

inequality (*).

An

proves directedness. Now

we

shall show that

is not clear is

Ui7?/77/ |

/ 6

id^mD 1} > id.



LK7?/7?/ |

But if s

I}.



(si \



The

I G

I)

only thing G lim D

that

we can

calculate si



rjli(si)i



iWrfM



and

(UW*W U

done. To prove that lim D is

so we are

i})/

algebraic,

let

us

take t G lim

D,

and prove that

d=

{r)lj(d) |

{s \



tT}



First note that d is compact, and thus

by

Lemma 1.5.14



has



I,d

DF,d

have



(UmD)°,s



tj, implying that

algebraicity proved by using id





is too, for

rj\

rjlj(d)

< t.

This shows the above

will follow if t is the

\_\{rjlIr}rI \

I E

join of the subset 5,

1}.

verify that the family (t7j: DI —*? lim D \ i G /) is a cone and so now in a position to see that ACCatlr has all (small) filtered colimits. cone (hi: DI —*? E \ I G I) and define a morphism h where

It is easy to we are

t}.

K be morphisms of right adjoint. Let a:I—>K and (3: J that d < U implies that D(a)\d) < D(a)l(tI) < tK and thus

D((3)rD(a)l(d)

which is itself

rf^d)



—?■

subset inclusion. Then

Take



continuous

I. Then note we

I G

DI

300

Chapter

by setting hl d= that /i is



U{hWi I

1}

and hr



pair, that hi





well defined 1-r

the unique 1-r pair for which such

Higher Order Polymorphism

6.

UWih1} \ h



I}.



We have to check

rjj for each J in

I, and that h is

equation holds. We omit all the details.

an

D Exercise 6.5.12

Work the details of the

those concerning algebraicity of

proof of Theorem 6.5.11, especially Urn D, that (77/: DI lim D | i G I) is a cone, —*

verification that ACCatlr has filtered colimits

and the

(direct)

the final

paragraph of the proof).

Theorem 6.5.13

(omitted

from

ACCatlr has all (small) limits.

The category

We shall prove this

Proof

proposition by appealing to Theorem 2.11.8 and thus showing that ACCatlr has equalisers and all small products. The idea of the proof uses the fact that the set of ideals X (see Discussion 1.5.17) of a join- semilattice is itself a complete algebraic lattice, together with Corollary 1.5.19. Thus constructing limits in a category of join-semilattices yields a construction of limits in ACCatlr.

begin by showing that ACCatlr ACCatlr be a diagram, where I is small for D, say We

{'KI:lvrnD as

follows.

We shall set limD

-+

has all small

Let D:I

products.

and discrete. We shall define

DI







-*

limit

el)

def =

Yli i(DI)°. This requires a few words of elements (DI)° of each algebraic complete

explanation. The set of compact lattice DI is easily seen to be a join-semilattice. The category JSCat has all small products, created by the forgetful functor U: JSCat —*? Set; thus Uiei(DI)° is a product in JSCat. We have defined limD to be the set of ideals of this product. Note that Proposition 1.5.18 tells us that limD is an algebraic complete lattice. We shall define  ̄l def

H\ where



pi



ILI&(DI)°

pi:Uiei(DI)°



(DI)°

(Diy





\J{Pi(e)i \





M}

product projection in the category JSCat. Proposition 1.5.18 says that 7Tj preserves all joins (and all joins exist) and thus it has a right adjoint. We wish to see that 7Tj has a continuous right adjoint (say 7fj); using Lemma 1.5.14 we shall verify that 7Tj preserves compactness of elements. This will be the case if given any finite subset F Cj Tii^DI)0, we —?

is

have

i',((V F)l)



(\J p,(F))l

(1)

A Domain Model

6.5.

where

of

we

(DI)°.

underlying

note that

To show

pi(F) C.f (DI)° and (1), we note that for

set of the ideal

set of

301

k\(M)

is

(\/pi(F))l is a compact element ideal M G TiIei(DI)°, the

thus any

given by pi(M) where pi acts

the

on

underlying

M, that is

*l(M) and it is routine to

verify

(j{pi(e)i \eeM}= Pl(M)



this. We check

one

half of

(2)

(1), namely

that

(ypi(F))icPl((\jFn). Certainly pi

preserves finite joins, for

Thus if

(Vp/(F))1,

e G

then





they are calculated pointwise in products.

pi(\/F),

where _L denotes the bottom element of

and

so

(l,e)

Rj<=i,j?:i(DI)0.

Um(DI)° (_L,e) G (V F)i

<\/F

Thus



implying that e G pi((\/ F)i). The reverse subset inclusion which we need for (1) is equally easy to show. This completes the verification that 7Tj (7T/,7rj) is an 1-r pair. We can now define 7r{- 6 o nj1: UmD DI, using {DI)° =

—?



Corollary

1.5.19.

(fi'.E

Now suppose that

f\: E°

—>

we can

(DI)°

tt1j {fi\I





I)

—>

DI



for each / in I. Thus

form the ideal

Tj.



I G

I)

We

can now

define the



the

diagram



We

can see



that



(/] |

/ g

I)



7rJ







f\

Let

us

in

JSCat,

check that

m G

M})

U{/i(?HI? M} 7F(M). —>

lim D for the

product

of

e ̄l:E^E° -+UmD.

adjoint, being the composition of

left

ACCatlr. Then

*li(\J{nwlfli(rn)l] \

mediating morphism /: E by setting the left adjoint to be

/'

D in

—>



is

a cone over

lifting (f\ \ I G I): E° Hi i(DI)°. Taking M G  ̄W, we have



fl

is

using the existence of products

^(UV/I^1)^)!!^^^})

Note that



adjoints. diagram of

two other left

for each / from the commutative

Figure 6.12 where we are appealing to Corollary 1.5.19. It follows that the corresponding diagram of right adjoints commutes, by appealing to Corollary 2.10.22 (in the poset case). Thus 717 o / fj. The uniqueness of / is =

immediate. Now

pair

of

we

show that

morphisms

in

ACCatlr has all equalisers. Let /, /': X ACCatlr. Define a subset

Ed^{eeX0\fl(e)



fn(e)}CX0,

—>

Y be



parallel

302

Chapter



Ec

e -i

6.

Higher Order Polymorphism

UmD

</i|/eI>-

Figure

6.12: A Commutative

Diagram.

Certainly each of fl and fl preserves finite joins, and it follows that E is a sub-join-semilattice of X°. In particular, we can say that the inclusion i:E —> X° preserves finite joins, where we give the subset E the restriction ordering from X°. Hence Lemma 6.5.7 X°. Appealing to Lemma 6.5.8, we have says we have an 1-r pair i: E where

we

note that E is

non-empty for ±x

G E.

—?

floi It follows that the





f'loi

commutes

by using Corollary equaliser diagram.







f f

diagram E

an

floi

ffl

o i.

XY

1.5.19. It is routine to

Any finite algebraic complete object of ACCatlr.

Proof any other that

we

that this is indeed □

Proposition 6.5.14 presentable

verify

lattice is

Suppose that X is a finite algebraic complete lattice algebraic complete lattice. Given an 1-r pair /: X

have

—?



continuous endofunction

flfr:L—>L.



finitely

and that L is L it is clear

Then it is the

case

that

L flfr is a compact element in the poset L =¥> L of continuous functions L (where we take the pointwise order). Note that in fact any algebraic complete —>

A Domain Model

6.5.

lattice L is



Scott domain, and thus in

domain too. We

(see

page

68)

303

particular

the poset L

L is

=>?



Scott

the characterisation of compact elements in L

can use

to show the

flfr.

compactness of

f'f

=>



We claim that

\/{[f'(x),f'(x)}\x X}.









(*) It is easy to x G

(*)

see

that this

X is compact and thus is



exists. Note also that

join

fl(x)

compact element of L

=¥>

is



as

X is

finite,

any element

compact element of L. Hence the join

L. Let

us

prove

our

claim,

thus

showing flfr

is compact. For any d G L

\/{[fl(x)jl(x)}(d)\xeX}

\j{fl(x)\xex,fl(x)<d} \J{fl(x)\xex,x<fr(d)}





flfr(d).



Take



colimit

(??/: DI

lim D

—?



I G

I)

in

ACCatlr. We wish to prove that

ACCatlr(X, UmD)^ lim,AC£atlr(X, £>(-)). Recall

(page 115)

the construction of filtered colimits in the category Set. We

have that

UmACCatlr{X,D{-)) equivalence classes \t){ACCatlr(X, DI) \ I G I}/  ̄, where if /: X —*? DI and g: X —?■ D J, then / g just in case there is some K G I and morphisms a:I^>K and (3:J^K for which Da o / £)/? o #. The proof is completed by using the above characterisation of compactness to induce the □ required bijection. is the set of





Let L be

Proposition 6.5.15



fixed

algebraic complete lattice,

poset of continuous functions L

write L =¥? L for the

—?

L. Write

and let

f:X

?—>

us



idx, that is, / is an e-p pair. pair for which frfl Let S be the set of finite algebraic complete lattices whose underlying sets are

to indicate that



is

an

1-r



subsets of R Then the poset I is directed

trivially





{flfr |

(regarded

as

X G

S, (/: X

having

L)



ACCatlr(X, L)}

the restriction order from L

filtered category. There is

ffr<9l9r



H^



diagram

D: I

—?

=¥-

L)

and hence

ACCatlr given by

(//',/y):X^y,

304

Chapter

where

we

have written X

D(flfr)



and Y

under D. In

particular,

have that L is

PROOF

Let



it is the

case

that

filtered colimit for the

us

write L

D(glgr),



(f:X^L\flf

define the set X" C L

which is finite. In

and

a cone

l)

idi

U{/z/r I flfr



I},

and

L for the set of continuous functions L

=>

so we

D.

diagram

Take

that the poset I is directed.

begin by showing

Higher Order Polymorphism

6.

flfr

—>

L. We

in

I, and

glgr

and

by

fact, X"

complete sublattice of L: as X" is finite it is X", and that if x, 2/ G X" then x\ZLy X". We

is

sufficient to show that _l_£, G



have ii If

we

if

we can

put



d=

///r(d)



/lf(iL)v^(ii)er.

glgr(d)





X" and 2/ d=

flfr(d')



pV (<f)



X\

then

show that

(f'f(d) V ffV(cO) V (/'/-(<*') V sV(<*')) A =

f'fr(f'r(d) v /'/r(d1)) v g'gr(9l9r(d) v s's't/))









X".

definition

have

/z/r

id, implying that flfr(flfr(d)Vflfr(d')) < flfr(d)Vflfr(d'), and with a similar inequality for g it follows that B < A. Further, note that id frfl implying that we

will indeed have xVlV

By

we





fr(d) and hkewise inequalities for g

flfr(d')

we

from L, it is





frfrid)



flnflr(d) v /</rw)

flfr(ffr(d)Vflfr(d')). Together with similar Regarding X" as a poset with the restriction order that X" is an algebraic complete lattice.

have A < B. now

clear

Consider the inclusion function i:X"

defined by which

h(d)

we now



flfr(d)

verify.

glgr(d)



f'fr(f'f(d) V ffV(d))

idx?, V ^



we

L and the function h:L

for d G L.

It is clear that ih <

In order to show that hi





—*

In fact

(i, h)

is

idj, because / and g

shall take d

an are

—>

pair, 1-r pairs. e-p

L and prove that

g'fU'fid) V g'g"(d))





f'f(d) V g'g'(d).







X"



A Domain Model

6.5.

305

It is clear that L < R.

/7-(d) and the

together case

with



that h is

functions.



Conversely, =

firfr(d)

/7r(/'r(d) vflV(d))



inequality for g we continuous function, being similar

(i,h):X"

Thus

note that

L is

—>

an

see

the

that R < L. It is

composition of continuous

pair, and

e-p

certainly

{flfr,glgr}

< ih so I is

directed.

diagram D is well denned, that is (grfl, frg1)- X Y is an embedding-projection pair whenever f\X L and g:Y L are. L \ flfr Moreover, to see that the family (/: X I) is a cone under D, we have to check that the diagram It is easy to see that the

—>

—*

—?

—>

D(<) ^



?Y

L commutes, where

flfr



glgr.

This follows from



simple calculation with the

definitions.

Finally,

we

wish to

prove that for any d

that

see



we

±l ¥"



{0,1}



W'r{d) | /'/r



e\x) and also the function p: L

—>

e-p

depends

pair. We

now

on



,,

def =



eifx

I}-

It is

IV







to

function

e:



lattice with

—>

(where

underlying

set





by

1 if



< I

0 otherwise.

given

e, the

pair (e,p): Q

have

1}



_L otherwise

e, and that for any

LK/'/rM I flfr

enough



ft defined

P(l) Note that p



I}.

we are

-/

an

\J{flfr I flfr

okay. Otherwise, consider the ^ d, e L°, and Q G § is the two point N) defined by

J_£,





have

d <

If d

id^mD

> =



\J{ep(d)\eeL%±L^e<d} \J{e\eeL°,±L^e<d} d.

?—?

L is

306

Chapter

Appeal

to Theorem 6.5.11 to deduce that the

6.

Higher Order Polymorphism

(/: X

cone

—>



\ flfr



I)

is



filtered colimit.

fp-generators given by

set S of

underlying

sets

ACCatlr

The category

Theorem 6.5.16 a

locally finitely presentable, with algebraic complete lattices whose

is

the finite

subsets of N.

are

Follows from Theorems 6.5.11 and

PROOF

6.5.13, and Propositions 6.5.14 □

and 6.5.15. DISCUSSION 6.5.17

F:C an

—>



ACCatlr be

Let



(C, S)

be



locally finitely presentable category

and

functor which preserves filtered colimits. We shall define

S-section of F to be



-S G

family (^s |

S)

indexed

by the set of objects S

where ?

each ts is

an

element of

satisfy the C, where S, S' G S. ?

the ts

We shall write

and

FS,

condition

(Ff)l(ts)

ts' for any morphism /: S



—>

S' of

VgF for the set of S-sections of the functor F.

Lemma 6.5.18

Let

(C, S)

locally finitely presentable category. We can regard the set VgF of S-sections of a filtered colimit preserving functor F: C ACCatlr as a poset via the pointwise ordering, namely that if t and s are S-sections, then t < s just in case ts < ¥s for each 5gS. Moreover, Vs-F is an algebraic complete lattice. be



—>

It is easy to check that

PROOF

VgF is

family (_!_¥ I S G §) of that this family is certainly



complete

lattice. The least element

of VsF is the

least elements of the

FS. Note

an

adjoint

joins. To

preserves all

subset U



{ta |





A},

be





well defined

morphism

of C



an

S-section t



< =

lattices

(posetal)

left

Vs-F, take



by setting

\f{ts \aeA}.

S-section, it is certainly with 5, S' G S and note

(FfY(ts)

because any

that non-empty joins exist in

and define

ts If t is

see

S-section,

complete

the join of U. So let

\J{(Ff)l(ts)\aeA} \J{tas> \aeA} tsi-

/: S

—?

S'

6.5.

A Domain Model

Now

we

307

V§F

prove that

that lG§ and

algebraic. Suppose

is





(FX)°,

and

define

[X>*]s

[X, x]s

It is easy to check that ^-sections forms



\/{(Ff)l(x) | /



is

basis of compact



AC£atlr(X,S)}.

S-section; in elements of V§F. an

fact the set of all such

We shall write



def

V[*?,*?]



[*i,*i]V...V[XB,sn],



[X, x] is that X any Vi[^Q,£i] is a

and will say that part of the force of the notation x



(FX)°.

It is



simple

verify

exercise to

that

G § and

compact

element of V§F. To prove that all compact elements arise in this way, show that for any *

Too

see

that









V§F

it is the

UWP^l I

<u, take 5



*i

case

we

shall

that

S,a*



(FXO0,**



uxj

(*)



G § and note that



which follows because



is

§-section.

an

In order to

verify

that





r, first

note that

V{[X,x] \XeS,xe (FX)°,x



ux}

< r.

U{c G (F5)° | c < tt5}. Thus it is sufficient to prove that for any given c G {FS)°, we have c < us implies c < \J{[X,x]s \X e§,x e {FX)°,x < ux}; but this follows from Also, for



fixed S G





\/{[X,x}s\Xe§,xe{FX)0,x<ux}.

the

compact, it must be

follows

have us

[S,c]s



proved

we

\/{{Ff)l(c)\feAC£atlr{S,S)}





We have

S,

representation (*) for any S-section u, and so if u is of the form Vil^Q^i] as required. Algebraicity of V§F □

immediately.

locally finitely presentable category, and let jP: A —*? ACCatlr a functor; F preserves filtered colimits iff given any filtered colimit (//: DI lim D \ I G I) for a diagram D: I ACCatlr we have Lemma 6.5.19

Let A be



—?■

—?

id

n/H3D)



U{(^)1W/)rK6i}.

308

Chapter

Higher Order Polymorphism

6.

Immediate from Theorem 6.5.11.

Proof

Lemma 6.5.20

Let A be





locally finitely presentable category and let

F,G:A —>-ACCatlr be two functors which preserve filtered colimits. Applying the (covariant) Grothendieck construction to F, we have a functor

ttf:G(F)

->



(and similarly

for

G).

Then

preserves filtered colimits and which makes the



G(F) ""f

fi:G(F)

functor





-+

G(G)

which

diagram

G(G)

/ kg

\ A

commute, is GA is

(i) (ii)

If



continuous function

/: A

—>

family (fiA \ A G A) where each fiA'- FA —*■ between algebraic complete lattices which satisfies

specified by giving B is

morphism





of

A,

then

(Gf)1

given a filtered colimit (t?/: DI D:I-*ACCatlr, then if

we are

MfaD



—>?

Ui(Gr)i)1



Mdj



—?



fj,A < \iB



/ G

/ G

I}.

&ra D

(Fiy/r |



(F/)', I)

for

and a

diagram

Note that any (small) filtered category I may certainly be considered directed set, and thus the result follows from Lemma 5.6.13. □

PROOF as a

Theorem 6.5.21

(i)

The

following

The base category is CFP. The

data define

an

u;Ax-hyperdoctrine: of CFP is the category

distinguished object

ACCatlr. We shall write U for this category.

(ii)

give an /IT^P-indexed category £FP(—,U):£FP —?■ OCCat as follows. The objects of the fibre CFP(A,U)-> where A is an object of £FP> are U. Note that this isomorphism classes of filtered colimit preserving functors A notation does not imply that the collection of such functors forms a set. Suppose that [F], [Gf\:A—*U are two objects in the fibre at A. A compositional U where F,F' G [F] F':A witnessing is a choice of witnesses if,f,:F such that if',f" ° lf,F' ^f- Given such for lf,F", ^f' i>f',f and lf,f [F] and [G], we can define an equivalence relation on filtered colimit preserving functors fi:G(F) —> G(G) (as F and G run over the classes [F] and [G]) by requiring fi // just in case \i and /x' commute with if,F' and tG,G'- A morphism [/*]: [F] —?■ [G] in £FP(A,U) is given by a choice of compositional We

—?









—?



6.5.

309

A Domain Model

witnessing for [F] and [G] together with such clarity we now drop the brackets [—]). Further 7i> and 7r<3

are

the

(projections

and G. Now recall from Lemma

(fiA \

functions

A).

A e

the)

for

we



^g

\i is

specified by



family

°

M? where

of continuous

A in the base CFP then the

—?

\pi\. (For

class

equivalence require irp

covariant Grothendieck fibrations of F

6.5.20,

If H: A'

an

reindexing

functor H* is defined

by

the

—>

CFP(A'M)

assignment

(^|iG .4): F

(iii)

CFP(AM)



Let .4 and /C be

->

hL



(/^ I A'

7r¥: .4

objects of CFP and

V¥ £77>(.A :



KM)

—?



/C



.4): F^ —*

->

GiJ.

A Define



functor

CFP(AM)

object of CFP(A x /C,ZY) then we have to give a functor VJ4F: X —? W in £77*. If /: A —? A is any morphism in .4 we define V5F(A) V§(F(A —)) where S is the set of fp-generators for K, and as

follows. If F: A





—?

W is

an



V¥F(/):V¥F(4)^V¥F(,4') is defined

by setting

fe|5 S)^?-((F(/,^))i(ts)|g6S)

MF(A,-)) and

(V¥F(/))'

^i^s)-^"(W,^)m)|ges)

vwf(a', -)) where £5 £

phisms.

F(A,S)

->

V¥G



F(A', S).



that

Suppose

V¥jz: V¥F

and

is

fi:F given by

—>

the

G is

where of

Proof Theorem

course

The

ts



proof

5.6.17, and of

F(A, 5)



family

I 5 G S)

(*c (V5M)A VS(F(4, -)) i*J :



?-*?

and M(a,s)-

of this result is in

course

makes

use

Now

we

have to define

morphism of C(A

((V¥/x)A |

A G

(mms^(tc) K^S)K S) I' S

F(A5) essence

of the

Vs(F(A _})

—?■

A) G



V^

on mor-

KM)-

Then

where

S)

i V8(G(A -))

G(A, S).

very similar to that of

preceding

results in Section 6.5. □

Exercise 6.5.22 Theorem

6.5.21.

Write down

some

of the details of the

proof

of

310

Chapter

6.

Classifying Hyperdoctrine of

6.6

The intuition behind

Discussion 6.6.1

Higher Order Polymorphism

an

ojXx-Theory

classifying u;Ax-hyperdoctrines

is

classifying structures in this book. Given an u;Ax- theory Th, the classifying hyperdoctrine can be thought of as the "smallest" such categorical structure in which Th can be soundly interpreted. In order to give a formal definition we need to define an u;Ax-functor, which can be thought of as a structure preserving mapping between u;Ax-hyperdoctrines. the

same as

for all the other

Given

u;Ax-hyperdoctrines C:C°p -+ functor (a,F):C —*? D is a morphism of ?

F is



the components olj: CI



cartesian closed functor C —?

DFJ



—*?

COCat and D:!?^

CCCat, an indexed categories satisfying

sending

for all

V,

on

objects of CI, and

objects / and K of C, ajoVj

where

U in C to V in

u;Ax-

strict cartesian closed functors for every

are

object I oi C, which agree with the action of F ?

-??

=:

FI



FA"

—?

F(I





jRT)

Vpj

o=



a/x/<:

because F preserves finite

a;Ax-hyperdoctrines, and let Th be an u;Ax-theory with model M in C Further, suppose that (a, F): C —?■ D is an u;Ax-functor. Then there is a model (a, F)*M of Th in D defined by the Let C: C°p

->

CCCat and D: P^

products.

-+

(XCa* be

clauses ?

[GH((a,F).M)°p



^([G]m°p)

where G is any

[0]((a,F).M)-P =f ^(I^Imop) S : n?F[iqMoP

ground

kind of

Th,



where 0:

A"i,..., lifn

—?



F(n?[^]Mop)

A" is any operator



f[a]m°p

symbol from Th (possibly





0),

and ?

[/]((a,F).M)tm



function

Then the

=f

symbol

=*

(a[A]((QtF).M)op([/]Mtm))

of Th and A has

length

classifying wAx -hyperdoctrine of



where

/: A; ¥!,..., ¥n

(possibly

T/i is





-?

¥ is

0).

Ax-hyperdoctrine C7( T/i) for which there is a generic model G of Th in Cl( Th) with the following universal property: Given any other model M of Th in some a; Ax-hyperdoctrine C there is which M

an a;

(up to isomorphism) a unique u;Ax-functor (a, F): Cl( Th) (a, F)*G. It is easy to see from the definition that such a

—?

C for



classifying hyperdoctrine

it is also clear that the indexed wAx -functors).

equivalence of indexed categories (and functors which form the equivalence must be

is determined up to

Classifying Hyperdoctrine of

6.6.

Theorem 6.6.2 construct

can

Gof Thin

should a

Suppose that we are given an u;Ax-theory Th. Then we classifying u; Ax-hyperdoctrine Cl(Th) with a generic model

Cl(Th).

now

a; Ax

-hyperdoctrine are no exception. of the proof, leaving the reader to flesh out COCat for the a; Ax-hyperdoctrine Cl(Th).

details

classifying categories

quite familiar, and the basic techniques for the construction

be

syntactic

C:C°p

311

a;Ax -Theory

The methods used in the construction of such

Proof of



an

We shall

give the basic

the ideas.

Let

us

write

->

objects of C are the kinds K of Th. Morphisms K —?■ K' in C are equivalence classes of proved operators under the relation of derivable equality. More formally, consider pairs (X: K, ¥) for which Sg > X: K h ¥: K'. Define an equivalence relation on such pairs by setting The

iff

(X:K,¥) ̄{Y:K,V) A

morphism K and composition

K' is then

—?

of

an

morphisms

is

The objects of the fibre CK

(X:K | ¥):K

C(K, Type) derivable

are

More

on



C(K, Type)

are

by definition morphisms

where here

such

consider for

precisely,

Mi

is

a raw



fixed K

term.

We

in

triples of the form

can

define

an

triples by setting -

(X2:K,x2:¥2,M2)

case

Th for

V[X/Y]:K'.



equivalence class (X:K | ¥) of such pairs, given by substitution of raw operators.

(Xx: #,*!:*!, Mx) in

X:K h ¥

-?

(Xi:K,Xi:¥i,Mi)

just



Type in C. Morphisms (X:K \ ¥) -> (X:K | tf) equivalence classes of proved terms under the relation of

equality.

equivalence relation

Th

some raw

equivalence



Xl:K\xl:¥l\-

operator ^i. Then



Mx



M2[X2/Xl)[x2/xl]:'Vl

morphism (X:



\ ¥)

—?

(X: K \ #)

is

an

class

(X: K | x: ¥ | M) of such

triples, where M is Composition of morphisms Given



a raw

is

term for which Th

given by substitution of

morphism (Z: K' \ @): K'

—>

K in

(Z: K' | O)* : C(K, Type) is

given by substitution of

{X:



raw

> raw

X: K

\ x: ¥

terms.

C, the reindexing functor

—*

C(K\ Type)

operators. Thus for any morphism

| x: ¥ | M): (X: K\¥)

h M: *&.

—?

(X: K \ *)

312

Chapter

C(K, Type)

in

Higher Order Polymorphism

6.

have

we

(Z: K' | 0)* (X: K | ¥) d= (Z: K' \ ¥[0/X]) and

(Z:K' | 0)* (X:K\x:Q\ M) d= (Z:K' \x:¥[6/X] | M[0/X]).

V%:C(K

The functor

V¥(Z:Kx on

object (Z: K

any



K', Type)



K'

V%{Z:KxK'\z:¥\M)

C{K, Type)

given by

is

| 0) =f (X:K \ VY:K'.¥[(X,Y)/Z\)

| ¥)

K'

-?-

of

C(#



#', Type),

and

by



(X:K\x:VY:K'.Q[{X,Y)/Z] \ KY:K'.M[{X,Y)IZ][xY/z\) on

morphism

any

(Z:KxK'\z:¥\M): (Z: K of

C{K

using



K', Type).



K'\ ¥)-^ (Z: K

It is routine to prove that C is

an



K'\V)

u;Ax-hyperdoctrine,

the rules of Th.

The

ground

generic model G

(and

kinds G

(Gop, Gtm) is defined by setting [G]g<>p =f [iir]Gop K for any kind K),



thus



on



[F]GoP d=lf (Z: n?Ki | FCProj^Z),..., ProjB(Z))) symbol F:Ki,..., Kn

for any operator

(Z:

Unit

Gop is



\ C)

for



constant

—*■

Koi

arity n, and [C]g°p prove by induction that

non-zero

operator C: K. One

can



model of Th°v. We also put

[/let- =f (Z: JJ^Ki | z: U^j | /(Proj^z),..., ProjB(z))) /: A; ¥1}..., ¥m —?■ ¥ is a function symbol and the context A by [Xii #i,..., Xn: tfn], and [Jfc]Gt? =f (Z: U^Ki \ z: unit \ k) if A; k: sees by induction that Gtm is a model of Thtm.

where

If D: V0*

is

given

¥. One

u;Ax-hyperdoctrine in which there is a model M of Th, we can define an a;Ax-functor (a, F): C D essentially by applying V is given by the structure M. Thus F: C —*?

OOCat is any other

—?

—?

(X: A" | <*>): K^K' and

a^iCif

easy to prove

i—

\X: K

h 0:

#V [#]m



[#']m

D[jRT]m is defined analogously for each object K of C. M. The remaining details are omitted. that (a, F)*G

—*?



It is □

313

Categorical Type Theory Correspondence

6.7.

Categorical Type Theory Correspondence

6.7

Discussion 6.7.1

Just

have done for the other

simpler type theories in this text, we show that any a; Ax-hyperdoctrine arises as the classifying a; Ax -hyperdoctrine of some a; Ax-theory. We begin by constructing such a theory from a given hyperdoctrine, and then prove a syntax/category theory as we

correspondence. For any

PROPOSITION 6.7.2 define of

an

Th(C)

Proof is

an

u;Ax-theory Th(C)



a;

Ax-hyperdoctrine C:C°p

(Sg, Ax)

for which there is

—>



COCat

we

can

canonical model

inC.

The

ground kinds of Sgop

operator symbol F: Ai,..., An

A. There is



function

are —>

copies A of the objects A of C and there A for each morphism F: A\ x... x An —>

symbol

f:A;MX),...,4>m(X)^(f>(X) x <f>m 0 in a fibre C(A, U). It should be morphism f:<j>i x clear what happens if either n or m are 0. A structure M is given by A (at a ground kind A) and so on. There are also function setting [-A]m°p symbols which assert appropriate isomorphisms between syntax and its denotation (such as Ik'. \K\ —*? K for all kinds K); the reader can provide the full definition. The axioms of Th(C) are given by those operator and term equations-in-context which are satisfied by this structure, which is thus a model

for every

—>

...



of

Th(C) by



definition.

THEOREM 6.7.3

Let C:C°p

the a;Ax-functor

Eq: Cl(Th(C))

of

Cl(Th(C)) applied

->

COCat be any —*■



a;

Ax-hyperdoctrine.

Then

arising from the universal property

to the canonical model of

Th(C)

in C is

one

half of

an

equivalence of indexed categories.

Eq ̄x is defined by taking the categorical structure in C to "syntactic copies" in Cl(Th(C)), for example F.K-+K' in the base K' in the base of Cl{ Th(C)). category of C is mapped to (X: K | F(X)): K Once the definition of Eq ̄l is given the details are lengthy but routine—see Proof

The u;Ax-functor

-+

the

proof



of Theorem 5.8.3.

DISCUSSION 6.7.4

Theorem 6.7.3 is the basis of the

slogan

314

I—

Chapter

6.

Higher Order Polymorphism

Categorical Type Theory Correspondence

u;Ax-hyperdoctrines are a representation of the notion of a; Ax-theories which is syntax independent. Exercise 6.7.5 a; Ax-theories

6.8

State

and sketch

completeness a proof of it.



result for the

categorical

semantics of

Pointers to the Literature

Some of the connections between

polymorphic type theory and higher order logic are discussed in [CE87]. This paper contains a description of the algebraic complete lattice model presented in this chapter of "Categories for Types." For those readers who are interested in looking at the categorical semantics of highly expressive type theories which are perhaps somewhat more complicated than those of this book, see [HP89]. This paper presents the so-called Calculus of Constructions along with a full account of its category- theoretic models. Further details of higher order polymorphism and associated models can be found in [See87]. The notion of kind given in this paper is a little more restricted than that of our Chapter 6, but the syntactical theories considered are slightly more complex in the sense that they involve a richer class of operators and terms.

higher

order

Bibliography [AL91]

A.

Asperti

and G.

introduction to Foundations of

[Bar84]

[Bir67]

H.

Barendregt. The Lambda Calculus: Its Syntax and Studies in Logic and the Foundations of Mathematics. Holland, 1984. Volume 103.

N. Bourbaki.

Algebre (elements de mathematique,

M. Barr and C. Wells.

[Car86]

L. Cardelli. A

[Car89]

L. Cardelli.

livre

ii), chapitre

Ind., 1044, 1948.

International Series in

Category Theory for Computing Science. Computer Science. Prentice Hall, 1990.

polymorphic lambda calculus with type:type. Technical Report 10, Systems Research Center, 130 Lytton Avenue, Palo Alto, CA, 1986.

Research

[CE87]

North

Theory. Coll. Publ. XXV, American Society, Providence, RI, 3rd edition, 1967.

3. Actualites Sci.

[BW90]

Semantics.

G. Birkhoff. Lattice Mathematical

[Bou48]

Longo. Categories, Types and Structures : An category theory for the working computer scientist. Computing Series. The MIT Press, 1991.

Typeful programming. Technical Report 45, Systems Center, 130 Lytton Avenue, Palo Alto, CA, 1989.

Coquand and T. Ehrhard. An equational presentation of higher order logic. In Summer Conference on Category Theory and Computer Science. University of Edinburgh, Scotland, U.K., September T.

1987.

[CGW87]

Coquand, C. Gunter, and G. Winskel. dl-domains as a model of polymorphism. Technical Report 107, University of Cambridge Computer Laboratory, 1987.

[CGW89]

T.

Coquand, C. Gunter, and G. Winskel. Domain theoretic models of polymorphism. Information and Computation, 81:123-167, 1989.

[Chu40]

A. Church. A formulation of the

T.

of Symbolic Logic, 5:56-68,

1940.

simple theory of types. Journal

316

Bibliography

[Coh79]

P.M. Cohn.

[DP90]

B.A.

Algebra,

volume 2. John

Wiley

and Sons

Ltd.,

1979.

Davey and H.A. Priestley. Introduction to Lattices and Order. Cambridge Mathematical Textbooks. Cambridge University Press, 1990.

[EM42]

Eilenberg and S. Mac Lane. Natural isomorphisms theory. Proc. Nat. Acad. Sci. U.S.A., 28:537-543, 1942.

[EM45]

S.

[Fre64]

P. J.

[Fre67]

G.

S.

in group

theory of natural equivalences. Trans. Amer. Math. Soc, 58:231-294, 1945. and S. Mac Lane. General

Eilenberg

Freyd.

Frege.

Abelian

Categories. Harper

and

Row,

1964.

Function and concept. In P. Geach and M.

Black,

editors, Translations from the Philosophical Writings of Gottlob Frege. Blackwell, Oxford, 1967.

[GHK+80]

Hofmann, K. Keimel, J.D. Lawson, M. Mislove, and D.S. Scott. A Compendium of Continuous Lattices. Springer- Verlag, 1980.

[Gir86]

J.-Y. Girard.

G.

Gierz,

K.H.

Theoretical

[Gir89]

The system F of variable types fifteen years later.

Computer Science, 45:159-192,

1986.

Proofs and Types. Cambridge Tracts in Computer Science. Cambridge University Press, 1989. and with appendices by P. Taylor and Y. Lafont. J.-Y. Girard.

[Gra71]

G. Gratzer. Lattice

[Gra78]

G. Gratzer. General Lattice

[HP89]

J.M.E.

Theoretical Translated

Theory: First Concepts and Distributive Lattices. W.H. Freeman and Co., San Francisco, 1971.

Hyland

Theory. Birkhauser, Basel,

1978.

theory of constructions: and topos-theoretic models. In Categories in and Logic, volume 92 of Contemp. Math., pages

and A.M. Pitts. The

Categorical semantics Computer Science 137-199, 1989.

[Joh82]

P.T. Johnstone.

[Joh87]

P.T. Johnstone. Notes

Spaces, volume 3 of Cambridge Studies in Advanced Mathematics. Cambridge University Press, 1982.

University Press,

Stone

1987.

on

Logic

and Set

Theory. Cambridge

317

Bibliography

[Kan58]

D.M. Kan.

Adjoint

functors. Trans. Amer. Math.

Soc, 87:294-329,

1958.

[Lam80]

categories. In J.P. Seldin and J.R. Hindley, editors, To H.B. Curry: Essays on J. Lambek.

From A-calculus to cartesian closed

Combinatory Logic, Press,

Lambda Calculus and Formalism. Academic

1980.

[Law63]

F.W. Lawvere. Functorial Semantics

[LS80]

J. Lambek and P.J. Scott.

of Algebraic Theories. PhD thesis, Columbia University, 1963- Summary appears in Proceedings of the National Academy of Science, 50:869-873, 1963.

topos. Journal

[Mac48]

S. Mac Lane.

[Mac50]

S. Mac Lane.

and

theory and the free Applied Algebra, 19:215-257, 1980.

Groups, categories U.S.A., 34:263-267, 1948.

516,

[Mac71]

of Pure

Intuitionist type

and

duality.

Proc. Nat. Acad. Sci.

Duality for groups. Bull. Amer. Math. Soc,

56:485-

1950.

S. Mac Lane.

Working Mathematician, volume Mathematics. Springer-Verlag, 1971.

Categories for

of Graduate Texts in

the

[Man76]

E. Manes.

[McL91]

McLarty. Elementary Categories, Elementary Toposes, volume 21 of Oxford Logic Guides. Oxford University Press, 1991.

[ML]

P. Martin-L6f. Constructive mathematics and computer

Algebraic Theories, volume Mathematics. Springer-Verlag, 1976.

26 of Graduate Texts in

C.

programming. In Logic, Methodology and Philosophy of Science, IV, Published by North-Holland, 1982.

[ML71]

P. Martin-L6f. A

of

[ML72]

Stockholm,

theory of types.

P. Martin-Lof. An intuitionistic

P. Martin-L6f. 1984.

Technical

1979.

Report 71-3, University

1971.

University of Stockholm,

[ML84]



theory of types. Technical report,

1972.

Intuitionistic

Type Theory.

Bibliopolis, Napoli,

318

[NPS90]

Bibliography

B.

Nordstrom, K. Petersson, and J.M. Smith.

Martin-Lof's Type Theory, volume 7 of Science. Oxford University Press, 1990.

[Pie91]

Programming in Monographs on Computer

Category Theory for Computer Scientists. Computing Series. The MIT Press, 1991.

B.C. Pierce. Basic Foundations of

[Pit87]

Polymorphism is set theoretic, constructively. In Summer Conference on Category Theory and Computer Science. University of Edinburgh, Scotland, U.K., September 1987.

[Sco69a]

D.S. Scott.

A.M. Pitts.

manuscript,

[Sco69b]

Models of the lambda calculus.

1969.

D.S. Scott. A type theoretic alternative to CUCH, ISWIM, OWHY.

Unpublished manuscript, University

[Sco70a]

D.S. Scott. Oxford

[Sco70b]

Unpublished

of

Oxford,

1969.

The lattice of flow

diagrams. Technical Report 3, University Programming Research Group, 1970.

D.S. Scott. Towards Annual Princeton



theory of computation. In 4th Information Sciences and

mathematical

Conference

on

Systems, 1970.

[Sco71]

D.S. Scott. Continuous lattices. Technical

University Programming Research Group,

Report 7, Oxford

1971.

[Sco76]

D.S. Scott.

[Sco82]

D.S. Scott. Domains for denotational semantics. In ICALP 1982,

Datatypes 5(3):522-587, 1976.

as

lattices.

volume 140 of Lecture Notes In

Springer-Verlag,

[See87]

R.A.G.

SIAM Journal

Computer Science,

of Computing,

pages 577-613.

1982.

Seely. Categorical

lambda calculus.

higher order polymorphic of Symbolic Logic, 52(4):969-989,

semantics for

The Journal

December 1987.

[SS71]

D.S. Scott and C.

[vD89]

D.

Strachey. Towards a mathematical semantics for computer languages. Technical Report 6, Oxford University Programming Research Group, 1971. van

3rd

Dalen.

edition,

Logic

and Structure. Universitext.

1989. Corrected Third

Printing.

Springer-Verlag,

319

Bibliography

[Vic89]

Topology via Logic. Cambridge Tracts in Computer Science. Cambridge University Press, 1989.

S. Vickers.

Theoretical

Index above 117 abstraction 154, 158, 204, 281

adjoint —

symbol of 2Ax-term signature 208 of function symbol of u;Ax-term signature 277 of operator symbol 276 of type symbol 204 ascending chain condition 17 —

of function



functor theorem for

preorders 79 functor theorem 102 Freyd's left for categories 81 left for preorders 77 for categories 81 right for preorders 77 right functor theorem 104 special adjunction —









associative







between

categories

81

between

preorders

77









closure operator 27

closure system 27

poset 26

signature

theory a-equivalent —



raw

121

terms from

raw terms

158

from

raw

anti-symmetric relation 3 antitone function 10 appears 124

arity





of



of

term term

type



types 205 anti-chain 8



axiom

algebraic theory Ax-theory 161 —







127

277

of

2Ax-theory 214 of a; Ax-theory 284

208

base category

2Ax-term signature 210 —

atomic Boolean lattice 117

balanced category 115

127

Ax-signature —

atom 117

operator

algebraic

in

category 40





composition





of indexed category 107 of

2Ax-hyperdoctrine 224 of a;Ax-hyperdoctrine 285

basis 26

Beck-Chevalley condition 35 for 2Ax-hyperdoctrine 225 for u;Ax-hyperdoctrine 285 binary coproduct 58 product 55 product type 156 —









of function

symbol of algebraic signature 122 of function symbol of Ax-signature 156



relation 3

has

coproducts 96 has products 55, 96 specified products 55 —





Index

321

binding

154



natural transformation 107

Boolean lattice 21

categorical type theory

bottom element 8

categories

bound —



equivalence of operator variable 277, 281 term variable from







209

term variable from

281

type variable 204, 209 variable 158

greatest lower least upper lower



upper bounded









category 40











110 equivalence of indexed 53 equivalent 110 equivalent indexed left adjoint for 81 43 product of 81 right adjoint for —

signature

u;Ax-term











cocomplete poset

26





classifying category of algebraic theory 142 classifying category of Ax-theory 177 isomorphism 60, 72 captured 154









term variable from 2Ax-term

signature —



209

type variable 209 variable 158

cardinality

of set 3





of models of of

Ax-theory

presheaves

114

of Scott domains and

embedding-projection pairs 242 of subobjects 103

associative

composition

in —40 balanced base

base







115

of indexed category 107

of

2Ax-hyperdoctrine base



C-indexed





category 185 C-indexed

category 107 functor 107



classifying theory classifying comma

discrete filtered

224

of

closed functor 72



174

of Scott domains 43

cartesian closed

lifting 117 product of lattices 14 product of preorders 5 closed relatively free



algebraic theory

closed category 67





of models of

u;Ax-hyperdoctrine

cartesian 117 —

of indexed categories 108 137

canonical



53





signature

2Ax-term

121











285

67

107

of

algebraic

139 —

of

Ax-theory

48 41 114

finitely cocomplete finitely complete





97

97

175

Index

322

sub—,

full

functor

glued

49



—,51

—,

identity



189

in

algebraic 40

—,



small sub

—,

—,

tiny

chain,

48 —,

powered

103

—,



condition,



17

condition,

17

—,

97

74

for



2Ax-hyperdoctrine, 263 u;Ax-hyperdoctrine, 310 cleavage, 117 —

closed

cartesian



category, 67

functor,

reflects

—s

of

shape I, 99 of shape I, 99

—s



lattice,

20

complete algebraic theory, 150 lattice, 12 lattice homomorphism, —







12

poset, 9

2Ax-theory, 273 finitely category, 97





P--,9 small —, 97

15



preserves

complement in

category of Ax-theory, 175

cartesian

96, 97

compact element of poset, 26 comparable, 3

category of algebraic theory, 139

subset,

99

comma



closure

small

category, 97

category, 48 commutative diagram, xvii

infinite —s, 17

detecting —,115 equivalence —, 3 separating —,115 classifying





has all small —s, 97

class



finitely P--9

diagram, 95 —s of shape I, 95 creates —s of shape I,

48

—,







has all finite —s,

ascending descending no

poset, 9 directed poset, 9







anti-

117

colimit

under-cone well

fibration, cocomplete cloven

has all —s, 96

61

44

—,

operator, 27 system, 27

algebraic Kleene —, 42

coequaliser,

48

over-cone —,





morphism, 108 isomorphic objects in —, 52 isomorphism in —, 52 lluf sub—, 49 locally small —, 61 morphism of —, 40 object of —, 40 opposite —, 42 indexed

operator, 15 system, 15

72

component —

of

homomorphism of models of algebraic theory, 137

323

Index

homomorphism of models of Ax-theory, 174 of natural transformation, 49 composable, 40 composition of morphisms, 40 compositional witnessing, 308

binary —s, 96 coreflective, 88 coseparating collection, counit, 89

condition

cpo



of



—,









over, 92





under, 95

diagram,

dcpo,

91



u-

—s, 24

symbol of algebraic signature, 122 function symbol of Ax-signature 156 function symbol of 2Ax-signature, 208 function symbol of 48

algebraic signature, Ax-signature, 159

operator

term type

homomorphism of —s, 24 sub

25



defined,

235

descending chain condition, detecting class, 115 diagonal functor, 83 diagram colimit for

constant





—,

continuous

123

diagrams, set

for

2Ax-signature,

211

for

a;

Ax-signature,

281

206

function,

25





functor,

coproduct, 59 insertion, 59 binary —, 58 —

has all finite —s, 96

xvii

91

a —,

91

91

46

—,



directed



contravariant powerset

—,

—,

difference

277

—,

95

a —,

Hasse —s, 4 limit for

for

term

33

—,

commutative

operator symbol, 276 type symbol, 204 for

shape I, 99 shape I, 99

24

free

function

functor,

limits of



context —

of

colimits of



u;Ax-term signature, 281 —

24

creates





46

a;—, 24

102

constant —

104

functor,

covariant powerset

homomorphism

cone —

has

d—,

ascending chain —,17 descending chain —, 17 solution set

has all small —s, 96

cocomplete poset, poset, 8 set, 8

discrete —

category, 41

preorder, 3 distributive lattice, domain, 24 —

19



17

Index

324



of PER 234



category of Scott

—s

43

category of Scott

—s

and

embedding-proj ection pairs 242 Scott

33





of indexed categories 110 relation 3

inverse



53

relation 234 partial equivalent algebraic theories 150 categories 53 indexed categories 110 —



down-set 8





e-p

242

pair

bottom



compact

global least

evaluation functor 51



image functor 47 exponential 67 existential

of poset 26



57





greatest





minimal





fibration 117 cloven



split

62 242

endofunction 2



endomorphism epic morphism equaliser 74

49

has all

96



73



term



term a;

type





161

2Ax-hyperdoctrine 224 of o;Ax-hyperdoctrine 285

products

from

class 3

of categories 53









preserves 214

from 208

has all has all

277

equivalence —

of

has all

Ax-signature

Ax-signature



of indexed category 107

has all

2Ax-signature —

of fibration 117



signature 127

operator

118

finite

algebraic

from



filtered category 114

equation-in-context



117

fibre —

endofunctor 49

from



fibre of— 117

embedding-projection pair

—s

72

faithful functor 49

242

Yoneda

—s





top —8

embedding

mate 67

preserves





maximal



Ax-theories 184



element

colimits 96, 97

coproducts

96

limits 96, 97

products 96 products 60



finitely cocomplete category 97 complete category 97 complete poset 9 presentable 292 locally presentable 292 fixpoint 26 —

284

58









Index

325

least



26

inverse for monotone

flat natural numbers 171

monotone

forgetful functor 48 fp-generators 292

partial



10

10







pointwise

monotone



space 10

free —





dcpo

33

source

operator variables 277, 281

strict

term variables from

target of

2Ax-term —

signature





209

signature

281

type variable 205 type variables 209 variables from

total

25











algebraic

category 51

adjoint





C-indexed

158

functor 49

72

107



48



covariant powerset

49

diagonal

symbol of algebraic signature 122 symbol of Ax-signature symbol of 2Ax-term signature 208 symbol of u; Ax-term signature 277

156

type 156 antitone 10



46

46

51

existential

image

faithful

49







82



evaluation



48 forgetful Freyd's adjoint



47



full





theorem 102

49

identity modelling



45

—s

for

algebraic

theories 139



symbol of algebraic signature 122 constant symbol of Ax-signature 156 constant symbol of 2Ax-term signature 208 constant symbol of wAx-term signature 281

modelling

continuous

universal













contravariant powerset

subcategory

constant

79

cartesian closed

variables from

function



theorem for



constant



25



functor 45

full







preorders

Ax-signature —



u;-continuous

signature 123 —





undefined

term variables from u;Ax-term



of

25

—s

for

Ax-theories 175

product



reflection

47



87

107 reindexing 62 representable theorem special adjoint —





2Ax—262

image



47

104

Index

326

weakening uXx-





265



310





310

generic —

model of

theory —





of lattices 12 of models of

algebraic

theories 137

139



176

Ax-theory model of 2Ax-theory 263 model of u;Ax-theory 310

global element glued category

lattices 12

complete of dcpos 24

algebraic

model of



of

57



of models of Ax-theories 174 of a;-cpos 24 of

preorders hyperdoctrine —

2Ax-

189



a;Ax

10

224 285

greatest element 6 greatest lower bound 7

ideal

ground

lifting 31 of join-semilattice idempotent 21 identity







kinds 276



types 156

has





























terminal

all all all all

object 96 coequalisers 96 equalisers 96 finite colimits 96, 97 finite coproducts 96

in category 40

implication Heyting incomparable

22





indexed C

category 107

all finite



functor 107



natural

all all

products pullbacks 96 pushouts 96

96

transformation 107

all small colimits 97 all small

coproducts

all small









lattice 22

homomorphism

categories 108 equivalence of categories 110 equivalent categories 110 morphism of categories 108 category of

96

all small limits 97





functor 45

all finite limits 96, 97

products 96 an initial object 96 binary coproducts 96 binary products 55, 96 small products 58 Hasse diagrams 4 Heyting implication 22 —











inductive subset 8 infimum 7 infinite no



chains 17

initial —

object

has

an



59

object

insertion 58 12

30

coproduct



59

96

327

Index

internal

language 149, 183,

meet-semi— 12

273

intreid 107

modular

inverse

sub— 12

equivalence





52

morphism isomorphic —





objects





52



Yoneda

in category 52

length lifting

of posets 10

natural



52





join 7 join-semilattice

ideal 12

276

kinds 276 Kleene closure 42 1-r

pair

I 99

has all finite

—s

96,

97

has all small

—s

97





149, 183,

273

homomorphism

12 —

21

product of —s 14 20 complement in a 12 complete complete homomorphism cartesian

22 Heyting join-semi— 12

19

bound 6

segment 35

exponential



67

maximal element 6





small category 61

mate 81





292

lower —

distributive

—s

of

subcategory 49 locally finitely presentable

lattice 12



shape I 99 of shape I 99

—s

lluf



Boolean



reflects

Ax-signature 156 Ax-theory 161 language



for

preserves

293

internal

31



diagram 91 —s of shape I 92 creates —s of shape



kind

ground

117



limit

124

—s

63

17

cartesian

judgement

293

lemma

isomorphism —

upper bound 7

adjoint for categories 81 for preorders 77 left-right-continuous pair

in category 52



26

fixpoint



posets 10

naturally

element 6

left

elements of poset 3





least

53

for monotone function 10



19



12

mediating morphism for binary product —

55





morphism

for colimit 96

Index

328





morphism for limit 92 morphism for product



of indexed

composition of —s

57

epic

meet-semilattice 12

inverse

minimal element 6

mediating

40



52





for

binary product

55

model

mediating mediating mediating

of

algebraic theory 134 of Ax-theory 171 of 2Ax-term theory 231 of 2Ax-theory 234 of 2Ax-typing theory 225 of u;Ax-operator theory 286 of u;Ax-term theory 290 of u;Ax-theory 291 category of —s of algebraic





monic



of

vertical

for limit 92 for

product

174





49

40







55

40

117





bijection in adjunction isomorphism 52 numbers object 197 transformation 49



C-indexed





transformation 107



natural numbers flat

171





topped

for Ax-theories 175

modification 109 modular lattice 19 monic

morphism 75 regular 75 split

73



vertical

no



initial





function 10

function space 10

morphism —

of category 40

52

of category 40

monotone

pointwise



exponential

function 10



object

has

inverse for





infinite chains 17

monoid 42



vertical

naturally isomorphic





57

natural —

Ax-theory of algebraic generic theory 139 of Ax-theory 176 generic of 2Ax-theory 263 generic of u;Ax-theory 310 generic modelling functors for algebraic theories 139

of

target of



—s



for colimit 96

73



source



category of







theory 137



parallel —s projection





108

73

meet 7



categories

an



initial —



59

sub— 103 terminal u;-chain 8 a;cpo 24 operator



67

57

96

81

Index















PER 234

axiom 277

equation-in-context

symbol

276



proved raw



ljXx-



closure



27

277

complete

277

directed

preorder

relation 3

reflect







over-cone



92

category 48

P-cocomplete 9 P-complete 9 —

293

left-right-continuous parallel morphisms 49 partial equivalence relation











is



is

an

function 3 order 4

partially ordered 4





functor 46

functor 46

chain 8 anti-chain 8

adjunction

between

discrete





—s

77

homomorphism of —s 10 left adjoint for —s 77 5 opposite right adjoint for —s 77 preordered set 3 presentable 292 finitely 292 locally finitely —

pair 1-r





over cone

preorder —





covariant

ordered

partially



contravariant

10







powerset 5



restriction





10

preserving



26

26

cocomplete 9 finitely complete isomorphic —s 10 isomorphism of —s 10 poset-ideal 33









directed

category 42

partial pointwise

26

compact element of

signature 276







order



reflection 4

cocomplete 9 cocomplete

operator-in-context opposite



order 5

bounded

276



monotone function space

algebraic

15



234

poset 4

variables 276





pointwise —

theorem 277

closure



277

structure 285

algebraic



domain of

context 277

293





preserves

234









shape I 99 exponentials 72 finite products 60 limits of shape 2 99

colimits of

330

Index

preserving order



presheaves product 56 —



10





114





of categories 43 57

projection 55 binary









cartesian cartesian finite

—s



type 156 —



of lattices 14 of

preorders 96

has all small

—s

96

binary

has small

—s

—s

—s

60

58 —s

55

242

signature

functor 87

—s87



124





limits of

reflexive relation 3



159

term from 2Ax-term

211

term from u;Ax-term

shape I 99 shape I 99

colimits of

34

regular

term from

signature —

reflection



algebraic

Ax-signature —

type 204 reflect order 10

reflects

operator 277 term from

281

reflective 87





208

term from u;Ax-term

poset

morphism 55 57 product proved —

term from 2Ax-term











2Ax-signature 209 subtype 204 term from algebraic signature 122 term from Ax-signature

signature

58

specified binary projection





55, 96

preserves finite —s



157

subterm from

signature —s

small

subterm from

58

has all finite

has

277

suboperator

Ax-signature

functor 47

binary

operator 276

monic 75

reindexing

functor 107

relation

anti-symmetric 3 binary equivalence







signature type 206 pullback 75

281









along

has all

pushout

—s

96

76

has all raw

76

—s

96

order





partial equivalence reflexive



symmetric transitive



234











relatively free cartesian closed category 185

157

Index

representable

functor 62

closed sub— 15

representation 63

directed sub— 8

restriction order 3

down

right adjoint

inductive sub— 8





for

categories 81 for preorders 77

preordered solution

up-

S-section —

for

2Ax-hyperdoctrine

249

§-section —

for

u;Ax-hyperdoctrine

306

satisfies —

equation-in-context from

algebraic



equation-in-context Ax-signature 171

from

operator equation-in- term

equation-in-context

from —

term

2Ax-signature



231

equation-in-context

from

a;

Ax-signature

290

type equation-in-context 225

scope

158, 204,

domains 43



domains and



embedding-projection pairs 242

upper





creates limits of

limits of

Sierpinski 21 signature algebraic Ax-



I 92











I 99

I 99 1 99

I 99

121

156

2Ax-term —208 2Ax-



203

2 Ax-type —204 wAx-



276

-operator



276

Ax-term —277

small —





cocomplete 97 complete 97 products 58

has all

solution

difference 3 —









colimits 97

coproducts



sorting

96

limits 97

products

96

category 61 small category 61

locally

set

of

I 99

I 99



reflects colimits of

has all

35

cardinality





preserves colimits of

has all

35

semigroup 41 separating class 115 —

I 95

creates colimits of

has all

segment lower



simultaneous substitution 123

domain 33

category of



colimits of

u;

category of

condition 102



shape

a; Ax

281

Scott —



reflects limits of

context 286 —





preserves limits of

signature 134 —





set condition 102

332

Index











for function

symbol of algebraic signature 122 for function symbol of Ax-signature 156 for function symbol of 2Ax- term signature 208 for function symbol of u;Ax- term signature 277 for operator symbol 276

subobject

category of

raw





of

raw

of

raw



morphism







of



of

40 —

binary products

55





colimits 97 limits 97

raw

monic 75

cartesian closed functor 72

product preserving



for for for

algebraic signature Ax-signature 168 2Ax-signature 234 a; Ax-signature 291

operator —



132

type

lluf



123



subterm from



157

subterm from

2Ax-signature

209

subtype —

204









symbol Ax-signature constant function

2Ax-term

285

for 2Ax-term signature for 225

Ax-signature

289

Ax-term

44

49

of

156 —

of

constant function



of





of

signature function





204

algebraic

122

of

Ax-signature

156

281

of

algebraic signature function

208

signature

constant type

49

sublattice 12

a;



signature

constant function u;

sub-dcpo 25 subcategory full

raw

constant function

227 term

210

supremum 7

for

term

raw

raw

function 25





terms from 2Ax-term

Ax-signature

structure



159

subterm

functor 60 —

raw

simultaneous

fibration 118

finite

terms from

types 205 of raw types from 2Ax-type signature 210

of

strict —

raw

algebraic

123

signature

split —

terms from

Ax-signature

specified —

operators 277

theory

of function 2 of

277

substitution





103

—s

suboperator

source —

103

122

Index

333

function

of 2Ax-term



signature 208 function



of

u; Ax-term

from 2Ax-term proved signature 211 from u;Ax-term proved —



signature 281

signature 277 operator type



276



raw

raw

system

raw

algebraic

closure



from

algebraic signature

from

Ax-signature

122

204

symmetric relation 3

closure







raw





of function 2



of

morphism





2Ax-theory 214 of a; Ax-theory 284

axiom of

context for

211

context for





Ax-signature 281 equation-in-context from 2Ax-signature 214 equation-in-context from a; Ax-signature 284 structure for 2Ax-term signature 227







structure for

a;

Ax-signature





for for for

for

theorem of theorem

2Ax-theory 214 of a; Ax-theory 284

variables for 2Ax-term variables for

277

algebraic signature 124 Ax-signature 159 2Ax-term signature 211 u;Ax-term signature 281

terminal

object 57 has a object

theorem —







from

algebraic theory Ax-theory 161 2Ax-theory 214 a; Ax-theory 284

from from from

term



type





of

2Ax-theory 214 of a; Ax-theory 284

208

theory algebraic

signature 281 from algebraic proved —

2Ax-

127



159

214 —

2Ax-typing a;





2Ax-term

ujXx-

signature 124

127

277



Ax- —161

a; Ax-term

from proved Ax-signature

96



term

signature 208 —

signature

operator

289 —

u;Ax



u;



signature 208



2Ax-signature —

2Ax



axiom

281

term-in-context

40

term —

208

from u;Ax-term

signature target

157

from 2Ax-term

signature

27

15





214



208

284

Ax-operator

u;Ax-term





284

277

334

Index

categorical

48

tiny category

121



type-in-context 206

top element 8

vertical natural numbers 5

topped

total function 2

undefined function 3

tracks 235

under cone

transformation C-indexed natural natural



under-cone category 48

107

underlying

49





theories 149

algebraic

universal —

of Ax-theories 184



2Ax-hyperdoctrine 2Ax-signature 203 2Ax-term signature 208 2Ax-term theory 214 2Ax-theory 214 2Ax-type signature 204 2Ax-typing theory 208 224







upper —













121





for for

204

constant free



term

—s —

raw —s

2Ax-

156

symbol

204

variable 205

function

ground proved



variable 204, 209





theory

158





156

for 2Ax-term

204

signature

type vertex



208

u; Ax-term

281

204

92, 95

vertical —

morphism

117

natural numbers 4

topped

206

for

signature



156





natural numbers 5

^-continuous function 25 204

122

276

signature

variables 204



209

algebraic signature Ax-signature 157

operator term

theorem 208







variables

208

structure 225

bound

type

captured

algebraic signature Ax-signature 156

binary product

158



bound type

equation-in-context

symbol

segment 35

bound

context 206

for

bound 6

variable

axiom 208

for

image functor 47 properties 59

up-set 8

type —

40

unitary

translation

of



unit 89

transitive relation 3



95



weakening functor 265 well powered category

103

Index

witnesses 52

witnessing compositional u;



308

Ax-functor 310

cjAx-hyperdoctrine 285 u; Ax-operator signature 276 a; Ax -operator theory 277 a; Ax-signature 276 u;Ax-term u;Ax-term a;

signature 277 theory 284

Ax-theory

284

Yoneda —



embedding lemma 63

62

This textbook

explains

and illustrates

some

semantics

for

principles techniques used

the basic

of the

specific type

of categorical type theory to derive categorical

theories. It introduces the reader to ordered

set theory, lattices and domains, and this material provides plenty of examples for an introduction to category theory. Categories, functors

covered, along with the Yoneda lemma, cartesian closed categories, limits and colimits, adjunctions and indexed categories. Four kinds of formal system are presented in detail, namely and natural transformations

are

algebraic, functional, second-order polymorphic and higher order polymorphic type theories. For each of these type theories a categorical semantics is derived from first principles, and soundness and completeness results are proved. Correspondences between the type theories and appropriate categorical structures are formulated, along with a discussion of internal languages. Specific examples of categorical models are given, and in the case of polymorphism both PER and are considered. Categorical gluing is used to prove results about type theories. Aimed at advanced undergraduates and beginning graduates, this book will be of interest to theoretical computer scientists logicians, and mathematicians specialising in category theory.

domain-theoretic structures



CAMBRIDGE UNIVERSITY PRESS

IFJ ai DB Price

Fhi-.-lhe

BSBN

5?'-^. -spN^ '"' '■' I" .

"?



III.

In

"78

521" 509281