User:Michiexile/MATH198/Lecture 1

From HaskellWiki
Jump to navigation Jump to search

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.

Introduction

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.

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.

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

Category

Graphs

We recall the definition of a (directed) graph. A graph is a collection of edges (arrows) and vertices (nodes). Each edge is assigned a source node and a target node.

Given a graph , we denote the collection of nodes by and the collection of arrows by . 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 and 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:

By a path in a graph from the node to the node of length , we mean a sequence of edges such that:

  • for all other .

Paths with start and end point identical are called closed. For any node , there is a unique closed path starting and ending in of length 0.

For any edge , there is a unique path from to of length 1: .

We denote by the set of paths in of length .

Categories

  • A category is a graph equipped with an associative composition operation and an identity element for each node for this composition operation. The identity arrows may be viewed as being a function . Additional axioms are:
    1. Composition respects sources and targets, in that:
  • More on how we write compositions, and why the order is the way it is.
  • We denote by , or if is obvious from context, just , the set of all arrows from to . This is the hom-set, and may also be denoted .
  • 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
  • The categories and
  • The category Set of sets.
  • The catgeory FSet of finite sets.
  • The category PFn of sets and partial functions.
    • 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 -vector spaces and linear maps.
  • The category with objects the natural numbers and 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 , 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 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 (.).
    • 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 4 questions should be given no later than midnight before the next lecture.

  1. Prove the general associative law: that for any path, and any bracketing of that path, the same composition may be found.
  2. Suppose in some category .
    1. If for all in the category, then .
    2. If for all in the category, then .
    3. These two results characterize the objects in a category by the properties of their corresponding identity arrows completely.
  3. 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.
  4. For this question, all parts are required:
    1. For which sets is the free monoid on that set commutative.
    2. Prove that for any category , the set is a monoid under composition for every object .






Graphs and paths

A graph is a collection of vertices and a collection 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 to . In other words, each arrow has a source and a target.

We denote by the collection of arrows with source and target .

We extend the notation, and denote by the collection of all paths of length . Such a path is a sequence of arrows, such that for each , .

Definition of a category

A category is a graph with some special structure:

  • Each 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 has a dedicated arrow with source and target , 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, . This will make more sense once we get around to generalized elements later on.

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 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.