Categories and Logic Programming LSV, October 2016 Logic Programming A Category - Theoretic Framework James Lipton (Wesleyan)
I Categories
A category is a directed graph whose nodes are called objects and whose edges are called arrows , equipped with a partial operation on arrows called composition satisfying the following conditions id A ✲ A called the ◮ For each object A there is an arrow A identity arrow on A . f ✲ B , B g ✲ C ◮ For each compatible pair of arrows A fg ✲ C (meaning src ( g ) = target ( f )) there is an arrow A called the composition of f and g ◮ composition (when defined) is associative: ( fg ) h = f ( gh ) f ✲ A , A g ✲ C ◮ For all objects A , B , C , and arrows C f id A = f id A g = g
Examples ◮ Set : the category with sets as objects and functions as arrows. ◮ Ab: objects: Abelian Groups, arrows: group homomorphisms ◮ Grp: objects: Groups, arrows: group homomorphisms ◮ Top: objects: Topological Spaces, arrows: continuous maps ◮ A × B : objects: pairs ( A , B ) ∈ | A | × | B | , arrows: pairs of arrows from A , B . ◮ 1 , the category with one object and one arrow. ✲ · with two objects, their identity arrows ◮ 2 , the category · and one arrow between them.
More examples R ✲ B . ◮ Rel: objects: sets, arrows: binary relations A ◮ A o : The opposite category of A . objects: the objects of A , f o ✲ A for each A f ✲ B . So for arrows: B g o f o f ✲ B g ✲ C we have C ✲ B ✲ A A with g o f o = ( fg ) o and id o = id . ◮ Graph: objects: Graphs, arrows: graph homomorphisms.
An important example: the slice category Let C be a category, and A an object of C . Then the slice of C by A (or C over A ), written C / A , is the category with ◮ objects: arrows of C whose target is A . β ✲ A to C γ ✲ A are arrows f in C from ◮ arrows: from B B to C making the following diagram commute f ✲ C B β γ ✲ ✛ A Reversing the arrows gives rise to the coslice A / C .
✲ C / A . (send B to Note that there is a natural functor C r ✲ A ) Action on arrows?. B × A
Some categorical notions ◮ A terminal object in C is an object (called 1 ) such that for ! ✲ 1 . every other object A there is a unique arrow A ◮ A coterminal (or initial) object 0 in B satisfies the dual ? ✲ A property: for any object A there is a unique arrow 0 What are the initial and terminal objects in Set, Rel, C / A ?
Monic and Epic Arrows m ✲ B in a category is monic if for every pair of ◮ An arrow A arrows x ✲ m ✲ B ✲ A • y if xm = ym then x = y . e ✲ B in a category is epic if for every pair of ◮ An arrow A arrows x ✲ e ✲ B ✲ • A y if mx = my then x = y .
In Set epis are precisely the surjections, and monos the injections. Not necessarily so in other concrete categories. e.g. in the category ✲ Z . It’s an epi!. ⊆ Mon of Monoids. Consider containment N
Products and Coproducts A product of two objects A and B in a category is an object A × B together with a diagram A ✛ l r ✲ B (or just the triple A × B ( A × B , l , r )) satisfying the following condition. For every object C and pair of arrows A ✛ f g ✲ B there is a unique arrow C ✲ A × B making the following diagram commute � f , g � : C C g f ! � f , g � ✲ ✛ ❄ A ✛ ✲ B A × B l r
A coproduct of two objects A , B in category A is an object ι l ✲ A + B ✛ ι r together with a diagram A B satisfying the following condition For every object C and pair of arrows f ✲ C ✛ g B there is a unique arrow [ f , g ] : C ✛ A + B A making the following diagram commute C ✲ ✛ ✻ g f ! [ f , g ] ✲ ✛ A A + B B ι l ι r
Let A be a category with products and let A , B be objects of A and C be the category whose objects are diagrams of the form A ✛ f g ✲ B . with an arrow C ( A ✛ f g ✲ B ) ϕ ✲ ( A ✛ f ′ g ′ ✲ B ) defined to be an C ′ C ϕ ✲ C ′ of C making the induced diagram commute. arrow C What is the terminal object in this category?
Examples ◮ In Set, 0 is {} , 1 is {∗} , any one element set. ◮ In Set A × B is the Cartesian Product, A + B the disjoint union. ◮ in Rel, 0 is the same as in Set, which is also 1 Rel . ⋆ what is the product? (it’s not the cartesian product), coproduct? ◮ Top, the category of topological spaces and continuous maps has the sum (with the sum topology = the finest topology making the injections continuous) as a coproduct. The product is just the set-theoretic product together with the so-called product topology not the box topology.
Functors ✲ B is given by a pair Let A , B be categories. A functor F : A ✲ | B | and F : arr ( A ) ✲ arr ( B ) of functions F : | A | satisfying: f ✲ D ) F ( f ) ✲ F ( D ) F ( C = F ( C ) F ( fg ) = F ( f ) F ( g ) F ( id A ) = id F ( A )
Functors (cont) A contravariant functor from A to B is just a functor ✲ B . We take this to mean, for objects C , D in A F : A o f ✲ D ) F ( f ) ✲ F ( C ) F ( C = F ( D ) F ( fg ) = F ( g ) F ( f ) F ( id A ) = id F ( A )
Functors (cont) Cat, the category of categories has categories as objects and functors as arrows.
isos f ✲ B is an isomorphism if it An arrow between two objects A g ✲ A has both a left and right inverse, i.e. if there is an arrow B such that fg = id A and gf = id B . A functor can also be an isomorphism (it is an arrow in the category of categories). e.g. just as in Set we have A × 1 ≃ A ( A × B ) × C ≃ A × ( B × C ) A × B ≃ B × A
A “famous” functor: The fundamental group Functors formalize some important correspondences in mathematics. For example the homotopy group functior π ✲ Grp Top Sending topological spaces to homotopy - equivalent loop classes. Continuous maps between topological spaces are sent to group homomorphisms. This functor can be used to give a simple proof of Brouwer’s fixed point theorem
✲ D that does not fix any Suppose f is a continuous map D point x . ✬✩ � ✒ � � � • x ✫✪ � • f ( x ) g ✲ ∂ D send each point x to the point on the boundary Let D picked out by the vector shown above.
The function g is continuous and maps each point on the boundary to itself. ✲ D S 1 ⊂ g i d ✲ ✛ S 1
The induced diagram cannot commute. Contradiction. ✲ π ( D ) = { 0 } Z = π ( S 1 ) ) g ( π id ✲ ✛ Z = π ( S 1 )
Some algebraic examples ◮ Any monoid can be viewed as a one object category. Functors between them are monoid homomorphisms. ◮ Similarly groups are one-object categories with all arrows isomorphisms. ◮ Posets are categories with at most one arrow between objects (and the identity arrow on each).
Comma categories The slice is a special case of the comma category construction: Let A , B and C be categories with functors ✲ C and G : B ✲ C . F : A An object in the comma category ( F ↓ G ) is an arrow from F ( A ) to G ( B ) for some objects A , B . An arrow between two objects u , v is a pair of arrows f , g (of the appropriate type) making the following digram commute. F ( f ) ✲ F ( A ′ ) F ( A ) u v ❄ ❄ ✲ G ( B ′ ) G ( B ) G ( g ) The slice C / A is a special case: ( 1 C ↓ λ x . A ).
Natural Transformations There is a natural way to define a mapping from one functor to ✲ B . A natural another (with the same type). Let F , G : A transformation α from F to G is a family of arrows ✲ G ( X ) | X ∈ | A |} in B , one for each object X of A { α X : F ( X ) satisfying the following “naturality condition”: For each arrow m ✲ Y in A the following diagram commutes. X α X ✲ G ( X ) F ( X ) F ( m ) G ( m ) ❄ ❄ α Y ✲ G ( Y ) F ( Y )
Functor categories Given two categories A , B we can the define the functor category B A with objects: Functors from A to B arrows: Natural transformations from one functor to another.
Functor Categories (cont) Many interesting mathematical structures arise as functor categories. Let M be a monoid defined as a one-object category. Then Set M is the category of M -sets, or semigroup actions . That is to say, each object (i.e. functor) F picks out a set F ( • ) and a closed family of functions on this set. We can define, for x ∈ F ( • ), m ∈ M xm := F ( m )( x ) Then it is easy to check that functoriality of F guarantees the monoid action axioms: x ( m 1 m 2 ) = ( xm 1 ) m 2 xid • = x Natural transformations η between M -sets are M -homomorphisms: η ( xm ) = η ( x ) m . A group acting on a set is similarly formalized as a functor category.
Functor Categories (cont) The functor category Set • 1 ✲ ✲ • 2 can be seen as the category of graphs . Each object is essentially a pair of sets (edges and nodes) with a pair of maps between them, namely the src and target maps. A natural transformation α between two objects F and G in this category is a pair of maps, α edge , α node satisfying α edge ✲ Edge G Edge F src F src G ❄ ❄ α node ✲ Node G Node F and the same commutativity for the target map. α is a graph homomorphism.
More on functor cats and natural transformations A nice ⋆ exercise: For any categories A , B and C , A 1 ≃ A C A × B ≃ ( C B ) A ( A × B ) C ≃ A C × B C
Recommend
More recommend