User:Michiexile/MATH198/Lecture 1
From HaskellWiki
Michiexile (Talk | contribs) |
Michiexile (Talk | contribs) |
||
Line 30: | Line 30: | ||
* Graph is vertices and edges. Each edge has source and target. | * Graph is vertices and edges. Each edge has source and target. | ||
− | * Notation: <math>G</math> a graph, <math>G_0</math> the vertices, <math>G_1</math> the edges. | + | * Notation: <math>G</math> a graph, <math>G_0</math> the vertices, <math>G_1</math> the edges, or arrows. |
* Some examples. | * Some examples. | ||
* Complete structure given by <math>G_0</math>, <math>G_1</math> and the two functions <math>s,t:G_1\to G_0</math>. | * Complete structure given by <math>G_0</math>, <math>G_1</math> and the two functions <math>s,t:G_1\to G_0</math>. | ||
Line 39: | Line 39: | ||
* Paths: A path from the node <math>x</math> to the node <math>y</math> is some sequence of edges <math>(f_1,\dots,f_n)</math> with: | * Paths: A path from the node <math>x</math> to the node <math>y</math> is some sequence of edges <math>(f_1,\dots,f_n)</math> with: | ||
− | ** <math>s( | + | ** <math>s(f_n)=x</math> |
− | ** <math>t( | + | ** <math>t(f_1)=y</math> |
− | ** <math> | + | ** <math>t(f_i) = s(f_{i-1})</math> for all other <math>i</math>. |
* For any node <math>x</math>, there is a unique path from <math>x</math> to <math>x</math> of length 0: <math>()</math>. | * For any node <math>x</math>, there is a unique path from <math>x</math> to <math>x</math> of length 0: <math>()</math>. | ||
Line 48: | Line 48: | ||
* We denote by <math>G_k</math> the set of all paths in <math>G</math> of length <math>k</math>. | * We denote by <math>G_k</math> the set of all paths in <math>G</math> of length <math>k</math>. | ||
* This is compatible with out previous definition of <math>G_0,G_1</math>. | * This is compatible with out previous definition of <math>G_0,G_1</math>. | ||
+ | |||
+ | ===Categories=== | ||
+ | |||
+ | * A category is a graph equipped with an associative composition operation <math>\circ:G_2\to G_1</math> and an identity element <math>1_x</math> for each node <math>x</math> for this composition operation. The identity arrows may be viewed as being a function <math>u:G_0\to G_1</math>. Additional axioms are: | ||
+ | *# Composition respects sources and targets, in that: | ||
+ | *** <math>s(g\circ f) = s(f)</math> | ||
+ | *** <math>t(g\circ f) = t(g)</math> | ||
+ | *# <math>s(u(x)) = t(u(x)) = x</math> | ||
+ | |||
+ | * More on how we write compositions, and why the order is the way it is. | ||
+ | |||
+ | * We denote by <math>Hom_C(A,B)</math>, or if <math>C</math> is obvious from context, just <math>Hom(A,B)</math>, the set of all arrows from <math>A</math> to <math>B</math>. This is the hom-set, and may also be denoted <math>C(A,B)</math>. | ||
+ | * In a category, arrows are also called ''morphisms'', and nodes are also called ''objects''. This ties in with the algebraic roots of the field. | ||
+ | |||
+ | * Large/small categories. Finite categories. Concrete categories. | ||
+ | |||
+ | * Sub-category. Full subcategory. Wide subcategory. Products of categories. Duals/opposites of categories. | ||
+ | |||
+ | * Slice categories. Free categories generated by graphs. | ||
+ | |||
+ | ===Morphisms and objects=== | ||
+ | |||
+ | Some morphisms and some objects are special enough to garner special names that we will use regularly. | ||
+ | |||
+ | * Isomorphisms and existence of inverses. | ||
+ | * Epi- and mono-morphisms and cancellability. | ||
+ | ** Examples in concrete categories. | ||
+ | ** Monomorphisms and subobjects: | ||
+ | *** Factoring through. Equivalence relation by mutual factoring. | ||
+ | *** Subobjects as equivalence classes of monomorphisms. | ||
+ | ** Splitting and the existence of inverses. | ||
+ | * Terminal and initial objects. | ||
+ | ** Constants. Pointless sets. | ||
+ | |||
+ | |||
+ | ===Examples=== | ||
+ | |||
+ | * The empty category. | ||
+ | * The one object/one arrow category <math>1</math> | ||
+ | * The categories <math>2</math> and <math>1+1</math> | ||
+ | * The category Set of sets. | ||
+ | * The catgeory FSet of finite sets. | ||
+ | * The category PFn of sets and partial functions. | ||
+ | ** <math>PFn(A,B)</math> is a partially ordered set. | ||
+ | * Every partial order is a category. Each hom-set has at most one element. | ||
+ | * Every monoid is a category. Only one object. | ||
+ | ** Kleene closure. Free monoids. | ||
+ | * The category of Sets and injective functions. | ||
+ | * The category of Sets and surjective functions. | ||
+ | * The category of <math>k</math>-vector spaces and linear maps. | ||
+ | * The category with objects the natural numbers and <math>Hom(m,n)</math> the set of <math>m\times n</math>-matrices. | ||
+ | * The category of Data Types with Computable Functions. | ||
+ | ** Our ideal programming language has: | ||
+ | *** Primitive data types. | ||
+ | *** Constants of each primitive type. | ||
+ | *** Operations, given as functions between types. | ||
+ | *** Constructors, producing elements from data types, and producing derived data types and operations. | ||
+ | ** We will assume that the language is equipped with | ||
+ | *** A do-nothing operation for each data type. Haskell has <hask>id</hask>. | ||
+ | *** An empty type <math>1</math>, with the property that each type has exactly one function to this type. Haskell has <hask>()</hask>. We will use this to define the constants of type <math>t</math> as functions <math>1\to t</math>. Thus, constants end up being 0-ary functions. | ||
+ | *** A composition constructor, taking an operator <math>f:A\to B</math> and another operator <math>g:B\to C</math> and producing an operator <math>g\circ f:A\to C</math>. Haskell has <hask>(.)</hask>. | ||
+ | ** This allows us to model a functional programming language with a category. | ||
+ | * The category with objects logical propositions and arrows proofs. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===Homework=== | ||
+ | |||
+ | For a passing mark, a written, acceptable solution to at least 2 of the 3 questions should be given no later than midnight before the next lecture. | ||
+ | |||
+ | # Prove the general associative law: that for any path, and any bracketing of that path, the same composition may be found. | ||
+ | # Suppose <math>u:A\to A</math> in some category <math>C</math>. | ||
+ | ## If <math>g\circ u=g</math> for all <math>g:A\to B</math> in the category, then <math>u=1_A</math>. | ||
+ | ## If <math>u\circ h=h</math> for all <math>h:B\to A</math> in the category, then <math>u=1_A</math>. | ||
+ | # For as many of the examples given as you can, prove that they really do form a category. Passing mark is at least 60% of the given examples. | ||
+ | # For this question, all parts are required: | ||
+ | ## For which sets is the free monoid on that set commutative. | ||
+ | ## Prove that for any category <math>C</math>, the set <math>Hom(A,A)</math> is a monoid under composition for every object <math>A</math>. | ||
+ | |||
Revision as of 13:08, 8 September 2009
Contents |
1 Welcome, administrativia
2 Introduction
2.1 Why this course?
An introduction to Haskell will usually come with pointers toward Category Theory as a useful tool, though not with much more than the mention of the subject. This course is intended to fill that gap, and provide an introduction to Category Theory that ties into Haskell and functional programming as a source of examples and applications.
2.2 What will we cover?
The definition of categories, special objects and morphisms, functors, natural transformation, (co-)limits and special cases of these, adjunctions, freeness and presentations as categorical constructs, monads and Kleisli arrows, recursion with categorical constructs.
Maybe, just maybe, if we have enough time, we'll finish with looking at the definition of a topos, and how this encodes logic internal to a category. Applications to fuzzy sets.
2.3 What do we require?
Our examples will be drawn from discrete mathematics, logic, Haskell programming and linear algebra. I expect the following concepts to be at least vaguely familiar to anyone taking this course:
- Sets
- Functions
- Permutations
- Groups
- Partially ordered sets
- Vector spaces
- Linear maps
- Matrices
- Homomorphisms
3 Category
3.1 Graphs
- Graph is vertices and edges. Each edge has source and target.
- Notation: G a graph, G_{0} the vertices, G_{1} the edges, or arrows.
- Some examples.
- Complete structure given by G_{0}, G_{1} and the two functions .
- Endoarrow, empty graph, discrete graph, complete graph, small graph, large graph, set theoretical traps, finite graph, simple graphs.
- Homomorphism: Map edges to edges, vertices to vertices, respects source and target maps.
- Paths: A path from the node x to the node y is some sequence of edges with:
- s(f_{n}) = x
- t(f_{1}) = y
- t(f_{i}) = s(f_{i − 1}) for all other i.
- For any node x, there is a unique path from x to x of length 0: ().
- For any edge f, there is a unique path from s(f) to t(f) of length 1.
- We denote by G_{k} the set of all paths in G of length k.
- This is compatible with out previous definition of G_{0},G_{1}.
3.2 Categories
- A category is a graph equipped with an associative composition operation and an identity element 1_{x} for each node x for this composition operation. The identity arrows may be viewed as being a function . Additional axioms are:
- Composition respects sources and targets, in that:
- s(u(x)) = t(u(x)) = x
- More on how we write compositions, and why the order is the way it is.
- We denote by Hom_{C}(A,B), or if C is obvious from context, just Hom(A,B), the set of all arrows from A to B. This is the hom-set, and may also be denoted C(A,B).
- In a category, arrows are also called morphisms, and nodes are also called objects. This ties in with the algebraic roots of the field.
- Large/small categories. Finite categories. Concrete categories.
- Sub-category. Full subcategory. Wide subcategory. Products of categories. Duals/opposites of categories.
- Slice categories. Free categories generated by graphs.
3.3 Morphisms and objects
Some morphisms and some objects are special enough to garner special names that we will use regularly.
- Isomorphisms and existence of inverses.
- Epi- and mono-morphisms and cancellability.
- Examples in concrete categories.
- Monomorphisms and subobjects:
- Factoring through. Equivalence relation by mutual factoring.
- Subobjects as equivalence classes of monomorphisms.
- Splitting and the existence of inverses.
- Terminal and initial objects.
- Constants. Pointless sets.
3.4 Examples
- The empty category.
- The one object/one arrow category 1
- The categories 2 and 1 + 1
- The category Set of sets.
- The catgeory FSet of finite sets.
- The category PFn of sets and partial functions.
- PFn(A,B) is a partially ordered set.
- Every partial order is a category. Each hom-set has at most one element.
- Every monoid is a category. Only one object.
- Kleene closure. Free monoids.
- The category of Sets and injective functions.
- The category of Sets and surjective functions.
- The category of k-vector spaces and linear maps.
- The category with objects the natural numbers and Hom(m,n) the set of -matrices.
- The category of Data Types with Computable Functions.
- Our ideal programming language has:
- Primitive data types.
- Constants of each primitive type.
- Operations, given as functions between types.
- Constructors, producing elements from data types, and producing derived data types and operations.
- We will assume that the language is equipped with
- A do-nothing operation for each data type. Haskell has .id
- An empty type 1, with the property that each type has exactly one function to this type. Haskell has . We will use this to define the constants of type t as functions . Thus, constants end up being 0-ary functions.()
- A composition constructor, taking an operator and another operator and producing an operator . Haskell has .(.)
- A do-nothing operation for each data type. Haskell has
- This allows us to model a functional programming language with a category.
- Our ideal programming language has:
- The category with objects logical propositions and arrows proofs.
3.5 Homework
For a passing mark, a written, acceptable solution to at least 2 of the 3 questions should be given no later than midnight before the next lecture.
- Prove the general associative law: that for any path, and any bracketing of that path, the same composition may be found.
- Suppose in some category C.
- If for all in the category, then u = 1_{A}.
- If for all in the category, then u = 1_{A}.
- For as many of the examples given as you can, prove that they really do form a category. Passing mark is at least 60% of the given examples.
- For this question, all parts are required:
- For which sets is the free monoid on that set commutative.
- Prove that for any category C, the set Hom(A,A) is a monoid under composition for every object A.
3.6 Graphs and paths
A graph is a collection G_{0} of vertices and a collection G_{1} of arrows. The structure of the graph is captured in the existence of two functions, that we shall call source and target, both going from G_{1} to G_{1}. In other words, each arrow has a source and a target.
We denote by [v,w] the collection of arrows with source v and target w.
We extend the notation, and denote by G_{i} the collection of all paths of length i. Such a path is a sequence of arrows, such that for each j, target(f_{j − 1}) = source(f_{j}).
3.7 Definition of a category
A category is a graph with some special structure:
- Each [v,w] is a set and equipped with a composition operation . In other words, any two arrows, such that the target of one is the source of the other, can be composed to give a new arrow with target and source from the ones left out.
We write if .
=>
- The composition of arrows is associative.
- Each vertex v has a dedicated arrow 1_{v} with source and target v, called the identity arrow.
- Each identity arrow is a left- and right-identity for the composition operation.
The composition of with is denoted by . A mnemonic here is that you write things so associativity looks right. Hence, (gf)(x) = g(f(x)). This will make more sense once we get around to generalized elements later on.
3.8 Examples
- The empty category with no vertices and no arrows.
- The category 1 with a single vertex and only its identity arrow.
- The category 2 with two objects, their identity arrows and the arrow .
- For vertices take vector spaces. For arrows, take linear maps. This is a category, the identity arrow is just the identity map f(x) = x and composition is just function composition.
- For vertices take finite sets. For arrows, take functions.
- For vertices take logical propositions. For arrows take proofs in propositional logic. The identity arrow is the empty proof: P proves P without an actual proof. And if you can prove P using Q and then R using P, then this composes to a proof of R using Q.
- For vertices, take data types. For arrows take (computable) functions. This forms a category, in which we can discuss an abstraction that mirrors most of Haskell. There are issues making Haskell not quite a category on its own, but we get close enough to draw helpful conclusions and analogies.
- Suppose P is a set equipped with a partial ordering relation <. Then we can form a category out of this set with elements for vertices and with a single element in [v,w] if and only if v<w. Then the transitivity and reflexivity of partial orderings show that this forms a category.
Some language we want settled:
A category is concrete if it is like the vector spaces and the sets among the examples - the collection of all sets-with-specific-additional-structure equipped with all functions-respecting-that-structure. We require already that [v,w] is always a set.
A category is small if the collection of all vertices, too, is a set.