35
Category Theory and Diagrammatic Modelling Uwe Wolter, Department of Informatics, University of Bergen, Norway February 9, 2011

Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

Category Theory and

Diagrammatic Modelling

Uwe Wolter, Department of Informatics, University of Bergen, Norway

February 9, 2011

Page 2: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

2

Page 3: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

Contents

1 Graphs, Categories, Functors 51.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.2 Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.3 Graph homomorphisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.4 Composition and identities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.5 Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.6 Monoids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151.7 Functors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171.8 Categories of categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2 A first taste of (meta)modelling 212.1 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222.2 Typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252.3 Indexed and typed sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3 Universal properties and constructions 273.1 Special morhisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

3.1.1 Monomorphisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273.1.2 Epimorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

4 (Meta)models 29

5 Rest from 2008 315.1 Lecture 23.01.2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

5.1.1 Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315.1.2 Graph Homomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315.1.3 Opposite graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

5.2 Lecture 30.01.2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.2.1 Paths in a graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.2.2 Category . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

5.3 Lecture 04.02.2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.3.1 More Examples of Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.3.2 Diagrams and commutative diagrams . . . . . . . . . . . . . . . . . . . . . . . . . 32

5.4 Lecture 06.02.2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.4.1 Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.4.2 Monomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

5.5 Lecture 11.02.2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.5.1 Epimorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.5.2 Split epimorphisms and split monomorphisms . . . . . . . . . . . . . . . . . . . . . 335.5.3 Opposite Category . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

3

Page 4: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

4 CONTENTS

5.5.4 Subcategories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.6 Lecture 13.02.2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

5.6.1 Slice Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.6.2 Initial objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

5.7 Lecture 18.02.2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.7.1 Terminal Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.7.2 Sums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

5.8 Lecture 20.02.2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345.8.1 Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345.8.2 Pushouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

5.9 Lecture 25.02.2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355.9.1 Pushouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355.9.2 Pullbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Page 5: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

Chapter 1

Graphs, Categories, Functors

1.1 Introduction

What “universal formalisms” do we have available?

→ set theory, logic, Universal Algebra, type theory . . .

Taking into account the “dialectic” between notation and content we may ask

What symbols these formalisms are based on or all about, respectively?

• Set theory is based on the “element relation” ∈.

