380 likes | 408 Views
Lecture 2: Introduction to Category Theory. Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk http://www.cs.ncl.ac.uk/people/b.n.rossiter/. Features of Interoperability. Complex mappings from user views to way data is held
E N D
Lecture 2: Introduction to Category Theory Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk http://www.cs.ncl.ac.uk/people/b.n.rossiter/
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
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
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”
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)
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
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
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)
Discrete Categories • Every arrow is an identity arrow e.g. a a, b b, c c • Discrete categories are sets (without functions)
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
Simple Categories 2 • 2 Category with two objects and one arrow which is not an identity e.g. a, b a b
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
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
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
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
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
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: Pos2 Pos1; Pos1 Pos2
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
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.
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.
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.
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
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;
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
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
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
Relationships -- Pullbacks • Notion of subproduct • Relation of two objects in context of a third • Restriction of universal product • Pullback of one arrow over another
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
Pullbacks - More Arrows 1 A pil pi*l f Delta A XC B C pi*r pir g B
Pullback - More Arrows 2 A pil pi*l f Coprod A XC B Delta C pi*r Prod pir g B
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
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
Coproducts (Sums) A+B il d ir A U B f g Equations il o f = d = ir o g U is universal object
Restricted Coproduct • Pushout A f il C A +C B g ir B Restriction over object C
Limits • Both Pullbacks and Pushouts are examples of Limits. • They are restricted products/coproducts • A +C B is colimit • A XC B is limit
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.