Sei sulla pagina 1di 53

Category Theory Background

and Introduction to Coalgebra


MATHLOGAPS 2008: Coalgebra and Circularity

August 2008

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

My goals for this part of the course

At this point, we have seen examples of circularly-defined sets such


as
the set of streams
the set of infinite trees
One of the main goals of the course is to present a theory of
how these solution spaces work.
The theory is based on the concept of a coalgebra for a functor
and on similar notions from category theory.
This part of the course is a quick introduction to a few of the
concepts which well need.
It is not a systematic presentation of the subject.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Categories
A category C consists of
1

objects c, d, . . .

morphisms f , g , . . ..
Each morphism has a domain and codomain.
f : c d means that c is the domain of f ,
and d is the codomain.

identity morphisms id a for all objects.

a composition operation:
if f : a b and g : b c, then g f : a c.

subject to the requirements that


Composition is associative.
If f : a b, then id b f = f = f id a .

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Examples of Categories

We continue with several examples of categories including


the category Set of sets.
the category CMS of complete metric spaces.
Of course, well see constructions of new categories from old
at several places as well.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

The category Set

The objects of Set are the sets, and the morphisms


are triples hx, y , f i where f : x y .
The domain of hx, y , f i is x, and the codomain is y .
The identity morphism id a for a set a is ha, a, f i, where f is the
identity function on a.
The composition operation of morphisms is given by:
hy , z, g i hx, y , f i = hx, z, g f i

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

The category Set

The objects of Set are the sets, and the morphisms


are triples hx, y , f i where f : x y .
The domain of hx, y , f i is x, and the codomain is y .
The identity morphism id a for a set a is ha, a, f i, where f is the
identity function on a.
The composition operation of morphisms is given by:
hy , z, g i hx, y , f i = hx, z, g f i
An alternative presentation of the category of sets would take as
morphism the pairs hy , f i with y {a : (b)hb, ai f }.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

The category CMS

This is the category of complete metric spaces,


with distances measured in [0, 1],
and with non-expanding functions as morphisms:
d(x, y ) d(fx, fy ).
One reason for the use of [0, 1] is that this way the homsets
CMS(X , Y )

{f : f is a continuous function from X to Y }

are again objects in the category, with


d(f , g )

sup dY (f (x), g (x)).


xX

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Functors

Let C and D be categories.


A functor from C to D consists of
An object mapping a 7 Fa, taking objects of C to
objects of D.
A morphism mapping f 7 Ff , taking morphisms of
C to morphisms of D.
such that
If f : a b, then Ff : Fa Fb.
F id a = id Fa .
F (f g ) = Ff Fg .
A functor from C to itself is an endofunctor.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

The easiest examples

Let d be an object of D.
We get F : C D, the constant functor d by:
Fc = d,
Ff = id d .

The composition of functors is again a functor.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Endofunctors on Set related to our examples


of systems
Let A be a fixed set.
Then we get a functor Fy = A y by using the cartesian product
for the object part, and
if f : y z, then Ff : A y A z is given by
Ff (ha, xi)

ha, fxi.

Another way to say this:


Ff (w )

