lecture 2: introduction to category theory nick rossiter, computing science, newcastle university,...

36
Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England [email protected] .uk http://www.cs.ncl.ac.uk/people/

Upload: kory-white

Post on 05-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Lecture 2: Introduction to Category Theory

Nick Rossiter, Computing Science, Newcastle University, England

[email protected]://www.cs.ncl.ac.uk/people/b.n.rossiter/

Page 2: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Features of Interoperability

• Complex mappings from user views to way data is held

• Need to handle data, metadata and metameta data

• Need to make semantic transformations

Page 3: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Category Theory?

• Need relations to represent mappings between levels

• Multi-level construction (higher-order)

• Category theory seems appropriate:- categories for basic structures

- functors relate categories

- natural transformations relate functors

Page 4: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Origins of Category Theory

1940s Sammy Eilenberg

1960s Fred Lawvere

1970s Saunders Mac Lane

1990s Mike Barr & Charles Wells

Peter Freyd

Various views: “Multi level Graph Theory”

“Multi level Functional Programming”

“Multi level Type Theory”

Page 5: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Basic Constructions

• The Category:

• Collection of arrows which may be named:

(name:) source target

e.g. a b

1a: a a (identity arrow named 1a)

f: b c (arrow named f)

Page 6: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Categorial Axioms 1

• The identity arrow 1a identifies an object a

• Arrows are composable if the source of one forms the target of the other:

a b, b c has composite a c

• Composition is associative:

f: a b, g: b c, h: c d

f o (g o (h)) equiv ((f) o g) o h

Page 7: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Categorial Axioms 2

• Identity arrows may be used for the operation of composition:

e.g. f: a b, g: b c f

a b

f 1b g

b c

g

• Equations: 1b o f = f and g o 1b = g

Page 8: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Types of Category

• Categories are named in bold font.

• A number of universal basic types have been developed for:

Sets

Ordered constructions on sets

Products

Relationships

(and many others)

Page 9: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Discrete Categories

• Every arrow is an identity arrow

e.g. aa, b b, c c

• Discrete categories are sets (without functions)

Page 10: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Simple Categories 0,1

• 0

empty category -- no objects, no arrows

• 1

(discrete) category with one object and one identity arrow e.g.

a 1a: a a

Page 11: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Simple Categories 2

• 2

Category with two objects and one arrow which is not an identity e.g.

a, b a b

Page 12: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Category Set

• Set

The objects are sets

The arrows are total functions between the sets

e.g. Sets X, Y, Z

Total functions a:X Y, b:Y Z

Page 13: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Category Set (commuting diagram)

• Represented as category XYZ in the universal category of Set

X

a c

Y Z

b

• Diagram is said to commute if c = b o a

• Equational logic to accompany diagrams

Page 14: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Category Preorder

• A set of objects p,q,r,…

• A collection of arrows such that:

each arrow represents an ordering

• There is no more than one arrow between any two objects

• p q is the ordered pair <p,q> for which p <= q

Page 15: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Preorder construction

• Satisfies categorical axioms:

identity p p (for each object)

composition p <= q <= r implies p <= r through transitivity

• Example of preorder: (may be symmetric)

b

d c e

a

Page 16: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Preorder Applications

• May be cyclic

• Occur naturally as rich data structures in information systems e.g. object-oriented

• In some approaches e.g. relational, preorders are converted to an equivalent collection of partial orders

• Normalization techniques

Page 17: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Partial Orders - Category Pos

• Collection of partial-order objects with order-preserving arrows between them

• As preorder but with asymmetric axiom:

if p<=q and q<=p then p=q is implied Objects b

Pos1 d c e

a

Pos2 a d

Order-preserving arrows: Pos2Pos1; Pos1 Pos2

Page 18: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Pos Applications

• Derived from Preorder by Functor (see later) to convert symmetric structures to asymmetric ones

• Basis of logic

• Ordering by projection, inclusion

• Inheritance and aggregation paths• Basic data structuring with constraints (keys)

• Relationship representation

Page 19: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Types of Arrow - Monic

• Monic:

m

a b

f g

d

• If m o f = m o g implies f=g, then m is monic. Left-cancellable.

• One path. Injective in sets. 1:1 relationship.

Page 20: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Types of Arrow - Epic

• Epic

h d

a b c

e

• If d o h = e o h implies d=e then h is epic.

Right-cancellable.• Onto. Surjective in sets. Mandatory relation.

Page 21: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Isomorphisms

• A mapping that is both monic and epic in the category Set is isomorphic.

• In other types of categories, this cannot always be assumed to hold.

Page 22: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Collections of Arrows - Hom Sets

• Sometimes useful to think of the collection of arrows between two objects

• Termed a hom set

• Written homC(a,b)

to represent all arrows between objects a and b in the category C.

• Emerge as results of queries on information systems

Page 23: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Types of Object - Initial

• An initial object in a category has precisely one arrow from it to every other object.

b

a c

d

• a is initial object in this category

• Bottom in partial orders; identifiers or keys in databases;

Page 24: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Types of Object - Terminal

• A terminal object in category has precisely one arrow onto it from every other object

a

b emptyset

c

• emptyset is terminal object

• top in partial orders; base supertype in inheritance partial orders

Page 25: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Category with Products

• A category has finite products if in addition to objects, say, a,b,c, it has:

• a product object a x b x c • projections:

pi1: a x b x c a

pi2: a x b x c b

pi3: a x b x c c

Page 26: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Product - Universal Mapping

• Binary product example (U universal object)

A x B

pi1 d pi2

A U B

f g

Equations: f o pi1 = d = g o pi2

Page 27: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Relationships -- Pullbacks

• Notion of subproduct

• Relation of two objects in context of a third

• Restriction of universal product

• Pullback of one arrow over another

Page 28: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Pullback Diagram for f over g - Basic Arrows

A

pil f

A XC B C

pir g

B• A, B are objects in relationship• C includes coproduct A+B, product AXB, link objects.

• A XC B is product A X B in context C

• Equational logic: f o pil = g o pir

Page 29: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Pullbacks - More Arrows 1

A

pil pi*l f

Delta

A XC B C

pi*r

pir g

B

Page 30: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Pullback - More Arrows 2

A

pil pi*l f

Coprod

A XC B Delta C

pi*r Prod

pir g

B

Page 31: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Interpretation of Objects, Arrows

• A XC B relation A to B over C

• Delta: C A XC B

Mapping from link object to relation

• Coprod: A XC B C (exists)

Mapping from relation to coproduct in C

• Prod: A XC B C (for all)

Mapping from relation to product in C

Page 32: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Interpretation of Projection Arrows

• pil: A XC B A

left projection

monic -- each A participates once in relation

epic -- each A must participate in relation

• pir: A XC B B

right projection

monic -- each B participates once in relation

epic -- each B must participate in relation

Page 33: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Coproducts (Sums)

A+B

il d ir

A U B

f g

Equations il o f = d = ir o g

U is universal object

Page 34: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Restricted Coproduct

• Pushout

A

f il

C A +C B

g ir

B

Restriction over object C

Page 35: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Limits

• Both Pullbacks and Pushouts are examples of Limits.

• They are restricted products/coproducts

• A +C B is colimit

• A XC B is limit

Page 36: Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk

Further Reading

• Categories for the Working Mathematician

Mac Lane, Saunders

2nd edition

Springer-Verlag 1998.

• Category Theory for Computing Science Barr, Michael & Wells, Charles

1st edition (later editions are available)

Prentice-Hall 1990.