Вы находитесь на странице: 1из 26

Category Theory

Baldur Bl ondal
Chalmers University of Technology

October 31, 2013

Categories, Denition

Category (C ) consists of:

Categories, Denition

Category (C ) consists of:


Objects: A, B , C ... Arrows (morphisms): f , g , h... For each arrow f we write f : A B to indicate that

dom(f ) = A and cod (f )


Composition: For arrows f : A B and g : B C we have

g f :AC
Identity arrow: For each object A we have idA : A A.

Laws of Categories

Such that:
Composition is Associative: h (g f ) = (h g ) f . id is Unit: Given f : A B , f idA = f = idB f .

Quick Comment!

Objects need not be sets, arrows need not be functions.

Category Sets

First category is Sets of sets and functions. Another category of Sets n of nite sets and functions between them. Also categories of structured sets:
Groups (objects) and group homomorphisms (arrows). Real numbers R (objects) and continuous functions R R

(arrows).
Posets (objects) and monotone functions (arrows). ...

Bunch of examples! Well cover them in more detail later.

Partial Order
A set A has partial order if there is a binary relation a1 that for all a1 , a2 , a3 A:
a1 a1 a1
A A A A

a2 such

a2 (reexivity) a2 , a2 a2 , a2
A A

a3 a1

a1

a3 (transitivity)

a1 = a2 (anti-symmetry)

Example
The real numbers R form a poset with the usual n1 a total order which is partial order plus totality). n2 (actually

Category of partially ordered sets Pos where objects are posets and arrows are monotone functions m : A B such that: a1
A

a2 implies m a1

m a2

(1)

Why is Pos a category?


Objects Objects are partially-ordered sets. Arrows Monotone functions. Typing f : A B from poset A to poset B . Composition If f : A B and g : B C are monotone, then g f : A C is monotone: a1 or (g f ) a1
A A

a2 = f a1

f a2 = g (f a1 ) (g f ) a2

g (f a2 )

Identity idA : A A is monotone: a1


A

a2 = idA a1

idA a2

Observation

Note about Category Theory


Category theory is all about doing without elements! We focus on relationships between things rather than the things themselves (like in set theory). Its the arrows that matter!

Sets and relations between them


YAC (Yet Another Category) Rel where objects are sets and arrows are binary relations (not traditional functions): Objects Sets. Arrows Binary relations between sets. Typing f : A B is an arbitrary subset f A B Composition Given relations R : A B and S : B C (R A B and S B C ) we dene (a, c ) S R if there exists some b such that (a, b ) R and (b , c ) S . Identity idA = {(a, a) A A|a A} A A Verify laws!

Quick Crazy Example

Another example where the arrows are not functions: Objects Finite sets A, B , C , . . . Arrows Arrow F : A B is a a b matrix where a and b are the number of elements of the sets A and B . Composition Normal matrix multiplication. Identity Unit matrix.

Functors
A functor is a mapping between categories (remember that I said that mappings were important): F :CD

Denition: Functor
A mapping between categories C and D maps objects in C to objects in D and arrows in C to arrows in D: 1. For each object X in C we have F X in D. 2. For each f : A B in C we have F f : F A F B in D such that:
2.1 F idA = idFA 2.2 F (g f ) = F f F g

Functor F preserves domains, codomains, identity arrows and composition.

Category Cat

The functor F : C D gives a sort of picture of C in D but functors also compose and have an identity: idC : C C so guess what: we have a category Cat category of all categories where functors are arrows!

Preorders

A preorder is a set P with a binary relation that is reexive and transitive, any preorder is a category as such: Objects Elements of P . Arrows Relations on the elements of P . Typing f : a b if and only if a Composition Guess! Identity Since a a. is reexive we have idA : a a since b.

Category of Proofs, Computer Science

Category of Proofs
Objects are formul (, , . . . ) and arrows from to is a deduction of from assumption . There is also an important category that well consider quite a bit later on (we will call it Hask):

Category of Functional Programming Languages


Objects are types of a language (Int, Bool, . . . ) and arrows are computable functions between types (isFive :: Int -> Bool).

Monoids
Monoids are just categories with a single object and the arrows of the category are the elements of the monoid. Composition is the binary operation of the monoid.

Example
N, Q and Q with addition and 0 or multiplication and 1. For any set X the set of functions from X to X (HomSets (X , X )) is a monoid under composition. More generally: Any object C from any category C , arrows from C to C (HomC (C , C )) is a monoid under C . Lists under (++) and many other programming concepts (go through Data.Monoid and Control.Monoad.Writer).

Category Mon
1. Monoids are structured sets and there is a category Mon whose objects are monoids and whose arrows are functions that preserve the monoid structure. 2. A homomorphism from a monoid M to a monoid N is a function h : M N such that h (m M n) = h m N h n and h u M = uN . 3. NOTA BENE: A monoid homomorphism from M to N is the same thing as a functor from M to N (when regarded as categories). 4. In that sense: Categories generalize monoids, functors generalize homomorphisms.

Isomorphism
For a category C f : A B is an isomorphism if there exists an arrow g : B A in C such that: g f = idA and f g = idB i.e. we can go back and forth without losing any information. Isomorphisms are unique so we write g = f 1 and say that A is isomorphic to B (A = B ). This denition is our rst example of an abstract, category theoretic denition of an important notion: it doesnt consider additional information about the objects and arrows and is valid for any category!

Groups
Denition: Group
A group G is a monoid with an inverse g 1 for every element g . G is a category with a single object where every arrow is an isomorphism.

Example
The natural numbers dont form a group under either addition or multiplication but integers Z and positive rationals Q+ do.

Example
For any set X we have a group Aut (X ) of automorphisms/permutations of X (isomorphisms from an object to itself: f : X X while preserving all of its structure). automorphism = endomorphism + isomorphism

Constructing New Categories: Products


Product of C and D is C D with objects of the form: (C , D ) for C C , D D And arrows of the form: (f , g ) : (C , D ) (C , D ) for f : C C C and g : D D D where composition and units are dened componentwise: (f , g ) (f , g ) = (f f , g g ) and
def def

id(C ,D ) = (idC , idD )

Constructing New Categories: Products


With two functors 1 and 2 : 1 : C D C 1 (C , D ) = C 1 : ((C , D ) (C , D )) C C 1 (f , g ) = f and 2 : C D D 2 (C , D ) = D ...
def def def

Constructing New Categories: Duals

The opposite or dual category C op which has the same objects as category C and an arrow f : C D in C op for every f : D C in C. We will write arrow f : D C in C op to distinguish from f : C D in C and procede to dene composition and units in C op using the corresponding operations in C : idC = (idC ) f g = (g f )
def def

Constructing New Categories: Arrow Category


The arrow category C of C : Objects Arrows of C . Arrows Arrow g = (g1 , g2 ) from f : A B to f : A B such that g2 f = f g1 . Typing g : (A B ) (A B ). Composition Composition done componentwise: h g = (h1 , h2 ) (g1 , g2 ) = (h1 g1 , h2 g2 ). Identity idf on an object f : A B is the pair (idA , idB ). Should we try to draw the commutative diagram? There are also two functors dom : C C and cod : C C .

Constructing New Categories: Slice Category

A slice category C /C of a category C over an object C C . Objects All arrows f C such that cod f = C . Arrows Arrow a : X X . Typing Arrow a is from f : X C to f : X C such that f a =f. Composition Same as C . Identity Same as C . Then there is a functor U : C /C C that forgets about base object C .

Title

Title

Вам также может понравиться