hfst(w ), f (snd(w )i.

Ill omit the verification that this actually is a functor.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Stream systems and their solutions


Let FX = N X .
Stream systems are coalgebras of F , maps of the form e : X FX .
Even more, the solution e : X N would be a coalgebra
morphism:
X
e

/ FX

id

Fe

/ FN

The point is that for x X ,


Fe (e(x)) = Fe hfst(e(x)), snd(e(x))i
= hfst(e(x)), e (snd(e(x)))i
We have seen this formulation before.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

The power set endofunctor P

For any set X , PX is the set of subsets of X .


P extends to an endofunctor, taking
f :X Y
to
Pf : PX PY
given by direct images: for a X , Pf (a) = f [a] = {f (x) : x a}.
We similarly have functors such as the finite power set functor Pfin .

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Set systems and their solutions


Let FX = PX .
Set systems are coalgebras of F , maps of the form e : X PX .
Even more, the solution e : X V is practically a coalgebra
morphism:
e

X
e

/ PX

id

Pe

/ PV

The point is that for x X ,


Pe (e(x)) = e [e(x)]
= {e (a) : a e(x)}
So e satisfies the equation we saw before.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Signature Functors

A signature is set of function symbols with arities.


Each gives us H : Set Set by
H (X )
for g : X Y
H g (hf , x1 , . . . , xn i)

{hf , x1 , . . . , xn i : arity (f ) = n; x X }

hf , g (x1 ), . . . , g (xn )i

So H (X ) is like the one-level trees,


allowing elements of X to appear on the leaves.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Signature Functors

A signature is set of function symbols with arities.


Each gives us H : Set Set by
H (X )
for g : X Y
H g (hf , x1 , . . . , xn i)

{hf , x1 , . . . , xn i : arity (f ) = n; x X }

hf , g (x1 ), . . . , g (xn )i

Example: has a binary symbol and a 0-ary e.


H ({x, y }) = {hei, h, x, xi, h, x, y i, h, y , xi, h, y , y i}.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Signature Functors
A signature is set of function symbols with arities.
Each gives us H : Set Set by
H (X )
for g : X Y
H g (hf , x1 , . . . , xn i)

{hf , x1 , . . . , xn i : arity (f ) = n; x X }

hf , g (x1 ), . . . , g (xn )i

The point is that now tree systems and solutions are represented:
X
e

Tr

/ H X

id

MATHLOGAPS 2008: Coalgebra and Circularity

H e

/ H (Tr )

Category Theory Background

The discrete measure functor D

A discrete measure on a set A is a function : A [0, 1] such


that
1
2

has finite support: {a A | (a) > 0} is finite.


P
aA (a) = 1.

D(A) is the set of discrete measures on A.


We make D into a functor by setting,
for f : P
A B, Df ()(b) = (f 1 (b));
this is {(a) : f (a) = b}.
(This extends discrete measures on A to functions on P(A) by
summing.)

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Functions from a fixed set

Let A be a set, and write X A for the functions from A to X .


Let F be defined by FX = X A ,
and for f : X Y , Ff : X A Y A is
??
.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Coproducts
Let C be a category.
A coproduct of objects x and y , is an object x + y
with morphisms inl : x x + y and inr : y x + y meeting the
following condition:
if f : x z and g : y z, then there is a unique
[f , g ] : x + y z such that [f , g ] inl = f and [f , g ] inr = g .
x
inl

[f ,g ]
$
x +O y _ _ _ _ _ _ _ _ _ _ _:/ z
inr

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Coproducts
Let C be a category.
A coproduct of objects x and y , is an object x + y
with morphisms inl : x x + y and inr : y x + y meeting the
following condition:
if f : x z and g : y z, then there is a unique
[f , g ] : x + y z such that [f , g ] inl = f and [f , g ] inr = g .
Technically, the coproduct of x and y is the triple (x + y , inl, inr).
Usually theres no need to add the names of the objects to the
coproduct maps inl and inr.
But if we would need to, we could write
inla,a+b : a a + b,
and similarly for inrb,a+b .

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Using coproducts
If f : a b and g : c d, then we have
f +g :a+c b+d
given by
f + g = [inl f , inr g ].
In pictures,
a

a+b

/c N
NNN
NNinl
NNN
NNN
'
[inlf ,inrg ]
/c +d
8
ppp
p
p
ppp
ppp inr
p
/d

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Categories with coproducts

C has coproducts if every two objects have a coproduct.


A category with coproducts is a tuple (C , +), where C is a
category and + is a coproduct operation on C , giving for each x
and y the triple (x + y , inlx,x+y , inry ,x+y ).
E.g., (Set, +), where
x +y

(x {0}) (y {1}),

also, inl(a) = (a, 0) for a x, and inr(b) = (b, 1) for b y .

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Coproducts of functors

Let C be a category and (D, +) be a category with coproducts.


If F : C D and G : C D, we define
F +G :C D
by (F + G )a = Fa + Ga,
and if f : a b, then
(F + G )f : Fa + Ga Fb + Gb
is given by
(F + G )f

MATHLOGAPS 2008: Coalgebra and Circularity

Ff + Gf

Category Theory Background

Initial and Final Objects

In a category C , an object c is called initial


if for every object a, there is a unique ! : c a.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Initial and Final Objects

In a category C , an object c is called initial


if for every object a, there is a unique ! : c a.
In Set, is initial.
For every a, the empty function is the unique function from to a.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Initial and Final Objects

In a category C , an object c is called initial


if for every object a, there is a unique ! : c a.

c is terminal, or final
if for every object a, there is a unique ! : a c.
In Set, the final objects are exactly the singletons.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Algebras for a Functor

Let F : C C be a functor.
An algebra for F is a pair (A, a), where a : FA A in C .
The leading example is when F is a signature functor, say F .
Then an F -algebra is a set A together with interpretations of the
symbols in .

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Algebras for a Functor


Let F : C C be a functor.
An algebra for F is a pair (A, a), where a : FA A in C .
The leading example is when F is a signature functor, say F .
Then an F -algebra is a set A together with interpretations of the
symbols in .
Example: has a binary symbol and a 0-ary symbol e.
An algebra as usually presented might have universe {x, y };
interpret e by y , and interpret by

x
y

x
x
y

y
x
x

We would trade all this in for a : H ({x, y }) {x, y }:


a(hei)
= y
a(h, x, xi) = x
a(h, x, y i) = x
MATHLOGAPS 2008: Coalgebra and Circularity

a(h, y , xi) = y
a(h, y , y i) = x
Category Theory Background

Algebras for a Functor

Let F : C C be a functor.
An algebra for F is a pair (A, a), where a : FA A in C .
The leading example is when F is a signature functor, say F .
A morphism from (A, a) to (B, b) is h : A B such that
FA
Fh

/A

FB

/B

commutes.
This gives a category of F -algebras.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Initial algebras
Lets return to with and e, and its associated H : Set Set.
Let T0 be the set of finite trees (=terms) on the signature.
So T0 contains e, (e, e), ((e, e), e), etc.
We have
i

H(T0 )
c

T0

For example, i(h, (e, e), ei) = ((e, e), e).


Then (T0 , i) is an initial algebra of H.
For any (A, a), the unique H-algebra morphism
from the term algebra (T0 , i) to (A, a)
is evaluation of terms  : T0 A.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

an initial algebra of another functor


Consider now Pfin on Set.
Then V = Pfin V is the set of hereditarily finite sets.
(V , id) is an initial algebra of Pfin .
That is, given (A, a : Pfin A A), we need a unique h : V A
such that
id /
Pfin V
V
Pfin h

Pfin A

/A

We get h by -recursion, and the formula is


h(x) =

MATHLOGAPS 2008: Coalgebra and Circularity

??

Category Theory Background

an initial algebra of another functor


Consider now Pfin on Set.
Then V = Pfin V is the set of hereditarily finite sets.
(V , id) is an initial algebra of Pfin .
That is, given (A, a : Pfin A A), we need a unique h : V A
such that
id /
Pfin V
V
Pfin h

Pfin A

/A

We get h by -recursion, and the formula is


h(x)

a(Pfin h(x))

MATHLOGAPS 2008: Coalgebra and Circularity

a({h(y ) : y x}).

Category Theory Background

Coalgebras for a Functor

Let F : C C be a functor.
A coalgebra for F is a pair (A, a), where a : A FA in C .
Well shortly see many examples.
A morphism from (A, a) to (B, b) is h : A B such that
A
h

/ FA

Fh

/ FB

commutes.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Why are we studying coalgebras?

stream systems are


coalgebras for FX = N X
tree systems are
coalgebras for FX = H X , where is x, y , ,
set systems (= graphs) are
coalgebra for FX = PX
Solutions are coalgebra morphisms into final coalgebras.
Next time well see a result that gives us final coalgebras in all
cases except PX
(but it works for Pfin X ).

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Why are we studying coalgebras?


stream systems are
coalgebras for FX = N X
tree systems are
coalgebras for FX = H X , where is x, y , ,
set systems (= graphs) are
coalgebra for FX = PX
Solutions are coalgebra morphisms into final coalgebras.
Next time well see a result that gives us final coalgebras in all
cases except PX
(but it works for Pfin X ).
belief spaces are
coalgebras for FX = ([0, 1] X ) on Meas

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Automata and languages


Let A = {a, b, c} be a set which we think of as alphabet symbols,
and consider the functor FX = X A 2, where 2 = {0, 1}.
A coalgebra for this F is a re-packaged version of a deterministic
automaton.
a,b

a,c


9y

xM m
b

b,c

ze

Here S = {x, y , z}, and e : S FS is


e(x)
e(y )
e(z)

=
=
=

h{ha, xi, hb, xi, hc, y i}, 0i


h{ha, y i, hb, xi, hc, y i}, 1i y is accepting
h{ha, zi, hb, xi, hc, xi}, 0i

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Automata and languages


a,b


9y

xM m

b,c

ze a
Let A be the set of finite words on A, including the empty word .
We define : X A X by recursion:
a,c

(s, )
(s, wi)

=
=

s
fst(e((s, w )))(i)

For example (x, bacabc) = y .


Also, let L be the set P(A ) of languages on A.
We define acc : X L, the language acceptance function by
acc(s)

=
=

{w A : (a, w ) is an accepting state}


{w A : snd((a, w )) = 1}

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

L carries a coalgebra structure


Let l : L F L be given by
l(L)

hi 7 {w : wi L}, 1 iff  Li.

This is the language automaton (L, l).


For example, if
L

{, ab, abab, ababab, abababab, . . .}

then
l(L)

h(a 7 , b 7 {a, aba, ababa, . . .}, c 7 ), 1i

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

L carries a coalgebra structure

Let l : L F L be given by
l(L)

hi 7 {w : wi L}, 1 iff  Li.

This is the language automaton (L, l).


For all languages L and words w A , (L,l) (L, w ) = {v : vw L}.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

L carries a coalgebra structure

Let l : L F L be given by
l(L)

hi 7 {w : wi L}, 1 iff  Li.

This is the language automaton (L, l).


In it,
acc(L,l) (L)

=
=
=
=

{w : (L, w ) is an accepting state}


{w : {v : vw L} contains }
{w : w L}
L

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

The language automaton is a final coalgebra

One first checks that acc is a coalgebra morphism:


S
acc

/ FS

F acc

/ FL

Second, every coalgebra morphism preserves language acceptance.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

The language automaton is a final coalgebra


One first checks that acc is a coalgebra morphism:
e

S
acc

/ FS


F acc

/ FL

Second, every coalgebra morphism preserves language acceptance.


To prove the uniqueness of acc, let : S L be a coalgebra
morphism.
Then for all states s of S,
acc(S,e) (s)

acc(L,l) ((s))

(s).

And this just says that = acc.


MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

The big picture

algebra
initial algebra
least fixed point
congruence relation
Foundation Axiom
iterative conception
equational logic
recursion: map out of
an initial algebra
useful in syntax
construct
bottom-up

coalgebra
final coalgebra
greatest fixed point
bisimulation equivalence relation
Anti-Foundation Axiom
coiterative conception
modal logic
corecursion: map into
a final coalgebra
useful in semantics
observe
top-down

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Lambeks Lemma

Lemma (Lambeks Lemma)


Let C be a category, let F : C C be a functor,
and let (a, f ) be an initial algebra for F .
Then f is an isomorphism:
there is a morphism g : Fa a such that
g f = id a and f g = id Fa .
The same statement holds for final coalgebras of F .

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Proof of Lambeks Lemma


Note first that (Fa, Ff ) is an algebra for F . The square below
commutes:
Ff /
FFa
Fa
Ff

Fa

/a

By initiality, there is a morphism g : a Fa so that the square on


the top commutes:
Fa
Fg

FFa
Ff

Ff

Fa

/a
g

/ Fa


/a

The bottom is obvious, the outside of the figure thus commutes.


MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Proof of Lambeks Lemma, continued


By initiality, there is a morphism g : a Fa so that the square on
the top commutes:
Fa
Fg
F (f g )

FFa
Ff

/a

Ff

/ Fa

f g

Fa


/a}