• What ever logic you consider, at the end, logic is always about a logical entailment relation `.

• Universal Algebra is mainly reasoning about equality =.

• Type theory provides us with different sophisticated systems of types and the basic relation thereis the “typing relation” o : t.

It is historically interesting that only in the early 40’s the arrow notation f : A → B for functions hasbeen introduced and nearly immediately after Category Theory appeared as a universal formalism basedon the symbol→. In view of this Category Theory (CT) could be described/characterized in differentways:

1. A universal language and formalism based on the symbol “→”

2. The mathematics/theory of the “→”-notation

3. The study of just another abstract mathematical structure (in the tradition of Emmy Noether)like group, monoid, lattice, vector space, partial order, . . .

4. An alternative foundation of mathematics (topos theory).

In the course we will focus on the aspects 1 and 2!

Any of the “universal formalisms”, mentioned above can be strongly related to CT and, in fact, there isa categorical variant/counterpart for each of them — topos theory, categorical logic, categorical algebra,. . .

5

Page 6: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

6 CHAPTER 1. GRAPHS, CATEGORIES, FUNCTORS

A shift of paradigm

Moving from set theory to category theory means a complete shift of paradigm and, especially, a com-pletely new way of thinking and reasoning. In set theory we describe/construct the objects of interestby describing and accessing their elements/parts. That is, set theory is based on the element relation ∈,and any other relations and constructions of interest are described by means of this relation (and somefirst order logic). The subset relation, for example, is defined by

A ⊆ B iff a ∈ A implies b ∈ A for all a ∈ A

Category theory, in contrast, is based on the following viewpoint and level of abstraction:

• There are objects of interest and directed relations (arrows) between these objects.

• There is no possibility to look “inside” the objects, i.e., objects are considered as “black boxes”.

• The only chance to find something out about an object of interest is to study the relations goinginto this object and going out, respectively. That is, an object is described/characterized by itsrelations to other objects, i.e., by its “social life”. (later reference to Girard).

• This means also, especially, that the properties of an object, we are able to recognize, depend on thecontext and may change if we change the context, i.e., the net of relations the object is embeddedin.

Methodological remark: I’ll try to save the term ”arrow” for informal discussions.I’ll try to illustrate the shift of paradigm by an example. The basic and important concept of theCartesian Product1 of two sets A and B is defined in set theory by the following concrete construction:

A×B = {(a, b) | a ∈ A, b ∈ B}

Due to the categorical imperative we can not give a concrete construction of the Cartesian Product incategory theory, but we can try to describe/characterize it “implementation independent, i.e., “up toisomorphism” (we will give later a precise definition of isomorphisms). So, let’s try to analyse the settheoretical construction following the categorical imperative.The first simple, but not trivial, thing we have to bear in mind is that there is not only the CartesianProduct A × B but that the product has been constructed for two given sets A and B. So the firstquestion is: Are there any “directed relations” between these three sets? Since we are dealt with sets onemay ask more specific: Do there exist any maps between these three sets?The answer is: Of course, we have two projection maps πA : A×B → A and πB : A×B → B defined by

πA(a, b)def= a and πB(a, b)

def= b for all (a, b) ∈ A×B (1.1)

The next thing, we have to be aware of, is that the construction of A×B uses only elements provided byA and B, respectively. The next question will be then: How can we formulate this kind of “minimality”in terms of arrows?Let’s consider any other candidate for the Cartesian product, i.e., a set C together with two mapsf : C → A and g : C → B. Any such candidate C is indeed “smaller” than A× B since the “tupling ofmaps” provides us with a map 〈f, g〉 : C → A×B defined by

〈f, g〉(c) def= (f(c), g(c)) for all c ∈ C (1.2)

Note, that “〈f, g〉” doesn’t denote a pair of maps. “〈f, g〉” serves as a “compound name/identifier” forthe new map indicating that this map is uniquely determined by the maps f and g.

1Why it’s called “cartesian”?

Page 7: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

1.1. INTRODUCTION 7

A closer look at the definition of the tupling of maps in (1.2) and of the projection maps in (1.1) makesevident that the definition of the map in (1.2) can be equivalently expressed by the requirement that thetwo triangles in the following diagram commute, i.e., that the composition of 〈f, g〉 with the projectionπA provides f and that the composition of 〈f, g〉 with the projection πB provides g.

Cg

##FFFFFFFFFf

||xxxxxxxxx〈f,g〉

��A A×B

πAoo πB // B

This observation makes our analysis complete and we can formulate the following property of the Cartesianproduct of sets.

Fact 1. For any two sets A and B there exists a set A×B together with two maps πA : A×B → A andπB : A × B → B such that the following ”universal property” is satisfied: For any set C and any mapsf : C → A, g : C → B there exists a map 〈f, g〉 : C → A×B such that the composition of 〈f, g〉 with πAprovides f and the composition of 〈f, g〉 with πB provides g. Moreover, 〈f, g〉 is uniquely determined bythese two conditions.

The crucial point, which makes category theory practically useful, is that the universal property in Fact1 describes the Cartesian product uniquely ”up to isomorphism” and it even allows us to prove a lotof things about Cartesian products without relying on one of the many possible special set-theoreticconstructions or implementations, respectively.2011: Sami asked Adrian ”But one has to provide a construction for the tuple?” — I should underline,when we treat products later, that the condition ”the composition of 〈f, g〉 with πA provides f and thecomposition of 〈f, g〉 with πB provides g” describes actually a concrete construction of the tuple once wehave decided for a concrete construction for the object A × B, that is this condition is, in case of sets,nothing but only a reformulation of the definition/construction in (1.2)!!!

Generalization and Dualization

Besides some insides into the essential properties of Cartesian products, what do we gain by the effort ofmaking a categorical analysis of something we have at hand already and know how to use it?Let’s have a closer look at Fact 1. Nothing there depends really on sets and maps. Actually, we couldtransfer Fact 1, by replacing the word ”set” by ”object and the word ”map” by ”arrow”, into a definitionof product that applies to any situation where we have objects and arrows between them. If we doso later, we will see that things like intersection ∩, conjunction ∧ and many other known or unknownconstruction fit into the product pattern.Moreover, we achieve, in such a way, that everything that can be shown based only on the universalproperty is valid for any possible incarnation of the product pattern. Summarizing one may say that acategorical analysis of something known or something we have done in a certain area pays of by openingfor ”horizontal generalizations”. A categorical analysis will make evident what things in our applicationdomain do have a more general and structural nature and what things are the more specific ones ofour domain. By summarizing the general structural things into a concept/definition we provide thensomething like a ”theory interface” which can hopefully instantiated later also for other special casesand/or in other domains.But, we can do even more! We can play a ”formal game” and ask, for example, what is the dual ofproducts. What does it mean to dualize a statement/definition? In category theory this is easily doneby reversing the direction of arrows. So let’s dualize the statement in Fact 1.

Fact 2. For any two sets A and B there exists a set A?B together with two maps iA : A → A?B andiB : B → A?B such that the following ”universal property” is satisfied: For any set C and any mapsf : A→ C, g : B → C there exists a map k : A?B → C such that the composition of iA with k provides f

Page 8: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

8 CHAPTER 1. GRAPHS, CATEGORIES, FUNCTORS

and the composition of iB with k provides g. Moreover, k is uniquely determined by these two conditions.

AiA //

f ""DDDDDDDD A?B

k

��

BiBoo

g||zzzzzzzz

C

Is this statement true? Have you ever seen a construction satisfying the universal property in Fact 2?. . .Of course there is a well-known construction satisfying this property, namely the disjoint union of sets.Given sets A and B we can define their disjoint union A ]B by

A ]B def= {(a, 1) | a ∈ A} ∪ {(b, 2) | b ∈ B} (1.3)

Note, that using the tags “1” and “2” is only one of the many possibilities to resolve “name clashes”.Another possibility would be to rely on the set identifiers “A” and “B” and to write a : A instead of (a, 1)(or A.a in case you like better the dot-notation used in object-oriented programming and modelling).Tagging the elements in A and B provides the injection maps iA : A → A ] B and iB : B → A ] B,respectively:

iA(a)def= (a, 1) for all a ∈ A and iB(b)

def= (b, 2) for all b ∈ B (1.4)

And given arbitrary maps f : A→ C and g : B → C the condition for the map k : A ]B → C that “thecomposition of iA with k provides f and the composition of iB with k provides g” means nothing but todefine k uniquely by what we usually call a complete case distinction. In analogy to the tupling offunctions I’ll use the notation [f, g] instead of k:

[f, g](x)def=

{f(a), if x = (a, 1)g(b) , if x = (b, 2)

(1.5)

(Maybe mention that the disjoint union appears in imperative programming, for example as “variablerecord” in PASCAL and as “union” in C.)Note, that on a set-theoretic level Cartesian product and disjoint union have nothing to do with each other.Our categorical analysis shows, however, that they present structurally nearly the same constructionpattern, only distinguished by the small detail what direction for the arrows we chose/consider. Laterwe will call the “disjoint union pattern” for sum or coproduct, respectively. And, as you may expect, wewill see then that things like union ∪, disjunction ∨ and many other known or unknown construction willfit into the sum pattern.The nice thing is that any statement about products and any construction based on products can bedualized to a statement about sums and a construction on sums, respectively. Especially, there is no needto dualize proofs, even if this is very instructive at many occasions.

1.2 Graphs

The title of the course is “Category Theory and Diagrammatic Modelling”. To what kinds of “diagram”I refer in the title?

• Not things like bar diagram, pie chart, fever chart, . . .

• But, things like plans of public traffic, Petri nets, class diagrams, ER diagrams, inheritance dia-grams, data flow diagrams, finite state machines, state charts, . . .

Let’s have a look at some examples . . . What do have all these “diagrams” in common? What is thecommon underlying structure?

Page 9: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

1.2. GRAPHS 9

→ (directed) graphs

What is a graph? Have you ever seens a definition of graphs? In textbooks one finds often the followingdefinition: A graph is an ordered pair G = (V,E) comprising a set V of vertices together with a setE ⊆ V × V of edges. Let’s have a closer look at this defintion! Does the graph in Figure 1.1 fits intothis definition? No! There are two parallel edges from 2 to 1 (multiple edge) where the definition above

Figure 1.1: A sample graph

1 2b

vv

a

hhc

((3

d

hh 4eoo fdd

allows only one edge between two vertices. Or, more precise, if we don’t have/allow multi edges thenthere either exists an arrow between two edges or not. And, in case there exists an arrow this arrowis uniquely identified by its source and target, i.e., can be represented by a pair of vertices. In case wehave/want to deal with multiple edges it is convenient that edges have their own identity. Therefore wewill work here with the following definition of graphs.

Definition 1 (Graph). A graph G = (G0, G1, scG, tgG) is given by

• a collection G0 of nodes,

• a collection G1 of edges,

• a map scG : G1 → G0 assigning to each edge its source, and

• a map tgG : G1 → G0 assigning to each edge its target.

We usually write f : x→ y or xf→ y to indicate that scG(f) = x and tgG(f) = y.

Remark 1 (Simple graphs). Graphs with at most one edge between arbitrary two nodes will be calledsimple graphs. As discussed above, we don’t need for simple graphs extra identifiers for edges. That is,for simple graphs we can assume that G1 ⊆ G0×G0 and that scG and tgG are the corresponding projectionmaps. Note, that those graphs are nothing but just a set together with a binary relation/predicate.

Example 1. The above motivating example in Figure 1.1 in view of Definition 1?

Example 2 (Finite graphs). Finite graphs are often visualized by pictorial diagrams. The graph G withG0 = {K,M,MM}, G1 = {c, b, π1, π2} and scG(c) = K, tgG(c) = M , scG(π1) = scG(π2) = scG(b) =MM , and tgG(π1) = tgG(π2) = tgG(b) = M , for example, can be visualized by the pictorial diagram

Kc // M MM

boo

π1

wwπ2

gg

2011: This is, more or less, the ”signature graph” for monoids. I haven’t presented it in the lecture.

2011: I forgot to stress in the lecture that there is no assumption that G0 and G1 have to be disjoint.That is, graphs like the the following are allowed

1 2

1

yy2

ee

I’ve to come back to this when discussing ”indexed sets” vs. ”typed sets”.

Page 10: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

10 CHAPTER 1. GRAPHS, CATEGORIES, FUNCTORS

Example 3 (Finite state machines). Example is missing!2011: I haven’t presented such an example in the lecture, but may need it later since I want to discuss”synchronization”.

Example 4 (Graph of finite maps). Discuss, that our way to picture finite maps provides also graphsand type an example like in the lecture!

Example 5 (Infinite graphs). Besides finite graphs that we can usually visualize by a picture as in Figure1.1, we may consider infinite graphs. For example we can consider a simple graph with nodes all naturalnumbers and edges given by the successor relation

0 // 1 // 2 // 3 // 4 . . .

Another example for an infinite (simple) graph may be taken from logic: As nodes we consider all propo-sitions for a given set of propositional variables. But, what could be the edges? . . . Edges will be given byan entailment relation ` (no matter how we define this relation). Where could multiple edges come fromin this area? . . . If we want to keep track not only of entailment but of also of proofs.

Remark 2 (Small graphs). There is a small subtlety in Definition 1. Why I’ve been using the word“collection” instead of “set”? To involve not only infinite graphs, as in Example 5, for example, but also“very big” infinite graphs as the graph of all sets and all maps, for example. Graphs G with G0 and G1

sets will be called small graphs.

2011: I would have really liked to include parametrized categories of propositional formulas as a runningexample for ”syntactic categories”, but the students don’t had enough background to understand andappreciate such an example. Therefore, I used examples from logic only in informal discussions.

1.3 Graph homomorphisms

