User:Michiexile/MATH198/Lecture 1
From HaskellWiki
Michiexile (Talk | contribs) |
Michiexile (Talk | contribs) |
||
Line 149: | Line 149: | ||
For a passing mark, a written, acceptable solution to at least 2 of the 4 questions should be given no later than midnight before the next lecture. |
For a passing mark, a written, acceptable solution to at least 2 of the 4 questions should be given no later than midnight before the next lecture. |
||
+ | |||
+ | For each lecture, there will be a few exercises marked with the symbol *. These will be more difficult than the other exercises given, will require significant time and independent study, and will aim to complement the course with material not covered in lectures, but nevertheless interesting for the general philosophy of the lecture course. |
||
# Prove the general associative law: that for any path, and any bracketing of that path, the same composition may be found. |
# Prove the general associative law: that for any path, and any bracketing of that path, the same composition may be found. |
||
Line 159: | Line 161: | ||
## For which sets is the free monoid on that set commutative. |
## 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>. |
## 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>. |
||
+ | # * Read up on <math>\omega</math>-complete partial orders. Suppose <math>\mathsc P</math> is the set of partial functions <math>S\to S</math> - in other words, an element of <math>\mathsc P</math> is some pair <math>(S_0,f:S_0\to S)</math> with <math>S_0\subseteq S</math>. We give this set a poset structure by <math>(S_0,f)\leq(S_1,g)</math> precisely if <math>S_0\subseteq S_1</math> and <math>f(s)=g(s)\forall s\in S_0</math>. |
||
+ | #* Show that <math>\mathsc P</math> is a strict <math>\omega</math>-CPO. |
||
+ | #* An element <math>x</math> of <math>S</math> is a ''fixpoint'' of <math>f:S\to S</math> if <math>f(x)=x</math>. Let <math>\mathsc N</math> be the <math>\omega</math>-CPO of partially defined functions on the natural numbers. We define a function <math>\phi:\mathsc N\to\mathsc N</math> by sending some <math>h:\mathbb N\to\mathbb N</math> to a function <math>k</math> defined by |
||
+ | #*# <math>k(0) = 1</math> |
||
+ | #*# <math>k(n)</math> is defined only if <math>h(n-1)</math> is defined, and then by <math>k(n)=n*h(n-1)</math>. |
||
+ | Describe <math>\phi(n\maptso n^2)</math> and <math>\phi(n\mapsto n^3)</math>. Show that <math>\phi</math> is ''continuous''. Find a fixpoint <math>(S_0,f)</math> of <math>\phi</math> such that any other fixpoint of the same function is less than this one. |
||
+ | Find a continuous endofunction on some <math>\omega</math>-CPO that has the fibonacci function <math>F(0)=0, F(1)=1, F(n)=F(n-1)+F(n-2)</math> as the least fixed point. |
Revision as of 11:12, 10 September 2009
IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE FIRST LECTURE WITH HANDING ANYTHING IN, OR TAKING THE NOTES AS READY TO READ.
Contents |
1 Welcome, administrativia
I'm Mikael Vejdemo-Johansson. I can be reached in my office 383-BB, especially during my office hours; or by email to mik@math.stanford.edu.
I encourage, strongly, student interactions.
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
We recall the definition of a (directed) graph. A graph G is a collection of edges (arrows) and vertices (nodes). Each edge is assigned a source node and a target node.
Given a graph G, we denote the collection of nodes by G_{0} and the collection of arrows by G_{1}. These two collections are connected, and the graph given its structure, by two functions: the source function and the target function .
We shall not, in general, require either of the collections to be a set, but will happily accept larger collections; dealing with set-theoretical paradoxes as and when we have to. A graph where both nodes and arrows are sets shall be called small. A graph where either is a class shall be called large.
If both G_{0} and G_{1} are finite, the graph is called finite too.
The empty graph has .
A discrete graph has .
A complete graph has .
A simple graph has at most one arrow between each pair of nodes. Any relation on a set can be interpreted as a simple graph.
- Show some examples.
A homomorphism of graphs is a pair of functions and such that sources map to sources and targets map to targets, or in other words:
- s(f_{1}(e)) = f_{0}(s(e))
- t(f_{1}(e)) = f_{0}(t(e))
By a path in a graph G from the node x to the node y of length k, we mean a sequence of edges such that:
- s(f_{1}) = x
- t(f_{k}) = y
- s(f_{i}) = t(f_{i − 1}) for all other i.
Paths with start and end point identical are called closed. For any node x, there is a unique closed path () starting and ending in x of length 0.
For any edge f, there is a unique path from s(f) to t(f) of length 1: (f).
We denote by G_{k} the set of paths in G of length k.
3.2 Categories
We now are ready to define a category. A category is a graph C equipped with an associative composition operation , and an identity element for composition 1_{x} for each node x of the graph.
Note that G_{2} can be viewed as a subset of , the set of all pairs of arrows. It is intentional that we define the composition operator on only a subset of the set of all pairs of arrows - the composable pairs. Whenever you'd want to compose two arrows that don't line up to a path, you'll get nonsense, and so any statement about the composition operator has an implicit "whenever defined" attached to it.
The definition is not quite done yet - this composition operator, and the identity arrows both have a few rules to fulfill, and before I state these rules, there are some notation we need to cover.
3.2.1 Backwards!
If we have a path given by the arrows (f,g) in G_{2}, we expect and to compose to something that goes . The origin of all these ideas lies in geometry and algebra, and so the abstract arrows in a category are supposed to behave like functions under function composition, even though we don't say it explicitly.
Now, we are used to writing function application as f(x) - and possibly, from Haskell, asOn the other hand, the way we write our paths, we'd read f then g. This juxtaposition makes one of the two ways we write things seem backwards. We can resolve it either by making our paths in the category go backwards, or by reversing how we write function application.
In the latter case, we'd write x.f, say, for the application of f to x, and then write x.f.g for the composition. It all ends up looking a lot like Reverse Polish Notation, and has its strengths, but feels unnatural to most. It does, however, have the benefit that we can write out function composition as and have everything still make sense in all notations.
In the former case, which is the most common in the field, we accept that paths as we read along the arrows and compositions look backwards, and so, if and , we write , remembering that elements are introduced from the right, and the functions have to consume the elements in the right order.
The existence of the identity map can be captured in a function language as well: it is the existence of a function .
Now for the remaining rules for composition. Whenever defined, we expect associativity - so that . Furthermore, we expect:
- Composition respects sources and targets, so that:
- s(u(x)) = t(u(x)) = x
In a category, arrows are also called morphisms, and nodes are also called objects. This ties in with the algebraic roots of the field.
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).
If a category is large or small or finite as a graph, it is called a large/small/finite category.
A category with objects a collection of sets and morphisms a selection from all possible set-valued functions such that the identity morphism for each object is a morphism, and composition in the category is just composition of functions is called concrete. Concrete categories form a very rich source of examples, though far from all categories are concrete.
- Sub-category. Full subcategory. Wide subcategory. Products of categories. Duals/opposites of categories.
- Slice categories. Free categories generated by graphs.
3.3 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.4 Homework
For a passing mark, a written, acceptable solution to at least 2 of the 4 questions should be given no later than midnight before the next lecture.
For each lecture, there will be a few exercises marked with the symbol *. These will be more difficult than the other exercises given, will require significant time and independent study, and will aim to complement the course with material not covered in lectures, but nevertheless interesting for the general philosophy of the lecture course.
- 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}.
- These two results characterize the objects in a category by the properties of their corresponding identity arrows completely.
- 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.
- * Read up on ω-complete partial orders. Suppose Failed to parse (unknown function\mathsc): \mathsc P
is the set of partial functions - in other words, an element of Failed to parse (unknown function\mathsc): \mathsc P is some pair with . We give this set a poset structure by precisely if and .
- Show that Failed to parse (unknown function\mathsc): \mathsc P
is a strict ω-CPO.
- An element x of S is a fixpoint of if f(x) = x. Let Failed to parse (unknown function\mathsc): \mathsc N
be the ω-CPO of partially defined functions on the natural numbers. We define a function Failed to parse (unknown function\mathsc): \phi:\mathsc N\to\mathsc N by sending some to a function k defined by
- k(0) = 1
- k(n) is defined only if h(n − 1) is defined, and then by k(n) = n * h(n − 1).
Describe Failed to parse (unknown function\maptso): \phi(n\maptso n^2)
and . Show that φ is continuous. Find a fixpoint (S_{0},f) of φ such that any other fixpoint of the same function is less than this one.
Find a continuous endofunction on some ω-CPO that has the fibonacci function F(0) = 0,F(1) = 1,F(n) = F(n − 1) + F(n − 2) as the least fixed point.