By initiality, we see that f g = id a .


And then from that top square again,
g f = Ff Fg = F (f g ) = F id a = id Fa .
This completes the proof.
MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

There are no initial algebras or final


coalgebras of P
An isomorphism in Set is a bijection.
And there are no maps from any set onto its power set (Cantors
Theorem).
Together with Lambeks Lemma, we see that P on Set has no
initial algebra and no final coalgebra.
To get around this, one either
1
2

moves from Set to the category Class.


moves from P to P , the functor giving the subsets of a set of
size < .

Well generally go the second route, and in particular consider Pfin .


It turns out that (H , id) is an initial algebra of P .
Well see the final coalgebra later.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Natural transformations
Let F : C D be a functor between two categories,
and let G : C D also be a functor between the same two.
Then a natural transformation from F to G is a family
of morphisms of D indexed by objects of C , in particular each x
is a morphism in D from Fx to Gx.
The requirement on is that for each morphism in C of the form
f : x y , the square below commutes:
x


Fx
f

Ff

Fy

/ Gx


Gf

/ Gy

In symbols, Gf x = y Ff .
One writes : F G .
For each object x of C , x is called the component of at x.
MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Constructions on natural transformations


Suppose first that : F G , and let H : B C be another
functor.
Then F H : B D and G H : B D.
We get a natural transformation called H from F H to G H by
H b