Story of the software engineer whom is getting up in the morning — opens his computer — loads the lastversion G of his graph (software model) — starts to work — commits, at the end of his, a new versionH.Is there anything more to say about G and H besides the fact that H is a newer version than G of thesame software model? There should be a relation between (at least some of) the items/components in Gand H and those point-wise realtions should result in a relation between G and H.What relation if our friend only adds nodes and/or arrows to G? . . .H is an extension of G, or, equiva-lently, G is a part of H.

Definition 2 (Subgraph). A graph G = (G0, G1, scG, tgG) is subgraph of a graph H = (H0, H1, sc

H , tgH),G v H in symbols, iff G0 ⊆ H0, G1 ⊆ H1, and scG(f) = scH(f), tgG(f) = tgH(f) for all f ∈ G1.

Remark 3 (Closeness under operations). A small subtlety which is implicit here: Not any subsets G0 ⊆H0, G1 ⊆ H1 constitute a subgraph of H. Only, in case that the chosen subsets are closed under theoperations in the host structure they will constitute a substructure. That is, in our case we have torequire that scH(f), tgH(f) ∈ G0 for all f ∈ G1.

No we may allow our friend to change also the names of nodes and/or edges and even to identify somenodes and/or edges. . . .

Definition 3 (Graph Homomorphism). A graph homomorphims ϕ : G → H between two graphsG = (G0, G1, sc

G, tgG) and H= (H0, H1, scH , tgH) is given by a pair of maps ϕ0 : G0 → H0 and

ϕ1 : G1 → H1 such that for each arrow f : x → y of G we have ϕ1(f) : ϕ0(x) → ϕ0(y) in H, i.e., wehave scH(ϕ1(f)) = ϕ0(scG(f)) and tgH(ϕ1(f)) = ϕ0(tgG(f)) for all f ∈ G1.

Page 11: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

1.4. COMPOSITION AND IDENTITIES 11

Remark 4 (Inclusion homomorphism). Note, that the concept ”graph homomorphism” subsumes theconcept ”subgraph” in the sense, that G v H iff the inclusion maps ini : Gi ↪→ Hi, i = 0, 1 define a graphhomomorphism in = (in0, in1) : G ↪→ H.

Methodological remark: Later, we may discuss what relations we get if our friend is also allowed to deletenodes and/or edges.

Example 6 (Graph homomorphisms). We denote the graph visualized in Figure 1.1 by G and considerthe following graph H:

i iiαoo β // iii iv

γoo

Is there a graph homomorphism from H into G? — discussion that not only embeddings (injectivehomomorphism), but that we could also identify nodes and edges — in the extreme case we can mapeverything to the “loop” f .Is there a graph homomorphism the other way around? — No! Due to the homomorphism conditionloops have to be mapped to loops and there is no loop in G. What if we remove the loop f?

We have discussed already that dualization in category theory can be obtained by reversing the directionof arrows. So, how can we describe this in a formal way? — We just change the role of the sourse andthe target map.

Definition 4 (Opposite graph). The opposite graph of a graph G = (G0, G1, scG, tgG) is given by the

graph Gopdef= (G0, G1, tg

G, scG), i.e., we have Gop0 = G0, Gop1 = G1, scGop

= tgG, and tgGop

= scG.

Methodological remark: I’couldn’t find a nice “practical” motivation/example for contra-variant graphhomomorphisms. Since I don’t present/discuss anymore inheritance explicitly I lost my ”standard moti-vation” from the last years.

1.4 Composition and identities

In the introduction we have been already referred to the composition of maps. But, let’s have look atanother motivating situation.What can we say about the graph G presented in Figure 1.1 and the following graph K?

???

Both graphs are the same ”up to renaming” (and, of course, up to layout details from which we abstractanyway). How can we formalize that the two graphs are the same ”up to renamimg”? We could say, inmore technical terms, that the renaming given by the assignments (1 7→ . . .) provides an ”isomorphism”between G and K.Thus we come to the motivating question: What is an isomorphism between graphs? The traditionalset-theoretical answer is, that an isomorphism is a graph homomorphism ϕ : G → K where both mapsϕ0 : G0 → K0 and ϕ1 : G1 → K1 are bijective.This definition is fine and works but refers to single elements and can, therefore not generalized toarbitrary structures and situations. The are, for example, structures like ”partial algebras” or ”partialorders” where bijectivity is not strong enough to define isomorphisms. So let’s attack the following task:Define the concept of isomorphism in an element-free, universal manner that applies to any structure orsituation!What is the ”nature” of renaming? What is one of the most important features in an editor tool? We canmake an ”undo”! In our example above, we can undo the renaming (1 7→ . . .) by applying the ”inverserenaming” (. . .) thus we and up with the identical renaming (1 7→ . . .). Moreover, if we compose bothrenaming in the reverse order we will get the identity on K.So, to define a universal concept of isomorphism have to clarify first the concepts ”composition” and”identity”

Page 12: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

12 CHAPTER 1. GRAPHS, CATEGORIES, FUNCTORS

Composition of maps

Remark: I’m aware that the abstraction step to consider maps as entities for its own and not only assomething that can be applied to an input and provides an output, maybe already difficult for somestudents. But, please keep in mind that ”pipelines” in Unix-like operating systems are just about this,i.e., the special character ”|” denotes composition of programs as in the simple example “ls -l | less”.Some nice pictures of finite functions and their composition like in Lawveres book pages 14-16

Definition 5 (Composition of maps). The composition f ; g : A → C of two maps f : A → B andg : B → C is defined by the consecutive application of the maps:

f ; g(a)def= g(f(a)) for all a ∈ A.

remark about ”diagrammatic order” vs. ”application order” (maybe mention polish postfix notation)What are identity maps?

Definition 6 (Identity map). For any set A the corresponding identity map idA : A→ A is defined by

idA(a)def= a for all a ∈ A.

What are the properties of composition and identities?composition is associative — make a short proof and argue that this is only a reflection of the fact thatfunction application is actually left associativeidentities are the neutral entities w.r.t. composition — short proof

1.5 Categories

Since, a situation as for sets — objects, arrows, composition, identities, associativity, neutrality — appearsat many places someone decided, one day in the past, to coin the concept of a category.

Definition 7 (Category). A category C is given by

• a graph gr(C) = (C0,C1, scC, tgC), where the nodes (rep. edges) of gr(C) are also called objects

(rep. morphisms) of C.

• a partial composition operation ; : C1×C1 ◦−→C1 assigning to each pair of morphisms f : x→ y,g : y → z a composite morphism f ; g : x→ z.

• a map idC : C0 → C1 assigning to each object x an identity morphisms idCx : x→ x.

Moreover, the following laws are satisfied:

ID If xf→ y then idCx; f = f and f ; idCy = f .

ASS If xf→ y

g→ zh→ u then (f ; g);h = f ; (g;h).

Some comments on the definition of categories:Diagram?

• Remark that composition is indeed partial since two morphisms f and g can be only composed ifftgC(f) = scC(g).

• Remark about the implicit “bookkeeping laws”: scC(f ; g) = scC(f), tgC(f ; g) = tgC(g), scC(idCx) =tgC(idCx) = x

• Remark that it’s usual and more convenient to write idCx instead of idC(x) and that we mostly justwrite idx if the corresponding category is clear from the context, i.e., if it is, especially, determinedby the object x.

Page 13: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

1.5. CATEGORIES 13

• diagram for associativity and remark that associativity means that we can drop parenthesisDiagram?

Our discussion of maps and their composition and identical maps can be summarized now by using thenewly coined concept.

Corollary 1 (Category Set). Sets and maps constitute a category Set: objects: All sets Amorphisms: All maps f : A→ B between sets.composition: The composition f ; g : A → C of two maps f : A → B and g : B → C is defined by:

f ; g(a) = g(f(a)) for all a ∈ A.Identity: For any set A the identity map idA : A→ A is defined by idA(a) = a for all a ∈ A.

And, having the concept of category at hand, we can indeed provide the universal definition of isomor-phisms we have been looking for:

Definition 8 (Isomorphism). A morphism f : x→ y in a category C is an isomorphism iff there existsa morphism g : y → x such that the two equations f ; g = idx and g; f = idy are satisfied.

Remark 5 (Inverse morphism). If such a morphism g : y → x exists this morphism is uniquely deter-mined by f : Let’s assume there is another morphism h : y → x satisfying the two equations. Then weget h = h; idx = h; (f ; g) = (h; f); , g = idy; g = g. Only, after being sure that g is uniquely determinedby f we can call now g the inverse of f and use the notation f−1.

The traditional definition of isomorphic maps as bijections turns now into a characterization of iso’s inthe category Set:

Lemma 1 (Bijective maps). A map f : A→ B is an isomorphism in the category Set iff f is a bijection.

Proof. This we take maybe later as an exercise.

Now we can come back to our motivating example of graphs that are the same “up to renaming”. Sincegraphs and graph homomorphism are defined by means of sets and maps, respectively, we can organizealso graphs into a category:

Definition 9 (Category Graph). Small graphs and the homomorphisms between them constitute a categoryGraph: objects: all small graphs Gmorphisms: all homomorphisms ϕ : G→ H between small graphscomposition: The composition ϕ;ψ : G → K of two graph homomorphisms ϕ = (ϕ0, ϕ1) : G →

H, ψ = (ψ0, ψ1) : H → K is defined componentwise: ϕ;ψdef= (ϕ0;ψ0, ϕ1;ψ1), i.e.,

(ϕ;ψ)0def= ϕ0;ψ0 and (ϕ;ψ)1

def= ϕ1;ψ1.

Identity: For any graph G the identity homomorphism idG : G→ G is given by a pair of identity

maps: idGdef= (idG0

, idG1), i.e., (idG)0

def= idG0

and (idG)1def= idG1

.

Proof. It sounds very strange that we have to give a proof for a definition. This is, however, very often thecase. What we have to prove is that the structure we have defined/constructed has indeed the propertieswe have been claiming in the definition. In our case we would have to show that Graph is indeed acategory, i.e., we have to show the following properties:

• The componentwise composition of two graph homomorphisms provides indeed a graph homomor-phism, i.e., the pair of maps (ϕ0;ψ0, ϕ1;ψ1) preserves sources and targets.

• The pair (idG0 , idG1) of identity maps is indeed a graph homomorphism.

• The composition in Graph satisfies the identity and the associativity law. Since composition andidentities are defined componentwise both laws are inherited from the category Set. It’s worth, thatyou try once to write down the corresponding “pedantic” proof.

Page 14: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

14 CHAPTER 1. GRAPHS, CATEGORIES, FUNCTORS

2011: It turned out that it’s very important to stress that we use the same symbol “;” for compositionin all categories and to ask, again and again, what composition a certain “;” is referring to. In the caseof Definition 9 we have composition in Set and in Graph!

Lemma 2 (Bijective graph homomorphisms). A graph homomorphism ϕ = (ϕ0, ϕ1) : G → H is anisomorphism in the category Graph iff both maps ϕ0 : G0 → H0 and ϕ1 : G1 → H1 are bijections.

Proof. This we take as an exercise later.

Discussion of some finite categories where composition can be represented by a “composition table”. Ipointed out that a drawing of a category as a graph may, in some cases, not provide all the necessaryinformation concerning composition.Of course, we can consider natural numbers not only as a graph as in Example ?? but also as a category:

Example 7 (Category Nat). The category Nat is given by: objects: all natural numbers n ∈ Nmorphisms: there exists an ”unnamed” morphism n→ m in Nat iff n ≤ mcomposition: two morphisms n → m and m → k give rise to a morphism n → k since n ≤ m and

m ≤ k implies n ≤ kidentity: for any natural number we have n→ n since n ≤ n

What other categories with sets as objects, but with other kinds of morphisms instead of maps, may beof interest and practical use for us?

Example 8 (Category Par). A category, very useful in software engineering is the category Par:objects: all sets Amorphisms: all partial maps f : A ◦−→B where we denote the domain of definition of f by

dom(f) ⊆ A.composition: the composition f ; g : A ◦−→C of two partial maps f : A ◦−→B and g : B ◦−→C is defined

by dom(f ; g)def= {a ∈ A | a ∈ dom(f), f(a) ∈ dom(g)} and f ; g(a)

def= g(f(a)) for all

a ∈ dom(f ; g).identity: for any set A the identity idA : A ◦−→A is given by the (total) identity map idA : A→ A.

Example 9 (Category Rel). To formalize things like associations and references, respectively, in object-oriented programming one could use the category Rel of sets and binary relations: objects: all sets Amorphisms: a morphism R : A→ B in Rel is given by a (binary) relation R ⊆ A×B.composition: The composition R;Q : A→ C of two relations R : A→ B, Q : B → C is given by the

relation R;Q ⊆ A× C where

R;Qdef= {(a, c) ∈ A× C | ∃b ∈ B : (a, b) ∈ R ∧ (b, c) ∈ Q}

iden-

tity: For any set A the identity idRelA : A → A is given by the so-called diagonal relation ∆Adef=

{(a, a) | a ∈ A}.

2011: Students had no idea about composition of relations and I’d really to spent some time on it!Especially, I’d to draw some nice picture to illustrate composition of finite relations.

Example 10 (Category Mult). Another equivalent, but more appropriate and convenient, category fortalking about associations and references is the category Mult of sets and multi functions:objects: all sets Amorphisms: a morphism f : A→ B in Mult is given by a map dfe : A→ ℘(B) in Setcomposition: The composition f ; g : A→ C of two morphisms f : A→ B, g : B → C in Mult is given

by the map df ; ge : A→ ℘(C) in Set with

df ; ge(a)def=⋃{dge(b) | b ∈ dfe(a)} = {c ∈ C | ∃b ∈ B : c ∈ dge(b) ∧ b ∈ dfe(a)}

identity: For any set A the identity idMultA : A→ A is given by the map didAe : A→ ℘(A) in Set with

didAe(a)def= {a} for all a ∈ A.

Page 15: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

1.6. MONOIDS 15

2011: Brigita asked about the meaning of the strange brackets d..e: I just wanted to make explicit thedifference between an ”abstract/symbolic arrow” and its ”concrete realization/implementation”. Here, amulti-function from a set A into the power set ℘(B) establishes an ”abstract arrow” from the object A tothe object B in the category Mult. We will meet this difference between ”abstract arrow” and ”concreterealization” again and again. I decided for the notation d..e since other possibilities, like f , f̂ , f∗, . . . ,are saved for other purposes or have a kind of ”standard meaning”, like the ”Kleene star” f∗.Fabian pointed out later that those brackets are used to denote the ”greatest integer less or equal to agiven real number”.Maps can be seen as special relations or multi functions, respectively. (Later we will make this statementmore precise and may prove it.) In other situations it may be useful to restrict the collection of morphismsinstead of extending it. We could, for example, restrict our attention to inclusions only.

Example 11 (Category Incl). The category Incl of sets and inclusions is given by:objects: all sets Amorphisms: all inclusions A ⊆ B between setscomposition: any two inclusions A ⊆ B and B ⊆ C give rise to an inclusion A ⊆ Cidentity: for any set A we have A ⊆ A

Methodological remark: I forgot to introduce here power sets ℘(A) with set inclusion as categories.Maybe, it will be enough to have the category Incl at hand?What is special with the categories Incl and Prop? — There is at most one morphism between two objects,i.e., the morphisms describe a binary relation/predicate on the collection of objects. — This means thatwe don’t need extra names/identifiers for those morphisms. — It turned out that composition in thosecategories is nothing but transitivity and that identities are given by what is usually called reflexivity.Therefore, we will call those categories preorder categories.Methodological remark: I avoided to introduce preorders as a structure for itself. This saves some time.Of course, it is methodological nice to present and to explain categories and categorical constructions asgeneralization of orders and corresponding constructions. But, what to do when most of the students arenot really familiar with orders.2011: I forgot to ask what ”anti-symmetry” means in terms of categories.The definition of opposite categories comes a bit ”out of the blue”, but here it is maybe a convenientplace to present it. Later we will often need this construction. The crucial point is that changing thedirection of arrows means also reversing the order of composition.

Definition 10 (Opposite category). For a category C its opposite category Cop is given by the oppositegraph gr(C)op = (C0,C1, tg

C , scC) where we use the notation fop : b → a to indicate that a morphismf ∈ C1, going from x to y in C, is considered as morphism in Cop going from y to x. Moreover, we have:

composition: gop; fopdef= (f ; g)op for all morphisms gop : z → y, fop : y → x in Cop, i.e., for all

morphisms f : x→ y, g : y → z in C.

identity: idCop

xdef= idCx for all objects x in Cop and thus all objects x in C.

Again a short discussion that Definition 10 is not a ”real construction”, i.e., doesn’t touch the ”concreterealization” of arrows, but is only a ”reinterpretation” on an abstract level. I mentioned also that thereare, especially in the SE area, often ideological fights about the ”right direction” of arrows. I discussedthe example of ”inheritance” in class diagrams, where the direction of ”inheritance arrows” is oppositeto the ”real direction” given by the inclusion of sets of attributes.

1.6 Monoids

Methodological remark: This example is meant to serve different purposes:

1. Beside graphs I want to have another algebraic structure with “real operations” as example. Es-pecially, I want that the students get a better feeling for homomorphisms and that they have seenonce a pre-fix notation for operations.

Page 16: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

16 CHAPTER 1. GRAPHS, CATEGORIES, FUNCTORS

2. Especially, I want to have another example of a “forgetful functor” for the motivation of functors.

3. I want to have the parameterized data type of lists available for the following reasons:

(a) The “free construction” of lists prepares for the construction of path categories.

(b) This is a kind of “practical example” for free functors and may serve later to motivate adjunc-tions?

Later I should make a remark that monoids can be just seen as small categories with exactly one object!

Definition 11 (Monoid). A monoid M = (M, cM, bM) is given by

• a set M ,

• a constant cM ∈M , and

• a binary operation bM : M ×M →M

subject of the following laws

ID bM(cM,m) = bM(m, cM) = m for all m ∈M .

ASS bM(bM(m1,m2),m3) = bM(m1, bM(m2,m3)) = m for all m1,m2,m3 ∈M .

2011: Brigita asked about the difference betweenM and M : I follow the convention to denote a monoidand its carrier by the same letter but with different fonts — calligraphic font for the monoid and normalfont for the underlying set. Note, that the superscripts are therefore also calligraphic!

Example 12 (Examples for monoids). We consider the following examples of monoids:

• Natural numbers with addition or multiplication, respectively: N+ = (N, 0,+), N∗ = (N, 1, ∗)

• Real numbers with addition: R+ = (R, 0,+)

• Positive real numbers with multiplication: R∗ = (R+, 1, ∗)

• For any set A we have the monoid of its subsets: P(A) = (℘(A), ∅,∪)

• For any set A we have the monoid of all lists with elements from A: L(A) = (A∗, [ ],@) withA∗ = {[a1, . . . , an] | n ∈ N; a1, . . . , an ∈ A} the set of lists over A, [ ] the empty list, and theconcatenation of lists [a1, . . . , an]@[a′1, . . . , a

′m] = [a1, . . . , an, a

′1, . . . , a

′m]

Do you know a datatype “between” P(A) and L(A)?

• The smallest monoid? — A monoid with exactly one element, as L(∅) for example!

• . . .

With monoids we have, besides graphs, a second example of an ”algebraic structure”, i.e., a structuregiven by set(s) and operations. A graph homomorphism had to respect the ”graph structure”, i.e., hadto be compatible with the source and target maps. Analogously, a morphism between monoids shouldrespect the ”monoid structure”, i.e., should be compatible with the constants and the binary operations:

Definition 12 (Monoid morphism). A morphism f :M→N between two monoidsM = (M, cM, bM)and N = (N, cN , bN ) is given by a map f : M → N such that:

• f(cM) = cN and

• f(bM(m1,m2)) = bN (f(m1), f(m2)) for all m1,m2 ∈M .

Page 17: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

1.7. FUNCTORS 17

Remark 6 (Notation of morphisms). Please be aware of a small subtelty in the notation: As mentionedbefore, we denote a monoid and its underlying set with the same letter but in different fonts. For themonoid (structure) we use the calligraphic font M and for the underlying set we are using the normalfont M . This convention allows us now do distinguish between different kinds of “arrows”: When wewrite f : M → N we mean a map. When we, however, write f :M→N we mean a monoid morphism,i.e., the notation f : M → N tells us implicitly that f is not only a map but also satisfies the twoconditions for a monoid morphism. Referring to a discussion we had before one could also say: The mapf : M → N establishes/realizes a morphism f :M→N in the category Mon.

Example 13 (Examples for monoid morphisms). Let’s look at some “practical” examples for monoidmorphisms.

• What morphism from L(A) into N+ could be useful? — How we can define the length of a list asa monoid morphism length : L(A) → N+. First, we can look what the morphism conditions meanin this example:

length([ ]) = 0 and length(l1@l2) = length(l1) + lenght(l2) for all list l1, l2 ∈ A∗

What condition is missing to define length uniquely? We have to say what the length of a list withone element is: length([a]) = 1 for all a ∈ A. Why does this work? — Because each non-empty listhas a unique representation as the concatenation of the singleton lists of all its elements:

[a1, a2, . . . , an] = [a1]@[a2]@ . . .@[an]

You should be able to define a monoid morphism into the other direction for all non-empty sets A!

• For any monoids M and N we have a trivial morphism c :M→ N that maps all elements in Mto the constant cN .

• A morphism from L(A) into P(A)? — Just turn [. . .] into {. . .}! — Discussion about the implicitassumptions concerning the {. . .} notation: The use of the curly brackets tells you that you have(are allowed) to abstract from the order and the multiplicity of elements! This means, for example,that all the expressions {a, b, b, a}, {b, a, a, a, a, a, a, b}, {a, b}, {a, b, a, b, a, b, . . .} represent the sameset.

• A morphism into the other direction from P(A) into L(A)? — Only the trivial one! The crucialpoint is that the operation ∪ is idempotent, i.e., B ∪ B = B for all sets B where, in contrast, theconcatenation of lists is not idempotent. Or, in other words, any set can be represented as a unionof singleton sets, but this representation is not unique!

2011: I haven’t put it so abstract in the lecture but gave a concrete example. Florian proposed touse “ordered lists” and I showed in the example that this doesn’t help.

1.7 Functors

• Following the categorical imperative we could ask directly: Arrows between graphs are given bygraph homomorphisms. Categories are graphs with some additional structures. How does theconcept of graph homomorphism extends to a concept of arrow between categories? — Besidesource and target also the additional structure (identities and composition) have to be preserved. . .

• But, let’s look, first, for a more concrete motivation: We have defined a graph as a pairs of setsplus . . . and a graph homomorphism as a pair of maps plus . . . In the same way we have defined amonoid as a set plus . . . and a monoid morphism as a map plus . . . How can we make explicit thatgraphs and monoids and their morphisms are based on sets and maps, respectively?

Page 18: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

18 CHAPTER 1. GRAPHS, CATEGORIES, FUNCTORS

• As a first approximation we could say that we have two graph homomorphisms node : gr(Graph)→gr(Set) and edge : gr(Graph) → gr(Set). What more? — We have defined composition andidentities in Graph componentwise by means of composition and identities in Set. This means thatthe two pairs of maps node and edge are not only compatible with source and target, but also withidentities and composition.

• Discussion that the componentwise definition of identity homomorphisms and of composition ofhomomorphisms, respectively, means exactly that both maps, node and edge are compatible withidentities and composition, respectively.

Definition 13 (Functor). A functor ϕ : C → D between two categories C and D is given by a graphhomomorphism ϕ : gr(C)→ gr(D) satisfying the following additional compatibility conditions:

• ϕ1(f ; g) = ϕ1(f);ϕ1(g) for any pair f : x→ y, g : y → z of composable morphisms in C.

• ϕ1(idCx) = idDϕ0(x)for all objects x in C.

Some comments on Definition 13:

• Remark that functors like node and edge are often called forgetful functors since they “forget”structure and/or properties. What structures/properties are forgotten by the functors node andedge, respectively? What structures/properties are forgotten by the forgetful functor from Moninto Set?

• Remark that compatibility w.r.t. composition means that commutative triangles are mapped tocommutative triangles and that this generalizes to arbitrary commutative diagrams. This means,especially, that functors preserve iso’s:

Corollary 2 (Functors preserve iso’s). Any functor ϕ : C→ D preserves isomorphisms, i.e., if f : x→ yis an isomorphism in C then ϕ1(f) : ϕ0(x)→ ϕ0(y) is an isomorphism in D.

Proof. 2011: At the end, I developed the proof on the black board. Maybe I’ll add it here later. I talkedalso about ”diagram chasing”.

Example 14 (Examples of functors). The following examples should be discussed in the lectures or inthe group exercises:

• Define a functor from Nat into Incl. That is, assign to each natural number n a set e(n) such thatn ≤ m implies e(n) ⊆ e(m) for all natural numbers n,m. (This resembles a well-known trick toencode natural numbers by sets.)

• Define a functor from Incl into Set. Methodological remark: This is a kind of artificial example andthe real question is if we want to consider the concepts ”inclusion” and ”inclusion map” as identicalor not, i.e., if we want to consider Incl as a subcategory of Set or not. 2011: I forgot to introducethe concept subcategory.

• Define a functor from Set into Rel. Methodological remark: This example is chosen to intro-duce/remind the concept of a graph of a function.

• Define a functor from Setop into Mult. Methodological remark: This example is chosen to intro-duce/remind the concept of a preimage or inverse image, respectively. Inverse images shallserve later as a motivating example for pullbacks.

• If you have still time you may look for a functor from Rel into Mult and a functor into the otherdirection. Methodological remark: This could be extended later to prove that both categories areisomorphic. But, this may be too much?

Page 19: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

1.8. CATEGORIES OF CATEGORIES 19

• Methodological remark: I never thought about it before, but it seems that the formation of converserelations establishes an isomorphism between Rel and Relop. The corresponding isomorphism be-tween Mult and Multop describes then what we call ”inverse multi function” and what is called”opposite references” in Ecore. These iso’s may serve later as a motivation for opposite categoriesand contravariant functors?

• After we have introduced the category Cat of small categories we may discuss a functor from Setinto Cat and coin the concept discrete category. 2011: In the group meeting some students likedto discuss ”inverse” vs. ”converse” and it seems that I should discuss this issue more extensively(later this year or next time?)

1.8 Categories of categories

We have now categories and functors, i.e., ”directed relations”, between categories. This time we askdirectly, without any further motivation, if we can define identity functors and if we can compose functors.

Lemma 3 (Identity functor). For any category C the identity graph homomorphism idgr(C) = (idC0, idC1

) :gr(C)→ gr(C) defines a functor idC : C→ C, i.e, the graph homomorphism idgr(C) satisfies the compati-bility conditions for functors.

Proof. This is an easy exercise. Compare the proof of the next lemma.

Lemma 4 (Functor composition). For any two functors ϕ : C → D and ψ : D → E the compositionϕ;ψ : gr(C) → gr(E) of the underlying graph homomorphisms ϕ : gr(C) → gr(D), ψ : gr(D) → gr(E)defines a functor ϕ;ψ : C → E, i.e., the graph homomorphism ϕ;ψ satisfies the compatibility conditionsfor functors:

• (ϕ;ψ)1(f ; g) = (ϕ;ψ)1(f); (ϕ;ψ)1(g) for any composable morphisms f : x→ y, g : y → z in C.

• (ϕ;ψ)1(idx) = id(ϕ;ψ)0(x) for all objects x in C.

Proof. 2011: At the end, I made the proof in the lecture to show once a systematic, pedantic proof.has to be typed

Now, we have closed a circle: We have categories, identity functors and composition of functors. Moreover,identity functors and the composition of functors satisfy the identity and the associativity law, sinceidentity graph homomorphisms and the composition of graph homomorphisms satisfy these laws.So what? — There seems to be something around like a “category of categories”. We have, however, tobe careful when defining such a category in order to avoid a “vicious circle”! So, let’s take a first, gentlestep.

Definition 14 (Category Cat). Small categories and the functors between them constitute a category Cat:objects: all small categories Cmorphisms: all functors ϕ : C→ D between small categoriescomposition: For any two functors ϕ : C → D and ψ : D → E the composition ϕ;ψ : C → E is

given by the composition ϕ;ψ : gr(C)→ gr(E) of the underlying graph homomorphismsϕ : gr(C)→ gr(D) and ψ : gr(D)→ gr(E) (see Lemma 4)

Identity: For any small category C the identity functor idC : C → C is given by the identity graphhomomorphism idgr(C) = (idC0 , idC1) : gr(C)→ gr(C) (see Lemma 3)

The crucial point is that the category Cat and all the categories Set, Incl, Rel, Mult, Mon are not small.So, we have to define another category CAT if we want those categories to have a place to live in. Thiscan be done by reusing Definition 14 where we replace “small category” by “category”. But, then CATshould also live somewhere, i.e., should be an object of a certain category — What we will get (or shouldassume), in such a way, is an open hierarchy of categories of categories (Grothendieck universes).

Page 20: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

20 CHAPTER 1. GRAPHS, CATEGORIES, FUNCTORS

• Remark that we can define a functor from Mon into Cat, showing that a monoid can be consideredactually as a small category with exactly one object, and that functors between one-object categoriesare just what we called monoid morphism .

• Remark that we can define a functor from Set into Cat, making out of a set a discrete categorywith identities the only morphisms.

1.9 Exercises

• For anybody which has been taken once a course in Linear Algebra: Define a category with mor-phisms given by arbitrary n×m-matrices of real numbers.

Page 21: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

Chapter 2

A first taste of (meta)modelling

Methodological remark: In this chapter I want to introduce the two main concepts/constructions wehave available to formalize modeling: Functor categories and slice categories. I’ll also stress that these”definition techniques” are omnipresent in mathematics and computer science.

1. The part on functor categories will be called ”indexing” referring to the concept of ”indexed sets”.

2. The part on slice categories will be called ”typing” referring to ”typed sets” and ”typed graphs”.

3. I would have liked to use ”fibred” instead of ”typed”, but this term would come ”out of the Blue”and, especially, I’m not intending to introduce fibrations. Hopefully, the students have a betterintuition concerning the term ”typing”?

4. I’ll not discuss here the general transition between ”indexed” and ”typed”, but intend to discussthe equivalence between ”indexed sets” and ”typed sets”.

5. It’s open if I should discuss forgetful functors in the indexed setting here. To define forgetfulfunctors in the fibred setting we need pullbacks and they come only later.

2011: I discussed a bit about the development of programming languages — machine code, assembler,higher order imperative programminglanguages (need for compilers), modular h.-o. imperative languages(Modula, Ada, bassword data encapsulation, . . . ), object oriented languages (Simula, Eiffel, . . . ). ThenI asked: What will be the next natural step? — Go from programming to modelling! And I talked a bitabout the vision behind MDE, MDD, MDA.The term “model” has different meanings in different contexts. Especially, we have to be aware of a”cultural clash” concerning the use of this term in areas like logic, geometry, algebraic specifications, onone side, and in areas like physics, chemistry, architecture, SE, on the other side.In expressions like ”a model of non-euclidian geometry” and ”model theory” the term ”model” means aninterpretation of a formal specification (systems of axioms) in an appropriate “semantic universe”.In expressions like ”standard model of particle physics”, ”atomic orbital model”, ”architectural model”,”software model” the term ”model” means, in contrast, an abstract description/representation of (someaspects of) a ”real system”.In software engineering, a “real system” means something like a “software system” or “computer system”,either an existing one or one that has to be build. We will use here the term ”model” in this softwareengineering sense.Models in software engineering are typically diagrammatic.We are concerned here with (at least) three different kinds of “diagrams”. To minimize potential confu-sion, we will try to distinguish between them with the following terminology.