Hb .

Now let H : D E . So now H F and H G are functors from C


to E .
We get a natural transformation from H F to H G , this time
called H, by
(H)x = Hx .
That is, we apply the functor H to the morphism x . The
verification of naturality is a little different: we apply H
throughout.
MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Constructions on natural transformations


Suppose first that : F G , and let H : B C be another
functor.
Then F H : B D and G H : B D.
We get a natural transformation called H from F H to G H by
H b

Hb .

To check that this is indeed natural, let f : x y be a morphism


in B. Then for each x in B (H)x : (F H)x G H)x. And we
have the diagram
(F H)x
(F H)f

(H)x

(F H)y

/ (G H)x


(H)y

(G H)f

/ (G H)y

This is literally the same as


F (Hx)
MATHLOGAPS 2008: Coalgebra and Circularity

Hx

/ G (Hx)
Category Theory Background

Constructions on natural transformations


If : F G and : F H, then we get a natural
transformation : F H by ( )x = x x . The
verification of naturality is easy.
Finally, suppose that F , G : D E and H, K : C D, and let
: F G and : H K . We get a natural transformation
: F H K G by
F

F HII
II

G H

/F K

II
G

II$ 
/G K

That is, we claim that the outside of the figure commutes, and
then we define to be the composite in either direction; this
will be a natural transformation by the three constructions which
we have already seen. But for each object x of C the square above
is a naturality square for , applied to the morphsim

x : Hx Kx.
MATHLOGAPS 2008: Coalgebra and Circularity
Category Theory Background

Functors preserving (weak) pullbacks

Definition
A functor F : C D preserves pullbacks if the image of every
pullback square is a pullback square.
Lemma
Concerning preservation of pullbacks:
1

Constant functors preserve pullbacks.

If F and G preserve pullbacks, so do F + G , F G , and F G .

P, Pfin , and D do not preserve pullbacks.

MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Set-functors and surjective maps


Lemma
Every functor F on Set preserves all surjective maps.
Proof.
Suppose g : X Y is surjective.
Let h : Y X be such that g h = id Y .
Then Fg Fh = id FY , and so Fg must be surjective.
Proposition
If FX = for some X 6= , then F is the constant functor .
Proof.
Let Y be any set. Then there is f : Y X ; f could be a
constant, for example. And now Ff : FY . So FY must be
empty also, since there are no maps from a non-empty set to .
MATHLOGAPS 2008: Coalgebra and Circularity

Category Theory Background

Potrebbero piacerti anche