1. There is the general idea of a “picture” with (labeled) nodes and (labeled) edges where nodes and/oredges may be drawn with different kinds of frames and/or may be colored. We will refer to thosepictures as pictorial diagrams or, shortly, p-diagram.

21

Page 22: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

22 CHAPTER 2. A FIRST TASTE OF (META)MODELLING

2. We have different specializations of this general idea for modeling and specification purposes like“ER diagrams”, “UML class diagrams”, ”date flow diagram”, Petri net, . . . . We will refer to thosespecializations as model diagrams (m-diagrams) or diagram of a model, respectively.

3. Finally, we have a strict, formal categorical concept of diagram, which we will discuss later. Wewill call these diagrams short diagrams. Methodological remark: For our purposes it may be moreappropriate to call them later (diagrammatic) constraints as we do in DPF.

Show a sequence of examples of m-diagrams like in the first lecture

Discussion: Models of a certain kind have a certain (syntactic) structure and the (syntactic) structure ofall models of a certain kind is described by a metamodel — analogy: program in a certain language is amodel and the BNF of the language is the metamodel — what is a meta-metamodel in this case? — aformal description of the structure of BNF’s . . .

2.1 Indexing

We have discussed that diagrammatic models are based on graphs. So let us, for now, consider a model tobe a graph. What would be then a metamodel of graphs, i.e., a diagrammatic description of the concept”graph”? — . . .

• Actually, our notation for graphs G = (G0, G1, scG, tgG) refers implicitly already to such a meta-

model consisting of 0, 1, sc, tg :

1tg

99

sc

%%0

• Let’s take this p-diagram as the representation of a category G where we dropped to draw theidentity morphisms id1 and id0

• If we consider now the category G as a metamodel of the concept ”graph” What is a modelconforming to this model, i.e., how we can describe graphs by means of the category G?

• A graph is given by assigning to each object in G a set and to each morphism in G a map. Or, toput it more abstract and precise: A graph is a functor G : G→ Set!!!

1tg

99

sc

%%0

G // G1 tgG 77

scG

''G0

• O.k.! A graph is a functor, but what is then a graph homomorphism in this abstract setting?

• Defining a graph homomorphism ϕ from a graph G to a graph H means to assign to each object inthe category G a morphism in Set relating the two different interpretations of the respective object.That is, we assign to the objects 1 and 0 in G maps ϕ1 : G1 → H1 and ϕ0 : G0 → H0, respectively.

1tg

99

sc

%%0

G //

H

%%KKKKKKKKKKKKK G1 tgG 77

scG

''

ϕ1

��

G0

ϕ0

��H1 tgH 77

scH

''H0

Page 23: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

2.1. INDEXING 23

• If we formulate now the compatibility conditions for graph homomorphisms by means of compositionof maps instead of map application, we get the two conditions: scG;ϕ0 = ϕ1; scH and tgG;ϕ0 =ϕ1; tgH . That is, we require that for any non-identity morphism in G we have a commutative square:

G1tgG //

ϕ1

��

G0

ϕ0

��

G1scG //

ϕ1

��

G0

ϕ0

��

G1

G(id1)=idG1 //

ϕ1

��

G1

ϕ1

��H1

tgH // H0 H1scH // H0 H1

H(id1)=idH1 // H1

Note, that the squares for identity morphisms are trivially commutative.

This idea of relating the images of two functors componentwise by arrows and of requiring a commutativesquare for each arrow in the source category is not restricted to the category G only, but can be formulatedfor any categories and functors.

Definition 15 (Natural transformation). A natural transformation ϕ : G⇒ H between two functorsG : C→ D and H : C→ D is given by a map

ϕ : C0 → D1 with ϕ; scD = G0 and ϕ; tgD = H0.

that is, for each object x in C we have a morphisms ϕx : G0(x) → H0(x). Moreover, the followingnaturality condition is satisfied:

NAT G1(f);ϕy = ϕx;G1(f) for all morphisms f : x→ y in C.

xf // y G0(x)

G1(f) //

ϕx

��

G0(y)

ϕy

��

G0(x)G1(idx)=idG0(x)//

ϕx

��

G0(x)

ϕx

��H0(x)

H1(f) // H0(y) H0(x)H1(idx)=idH0(x)// H0(x)

• Underline that a natural transformation relates componentwise the images of the same categoryw.r.t. two functors (draw a picture) and that we have only for non-identity morphisms in C a propercondition since the naturality condition is trivially satisfied for identity morphisms.

• Natural transformations are usually pictured by a cell consisting of two parallel arrows betweennodes and an additional arrow between the arrows. diagram of a cell together with the correspondingsequential notation

C

G((

H

66�� ���� ϕ D

I personally find it helpful to use a sequentialization of this diagram like ϕ : G ⇒ H : C → Dinstead of the short notation ϕ : G⇒ H to keep track of the envolved categories also.

The componentwise definition of identity graph homomorphisms and of the composition of graph homo-morphisms, respectively, can be straightforwardly generalized to natural transformations.

Definition 16 (Identity transformation). For any functor G : C → D the identity transformation

idG : G⇒ G is given componentwise by identity morphisms: (idG)xdef= idG0(x) for all objects x in C.

xf // y G0(x)

G1(f) //

idG0(x)

��

G0(y)

idG0(y)

��G0(x)

G1(f) // G0(y)

Page 24: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

24 CHAPTER 2. A FIRST TASTE OF (META)MODELLING

Definition 17 ((Vertical) composition of transformations). The (vertical) composition of two naturaltransformations ϕ : G⇒ H : C→ D and ψ : H ⇒ K : C→ D is defined componentwise:

(ϕ;ψ)xdef= ϕx;ψx for all objects x inC.

G0(x)G1(f) //

ϕx

��ϕx;ψx

��

G0(y)

ϕy

��ϕy ;ψy

��

xf // y H0(x)

H1(f) //

ψx

��

H0(y)

ψy

��K0(x)

K1(f) // K0(y)

C

G

!!�� ���� ϕH //

K

==�� ���� ψ

D C

G((

K

66�� ���� ϕ;ψ D

2011: In the lecture I mentioned that “cells” are a natural way to formalize term rewriting and Ireferred to the language MAUDE. Moreover, I mentioned that there exist also a horizontal compositionof natural transformations, but that this maybe too much for this course and that we will probably don’tneed this kind of composition at the present stage of what I can cover in the course.In the same way as the identity and the associativity law for graph homomorphisms was inherited, due tothe componentwise definitions, from the category Set, we see easily that the identity and the associativitylaw for natural transformations are inherited from the category D. This allows us to define categorieswith functors as objects:

Definition 18 (Functor category). For any categories C and D we can define a functor category whichis denoted by [C→ D]: objects: all functors G : C→ Dmorphisms: all natural transformations ϕ : G⇒ H : C→ Dcomposition: the composition of two natural transformations ϕ : G ⇒ H and ψ : H ⇒ K is defined

componentwise as in Definition 17: (ϕ;ψ)x = ϕx;ψx for all objects x in C.identity: For any functor G : C→ D the identity transformation idG : G⇒ G is defined componentwise

as in Definition 16: (idG)x = idG0(x) for all objects x in C.

• remark corning “exponential notation”

• Remark that the iso’s in functor categories are natural isomorphisms, i.e., componentwise iso’s.

• Corollary that Graph is isomorphic to functor category . . .

• underline that the abstract presentation of graphs opens quite natural for generalizations: That is,we could just exchange the category Set with another category and will get in such a way thingslike ”graphs of graphs”, ”graphs of monoids”, . . .

• generalization? — reflexive graphs

• underline that CT allows us to formulate definitions, statements and constructions in a very compactand concise way

– define the category of reflexive graphs as a functor category

– and then unfold this definition into a set-theoretical definition

• Exercise “forgetful functor” (copying?)

• general patter is “indexed semantics” where we may also very the semantic domain!!!

Page 25: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

2.2. TYPING 25

2.2 Typing

Typing as motivation for slice categories

• Petri nets and ER-diagrams as motivation

• different examples

• (maybe dual concept?)

• functors between slice categories

2.3 Indexed and typed sets

Page 26: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

26 CHAPTER 2. A FIRST TASTE OF (META)MODELLING

Page 27: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

Chapter 3

Universal properties andconstructions

3.1 Special morhisms

3.1.1 Monomorphisms

3.1.2 Epimorphism

27

Page 28: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

28 CHAPTER 3. UNIVERSAL PROPERTIES AND CONSTRUCTIONS

Page 29: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

Chapter 4

(Meta)models

29

Page 30: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

30 CHAPTER 4. (META)MODELS

Page 31: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

Chapter 5

Rest from 2008

5.1 Lecture 23.01.2008

5.1.1 Graph

The Generalized Sketch framework, as any other diagrammatic specification technique, is heavily basedon the concept of graph, thus we start with a formal definition of this concept and the other necessaryconcepts around. Before we dive into technicalities, the following important remark is in order. In thispaper

5.1.2 Graph Homomorphism

A first important methodological point for Diagrammatic Specification Techniques is that we have todistinguish clearly between the concept of a graph and the concept of a diagram.

Definition 19 (Diagram). Let G and I be graphs, A diagram in G with shape I is a graph homomor-phism δ : I → G.

Example 15 (Shapes). Some of the most simple shapes, that are used in nearly any application, are

Node = ( x ), Arrow = (x1→ y), Span = (x

1← z2→ y), Cospan = (x

1→ z2← y), and the following three

graphs Cell, Circle, and Triangle, respectively:

x1

((

2

66 y x1

(( y2

hh x1 //

3

44y 2 // z

Remark 7 (Parameter). In programming we have the concepts “formal parameter list” and “actualparameter list”. Analogously, a shape can be seen as a “formal parameter graph” with variables for nodes(as in a “formal parameter list”) and, in generalizing the concept of list, also with variables for arrows. Adiagram assigns “actual values” to the variables and can bee seen, in such a way, as an “actual parametergraph”. A crucial point is that we can assign the same “actual value” to different variables thus in the“actual parameter graph” there maybe different copies of the same “actual value” (see also Remark 8).

Remark 8 (Visualization of Diagrams). Pict-diagrams are traditionally also used to present diagramsδ : I → G. The essential idea is to draw a picture with a separate “place holder node” for each elementin I0 and with a separate “place holder arrow” for each element in I1. And then we put into the “placeholders” the corresponding items from G according to the assignment δ. In such a way, we may have inthe picture different copies of the same item from G at different places. The following three pict-diagrams,for example,

Af // A A A

f //foo A Af // A A

foo

31

Page 32: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

32 CHAPTER 5. REST FROM 2008

represent diagrams δ1 : Arrow → Set, δ2 : Span → Set, δ3 : Cospan → Set with the same “actual values”but with different shapes.A critical methodological point is, that the ordinary way of visualizing math-diagrams by pict-diagramscan be ambiguous. From the following pict-diagram

N Mπ1 //π2oo N

visualizing a diagram δ : Span → G in the graph G from Example ??, we cannot deduce, for example,the following information: does δ actually assign to 1 the arrow π1 or the arrow π2? This informationmay be irrelevant in this special case, but it illustrates that some additional information may be requiredto extract the respective math-diagram from a given pict-diagram, and a tool for drawing diagrams musthandle those informations.

5.1.3 Opposite graphs

5.2 Lecture 30.01.2008

5.2.1 Paths in a graph

5.2.2 Category

• definition of a category with examples Set, Graph

• category of paths in a graph

5.3 Lecture 04.02.2008

5.3.1 More Examples of Categories

• category Logi and general pre-orders as categories

• category Mult of sets and multi-functions

5.3.2 Diagrams and commutative diagrams

5.4 Lecture 06.02.2008

5.4.1 Isomorphism

• definition of isomorphisms with examples in Set, Graph, Logi

• isomorphic objects have the same “social life”

5.4.2 Monomorphism

• Coding of injectivity in the language of arrows?

⇒ coding of symbol ∈ by pointers!

• definition of monomorphisms

• monomorphisms in Set are exactly the injective maps

Page 33: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

5.5. LECTURE 11.02.2008 33

5.5 Lecture 11.02.2008

5.5.1 Epimorphism

• Epimorphisms as dual to monomorphisms

• definition of epimorphisms

• epimorphisms in Set are exactly the surjective maps

5.5.2 Split epimorphisms and split monomorphisms

5.5.3 Opposite Category

• definition of opposite category

• definition of “dual concept/statement”

• duality principle

5.5.4 Subcategories

• definition of subcategory

• full subcategories

• discrete categories

5.6 Lecture 13.02.2008

5.6.1 Slice Categories

• discussion of “typing”

• definition of slice categories with examples

5.6.2 Initial objects

• Don’t forget the nice argumentation concerning ∅ in Fiadeiro’s book

• characterization of the empty set in the language of arrows?

• definition of initial objects

• initial objects determined “up to isomorphism”

5.7 Lecture 18.02.2008

5.7.1 Terminal Objects

• terminal objects as dual to initial objects

• examples of initial and terminal objects in Set, Logi, Mult

Page 34: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

34 CHAPTER 5. REST FROM 2008

5.7.2 Sums

– definition of sums

– examples of sums in Set, Logi, and for power sets

⇒ discussion of different social lifes of sets in Set and in power sets

Definition 20 (Sum). An object x + y together with injections ix : x → x + y, iy : y → x + y is saidto be a sum(coproduct) of objects x and y in a category C iff for any object v and any morphismsfx : x → v, fy : y → v there is a unique morphism [fx, fy] : x + y → v such that ix; [fx, fy] = fx andiy; [fx, fy] = fy.

xix //

fx ""EEEEEEEEE x+ y

[fx,fy ]

��

yiyoo

fy||yyyyyyyyy

v

5.8 Lecture 20.02.2008

• sums in slice categories

5.8.1 Product

• definition of products

• examples in Set, Logi, and for inheritance

Definition 21 (Product). An object x × y together with projections πx : x × y → x, πy : x × y → yis said to be a product of objects x and y in a category C iff for any object v and any morphismsfx : v → x, fy : v → y there is a unique morphism 〈fx, fy〉 : v → x × y such that 〈fx, fy〉;πx = fx and〈fx, fy〉;πy = fy.

v

〈fx,fy〉��

fx

||yyyyyyyyyfy

""EEEEEEEEE

x x× yπx

ooπy

// y

v

5.8.2 Pushouts

• from sums to pushouts motivated by “sharing”

• definition of pushouts

• construction of pushouts in Set

⇒ definition of equivalence relations and quotient sets

⇒ discussion of equivalence as mathematical way of abstraction and of creating new concepts

⇒ example “fractions vs. rational numbers”

Page 35: Category Theory and Diagrammatic Modellingwolter/teaching/v11-inf223/manuscript.pdfDue to the categorical imperative we can not give a concrete construction of the Cartesian Product

5.9. LECTURE 25.02.2008 35

5.9 Lecture 25.02.2008

5.9.1 Pushouts

• construction of pushouts in Set

• pushouts by sums and co-equalizers

• definition of coequalizers

Definition 22 (Pushout). Let f : x→ y, g : x→ z be morphisms in a category C. A pushout of f andg consists of an object w : C and two morphisms f ′ : y → w, g′ : z → w such that:

1. f ; f ′ = g; g′,

2. for any other v : C and f ′′ : y → v, g′′ : z → v such that f ; f ′′ = g; g′′ there is a unique k : w → vsuch that f ′; k = f ′′ and g′; k = g′′.

xix //

fx ""EEEEEEEEE x+ y

[fx,fy ]

��

yiyoo

fy||yyyyyyyyy

v

5.9.2 Pullbacks

• pullbacks as duals of pushouts

• pullbacks by products and equalizers