https://wiki.haskell.org/api.php?action=feedcontributions&user=Michiexile&feedformat=atom HaskellWiki - User contributions [en] 2021-07-31T19:12:32Z User contributions MediaWiki 1.27.4 https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198&diff=36339 User:Michiexile/MATH198 2010-07-24T05:51:12Z <p>Michiexile: </p> <hr /> <div>==Course overview==<br /> <br /> Page is the background material for the Fall 2009 lecture course MATH198[http://coursework.stanford.edu/homepage/F09/F09-MATH-198-01.html] on Category Theory and Functional Programming that I gave at Stanford University.<br /> <br /> Single unit course. 10 lectures. Each lecture is Wednesday 4.15-5.05 in 380F.<br /> <br /> <br /> * [[User:Michiexile/MATH198/Lecture 1]]<br /> ** Category: Definition and examples.<br /> ** Concrete categories.<br /> *** Set.<br /> *** Various categories capturing linear algebra.<br /> ** Small categories.<br /> *** Partial orders.<br /> *** Monoids.<br /> *** Finite groups.<br /> ** Haskell-Curry isomorphism.<br /> <br /> <br /> * [[User:Michiexile/MATH198/Lecture 2]]<br /> ** Special morphisms<br /> *** Epimorphism.<br /> *** Monomorphism.<br /> *** Isomorphism.<br /> *** Endomorphism.<br /> *** Automorphism.<br /> ** Special objects<br /> *** Initial. <br /> *** Terminal. <br /> *** Null.<br /> <br /> * [[User:Michiexile/MATH198/Lecture 3]]<br /> ** Functors.<br /> ** Category of categories.<br /> ** Natural transformations.<br /> <br /> * [[User:Michiexile/MATH198/Lecture 4]]<br /> ** Products, coproducts.<br /> ** The power of dualization.<br /> ** The algebra of datatypes<br /> <br /> <br /> * [[User:Michiexile/MATH198/Lecture 5]]<br /> ** Limits, colimits.<br /> <br /> * [[User:Michiexile/MATH198/Lecture 6]]<br /> ** Equalizers, coequalizers.<br /> ** Pushouts/pullbacks<br /> ** Adjunctions.<br /> ** Free and forgetful.<br /> <br /> <br /> * [[User:Michiexile/MATH198/Lecture 7]]<br /> ** Monoid objects.<br /> ** Monads.<br /> ** Triples.<br /> ** Kleisli category.<br /> ** Monad factorization.<br /> <br /> * [[User:Michiexile/MATH198/Lecture 8]]<br /> ** Algebras over monads<br /> ** Algebras over endofunctors<br /> ** Initial algebras and recursion<br /> ** Lambek's lemma<br /> <br /> * [[User:Michiexile/MATH198/Lecture 9]]<br /> ** Catamorphisms<br /> ** Anamorphisms<br /> ** Hylomorphisms<br /> ** Metamorphisms<br /> ** Paramorphisms<br /> ** Apomorphisms<br /> ** Properties of adjunctions, examples of adjunctions<br /> <br /> * [[User:Michiexile/MATH198/Lecture 10]]<br /> ** Power objects<br /> ** Classifying objects<br /> ** Topoi<br /> ** Internal logic</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_2&diff=32219 User:Michiexile/MATH198/Lecture 2 2009-12-07T06:10:53Z <p>Michiexile: </p> <hr /> <div>This lecture covers material occurring in Awodey sections 2.1-2.4. <br /> <br /> ===Morphisms and objects===<br /> <br /> Some morphisms and some objects are special enough to garner special names that we will use regularly.<br /> <br /> In morphisms, the important properties are<br /> * cancellability - the categorical notion corresponding to properties we use when solving, e.g., equations over &lt;math&gt;\mathbb N&lt;/math&gt;:<br /> ::&lt;math&gt;3x = 3y \Rightarrow x = y&lt;/math&gt;<br /> :See also Wikipedia [http://en.wikipedia.org/wiki/Cancellation_property], where the relevant definitions and some interesting keywords occur. The article is technical and terse, though.<br /> * existence of inverses - which is stronger than cancellability. If there are inverses around, this implies cancellability, by applying the inverse to remove the common factor. Cancellability, however, does not imply that inverses exist: we can cancel the 3 above, but this does not imply the existence of &lt;math&gt;1/3\in\mathbb N&lt;/math&gt;.<br /> <br /> Thus, we'll talk about isomorphisms - which have two-sided inverses, monomorphisms and epimorphisms - which have cancellability properties, and split morphisms - which are mono's and epi's with correspodning one-sided inverses. We'll talk about what these concepts - defined in terms of equationsolving with arrows - apply to more familiar situations. And we'll talk about how the semantics of some of the more wellknown ideas in mathematics are captured by these notions.<br /> <br /> For objects, the properties are interesting in what happens to homsets with the special object as source or target. An empty homset is pretty boring, and a ''large'' homset is pretty boring. The real power, we find, is when ''all'' homsets with the specific source or target are singleton sets. This allows us to formulate the idea of a 0 in categorical terms, as well as capturing the roles of the empty set and of elements of sets - all using only arrows.<br /> <br /> ===Isomorphisms===<br /> <br /> An arrow &lt;math&gt;f:A\to B&lt;/math&gt; in a category &lt;math&gt;C&lt;/math&gt; is an ''isomorphism'' if it has a twosided inverse &lt;math&gt;g&lt;/math&gt;. In other words, we require the existence of a &lt;math&gt;g:B\to A&lt;/math&gt; such that &lt;math&gt;fg=1_B&lt;/math&gt; and &lt;math&gt;gf=1_A&lt;/math&gt;. <br /> <br /> ====In Set====<br /> <br /> In a category of sets with structure with morphisms given by functions that respect the set structure, isomorphism are bijections respecting the structure. In the category of sets, the isomorphisms are bijections.<br /> <br /> In wikipedia: [http://en.wikipedia.org/wiki/Bijection]<br /> <br /> ====Representative subcategories====<br /> <br /> Very many mathematical properties and invariants are interesting because they hold for objects regardless of how, exactly, the object is built. As an example, most set theoretical properties are concerned with how large the set is, but not what the elements really are.<br /> <br /> If all we care about are our objects up to isomorphisms, and how they relate to each other - we might as well restrict ourselves to one object for each isomorphism class of objects.<br /> <br /> Doing this, we get a ''representative subcategory'': a subcategory such that every object of the supercategory is isomorphic to some object in the subcategory. <br /> <br /> The representative subcategory ends up being a more categorically interesting concept than the idea of a wide subcategory: it doesn't hit every object in the category, but it hits every object worth hitting in order to capture all the structure.<br /> <br /> '''Example''' The category of finite sets has a representative subcategory given by all sets &lt;math&gt;[n]=\{1,\ldots,n\}&lt;/math&gt;.<br /> <br /> ====Groupoids====<br /> <br /> A ''groupoid'' is a category where ''all'' morphisms are isomorphisms. The name originates in that a groupoid with one object is a bona fide group; so that groupoids are the closest equivalent, in one sense, of groups as categories.<br /> <br /> A very rich starting point is the wikipedia page [http://en.wikipedia.org/wiki/Groupoid]. In the categorical definition on this page, the difference to a category is in the existence and properties of the function inv.<br /> <br /> ===Monomorphisms===<br /> <br /> We say that an arrow &lt;math&gt;f&lt;/math&gt; is ''left cancellable'' if for any arrows &lt;math&gt;g_1,g_2&lt;/math&gt; we can show &lt;math&gt;fg_1 = fg_2 \Rightarrow g_1=g_2&lt;/math&gt;. In other words, it is left cancellable, if we can remove it from the far left of any equation involving arrows.<br /> <br /> We call a left cancellable arrow in a category a ''monomorphism''.<br /> <br /> ====In Set====<br /> <br /> Left cancellability means that if, when we do first &lt;math&gt;g_1&lt;/math&gt; and then &lt;math&gt;f&lt;/math&gt; we get the same as when we do first &lt;math&gt;g_2&lt;/math&gt; and then &lt;math&gt;f&lt;/math&gt;, then we had equality already before we followed with &lt;math&gt;f&lt;/math&gt;.<br /> <br /> In other words, when we work with functions on sets, &lt;math&gt;f&lt;/math&gt; doesn't introduce relations that weren't already there. Anything non-equal before we apply &lt;math&gt;f&lt;/math&gt; remains non-equal in the image. This, translated to formulae gives us the well-known form for ''injectivity'':<br /> ::&lt;math&gt;x\neq y\Rightarrow f(x)\neq f(y)&lt;/math&gt; or moving out the negations,<br /> ::&lt;math&gt;f(x)=f(y) \Rightarrow x=y&lt;/math&gt;.<br /> <br /> In Wikipedia: [http://en.wikipedia.org/wiki/Injective_function].<br /> <br /> ====Subobjects====<br /> <br /> Consider the subset &lt;math&gt;\{1,2\}\subset\{1,2,3\}&lt;/math&gt;. This is the image of an accordingly chosen injective map from any 2-element set into &lt;math&gt;\{1,2,3\}&lt;/math&gt;. Thus, if we want to translate the idea of a subset into categorical language, it is not enough talking about monomorphisms, though the fact that inclusion is an injection indicates that we are on the right track. <br /> <br /> The trouble that remains is that we do not want to view &lt;math&gt;\{1,2\}&lt;/math&gt; as different subsets when it occurs as an image of the 2-element set &lt;math&gt;\{1,2\}&lt;/math&gt; or when it occurs as an image of the 2-element set &lt;math&gt;\{5,6\}&lt;/math&gt;. So we need some way of figuring out how to catch these situations and parry for them.<br /> <br /> We'll say that a morphism &lt;math&gt;f&lt;/math&gt; ''factors through'' a morphism &lt;math&gt;g&lt;/math&gt; if there is some morphism &lt;math&gt;h&lt;/math&gt; such that &lt;math&gt;f=gh&lt;/math&gt;.<br /> <br /> We can also talk about a morphism &lt;math&gt;f:A\to C&lt;/math&gt; factoring through an ''object'' &lt;math&gt;B&lt;/math&gt; by requiring the existence of morphisms &lt;math&gt;g:A\to B, h:B\to C&lt;/math&gt; that compose to &lt;math&gt;f&lt;/math&gt;.<br /> <br /> Now, we can form an equivalence relation on monomorphisms into an object &lt;math&gt;A&lt;/math&gt;, by saying &lt;math&gt;f\sim g&lt;/math&gt; if &lt;math&gt;f&lt;/math&gt; factors through &lt;math&gt;g&lt;/math&gt; and &lt;math&gt;g&lt;/math&gt; factors through &lt;math&gt;f&lt;/math&gt;. The arrows implied by the factoring are inverse to each other, and the source objects of equivalent arrows are isomorphic.<br /> <br /> Equipped with this equivalence relation, we define a ''subobject'' of an object &lt;math&gt;A&lt;/math&gt; to be an equivalence class of monomorphisms.<br /> <br /> Wikipedia has an accurate exposition [http://en.wikipedia.org/wiki/Subobject].<br /> <br /> ===Epimorphisms===<br /> <br /> ''Right cancellability'', by duality, is the implication<br /> :&lt;math&gt;g_1f = g_2f \Rightarrow g_1 = g_2&lt;/math&gt;<br /> The name, here comes from that we can remove the right cancellable &lt;math&gt;f&lt;/math&gt; from the right of any equation it is involved in.<br /> <br /> A right cancellable arrow in a category is an ''epimorphism''.<br /> <br /> ====In Set====<br /> <br /> For epimorphims the interpretation in set functions is that whatever &lt;math&gt;f&lt;/math&gt; does, it doesn't hide any part of the things &lt;math&gt;g_1&lt;/math&gt; and &lt;math&gt;g_2&lt;/math&gt; do. So applying &lt;math&gt;f&lt;/math&gt; first doesn't influence the total available scope &lt;math&gt;g_1&lt;/math&gt; and &lt;math&gt;g_2&lt;/math&gt; have.<br /> <br /> In Wikipedia: [http://en.wikipedia.org/wiki/Surjective_function].<br /> <br /> ===More on factoring===<br /> <br /> In Set, and in many other categories, any morphism can be expressed by a factorization of the form &lt;math&gt;f=ip&lt;/math&gt; where &lt;math&gt;i&lt;/math&gt; is a monomorphism and &lt;math&gt;p&lt;/math&gt; is an epimorphism. For instance, in Set, we know that a function is surjective onto its image, which in turn is a subset of the domain, giving a factorization into an epimorphism - the projection onto the image - followed by a monomorphism - the inclusion of the image into the domain.<br /> <br /> A generalization of this situation is sketched out on the Wikipedia page for Factorization systems [http://en.wikipedia.org/wiki/Factorization_system]. <br /> ----<br /> <br /> Note that in Set, every morphisms that is both a mono and an epi is immediately an isomorphism. We shall see in the homework that the converse does not necessarily hold.<br /> <br /> ===Initial and Terminal objects===<br /> <br /> An object &lt;math&gt;0&lt;/math&gt; is ''initial'' if for every other object &lt;math&gt;C&lt;/math&gt;, there is a unique morphism &lt;math&gt;0\to C&lt;/math&gt;. Dually, an object &lt;math&gt;1&lt;/math&gt; is ''terminal'' if there is a unique morphism &lt;math&gt;C\to 1&lt;/math&gt;.<br /> <br /> First off, we note that the uniqueness above makes initial and terminal objects unique up to isomorphism whenever they exist: we shall perform the proof for one of the cases, the other is almost identical.<br /> <br /> '''Proposition''' Initial (terminal) objects are unique up to isomorphism.<br /> <br /> '''Proof''': Suppose &lt;math&gt;C&lt;/math&gt; and &lt;math&gt;C'&lt;/math&gt; are both initial (terminal). Then there is a unique arrow &lt;math&gt;C\to C'&lt;/math&gt; and a unique arrow &lt;math&gt;C'\to C&lt;/math&gt;. The compositions of these arrows are all endoarrows of one or the other. Since ''all'' arrows from (to) an initial (terminal) objects are unique, these compositions have to be the identity arrows. Hence the arrows we found between the two objects are isomorphisms. QED.<br /> <br /> * In Sets, the empty set is initial, and any singleton set is terminal.<br /> * In the category of Vector spaces, the single element vector space 0 is both initial and terminal. <br /> <br /> On Wikipedia, there is a terse definition, and a good range of examples and properties: [http://en.wikipedia.org/wiki/Initial_and_terminal_objects].<br /> <br /> Note that terminal objects are sometimes called ''final'', and are as such used in the formal logic specification of algebraic structures.<br /> <br /> ====Zero objects====<br /> <br /> This last example is worth taking up in higher detail. We call an object in a category a ''zero object'' if it is simultaneously initial and terminal. <br /> <br /> Some categories exhibit a richness of structure similar to the category of vectorspaces: all kernels exist (nullspaces), homsets are themselves abelian groups (or even vectorspaces), et.c. With the correct amount of richness, the category is called an ''Abelian category'', and forms the basis for ''homological algebra'', where techniques from topology are introduced to study algebraic objects.<br /> <br /> One of the core requirements for an Abelian category is the existence of zero objects in it: if a category does have a zero object &lt;math&gt;0&lt;/math&gt;, then for any &lt;math&gt;Hom(A,B)&lt;/math&gt;, the composite &lt;math&gt;A\to 0\to B&lt;/math&gt; is a uniquely determined member of the homset, and the addition on the homsets of an Abelian category has this particular morphism as its identity element.<br /> <br /> ====Pointless sets and generalized elements====<br /> <br /> Arrows to initial objects and from terminal objects are interesting too - and as opposed to the arrows from initial and to the terminals, there is no guarantee for these arrows to be uniquely determined. Let us start with arrows &lt;math&gt;A\to 0&lt;/math&gt; into initial objects.<br /> <br /> In the category of sets, such an arrow only exists if &lt;math&gt;A&lt;/math&gt; is already the empty set.<br /> <br /> In the category of all monoids, with monoid homomorphisms, we have a zero object, so such an arrow is uniquely determined.<br /> <br /> For arrows &lt;math&gt;1\to A&lt;/math&gt;, however, the situation is significantly more interesting. Let us start with the situation in Set. &lt;math&gt;1&lt;/math&gt; is some singleton set, hence a function from &lt;math&gt;1&lt;/math&gt; picks out one element as its image. Thus, at least in Set, we get an isomorphism of sets &lt;math&gt;A = Hom(1,A)&lt;/math&gt;.<br /> <br /> As with so much else here, we build up a general definition by analogy to what we see happening in the category of sets. Thus, we shall say that a ''global element'', or a ''point'', or a ''constant'' of an object &lt;math&gt;A&lt;/math&gt; in a category with terminal objects is a morphism &lt;math&gt;x:1\to A&lt;/math&gt;.<br /> <br /> This allows us to talk about elements without requiring our objects to even be sets to begin with, and thus reduces everything to a matter of just morphisms. This approach is fruitful both in topology and in Haskell, and is sometimes called ''pointless''.<br /> <br /> The important point here is that we can replace ''function application'' &lt;math&gt;f(x)&lt;/math&gt; by the already existing and studied ''function composition''. If a constant &lt;math&gt;x&lt;/math&gt; is just a morphism &lt;math&gt;x:1\to A&lt;/math&gt;, then the value &lt;math&gt;f(x)&lt;/math&gt; is just the composition &lt;math&gt;f\circ x:1\to A\to B&lt;/math&gt;. Note, also, that since &lt;math&gt;1&lt;/math&gt; is terminal, it has exactly one point.<br /> <br /> In the idealized Haskell category, we have the same phenomenon for constants, but slightly disguised: a global constant is 0-ary function. Thus the type declaration<br /> &lt;haskell&gt;<br /> x :: a<br /> &lt;/haskell&gt;<br /> can be understood as syntactic sugar for the type declaration<br /> &lt;haskell&gt;<br /> x :: () -&gt; a<br /> &lt;/haskell&gt;<br /> thus reducing everything to function types. <br /> <br /> ----<br /> <br /> Similarly to the ''global'' elements, it may be useful to talk about ''variable elements'', by which we mean non-specified arrows &lt;math&gt;f:T\to A&lt;/math&gt;. Allowing &lt;math&gt;T&lt;/math&gt; to range over all objects, and &lt;math&gt;f&lt;/math&gt; to range over all morphisms into &lt;math&gt;A&lt;/math&gt;, we are able to recover some of the element-centered styles of arguments we are used to. We say that &lt;math&gt;f&lt;/math&gt; is ''parametried over &lt;math&gt;T&lt;/math&gt;''.<br /> <br /> Using this, it turns out that &lt;math&gt;f&lt;/math&gt; is a monomorphism if for any variable elements &lt;math&gt;x,y:T\to A&lt;/math&gt;, if &lt;math&gt;x\neq y&lt;/math&gt; then &lt;math&gt;f\circ x\neq f\circ y&lt;/math&gt;.<br /> <br /> ===Internal and external hom===<br /> <br /> If &lt;math&gt;f:B\to C&lt;/math&gt;, then &lt;math&gt;f&lt;/math&gt; induces a set function &lt;math&gt;Hom(A,f):Hom(A,B)\to Hom(A,C)&lt;/math&gt; through &lt;math&gt;Hom(A,f)(g) = f\circ g&lt;/math&gt;. Similarly, it induces a set function &lt;math&gt;Hom(f,A):Hom(C,A)\to Hom(<br /> B,A)&lt;/math&gt; through &lt;math&gt;Hom(f,A)(g) = g\circ f&lt;/math&gt;.<br /> <br /> Using this, we have an occasionally enlightening <br /> <br /> '''Proposition''' An arrow &lt;math&gt;f:B\to C&lt;/math&gt; is<br /> # a monomorphism if and only if &lt;math&gt;Hom(A,f)&lt;/math&gt; is injective for every object &lt;math&gt;A&lt;/math&gt;.<br /> # an epimorphism if and only if &lt;math&gt;Hom(f,A)&lt;/math&gt; is injective for every object &lt;math&gt;A&lt;/math&gt;.<br /> # a split monomorphism if and only if &lt;math&gt;Hom(f,A)&lt;/math&gt; is surjective for every object &lt;math&gt;A&lt;/math&gt;.<br /> # a split epimorphism if and only if &lt;math&gt;Hom(A,f)&lt;/math&gt; is surjective for every object &lt;math&gt;A&lt;/math&gt;.<br /> # an isomorphism if and only if any one of the following equivalent conditions hold:<br /> ## it is both a split epi and a mono.<br /> ## it is both an epi and a split mono.<br /> ## &lt;math&gt;Hom(A,f)&lt;/math&gt; is bijective for every &lt;math&gt;A&lt;/math&gt;.<br /> ## &lt;math&gt;Hom(f,A)&lt;/math&gt; is bijective for every &lt;math&gt;A&lt;/math&gt;.<br /> <br /> ----<br /> <br /> For any &lt;math&gt;A,B&lt;/math&gt; in a category, the homset is a ''set'' of morphisms between the objects. For many categories, though, homsets may end up being objects of that category as well. <br /> <br /> As an example, the set of all linear maps between two fixed vector spaces is itself a vector space.<br /> <br /> Alternatively, the function type &lt;hask&gt;a -&gt; b&lt;/hask&gt; is an actual Haskell type, and captures the morphisms of the idealized Haskell category.<br /> <br /> We shall return to this situation later, when we are better equipped to give a formal scaffolding to the idea of having elements in objects in a category act as morphisms. For now, we shall introduce the notations &lt;math&gt;[A\to B]&lt;/math&gt; or &lt;math&gt;B^A&lt;/math&gt; to denote the ''internal'' hom - where the morphisms between two objects live as an object of the category. This distinguishes &lt;math&gt;B^A&lt;/math&gt; from &lt;math&gt;Hom(A,B)&lt;/math&gt;.<br /> <br /> To gain a better understanding of the choice of notation, it is worth noting that &lt;math&gt;|Hom_{Set}(A,B)|=|B|^{|A|}&lt;/math&gt;.<br /> <br /> ===Homework===<br /> <br /> Passing mark requires at least 4 of 11.<br /> <br /> # Suppose &lt;math&gt;g,h&lt;/math&gt; are two-sided inverses to &lt;math&gt;f&lt;/math&gt;. Prove that &lt;math&gt;g=h&lt;/math&gt;.<br /> # (requires some familiarity with analysis) There is a category with object &lt;math&gt;\mathbb R&lt;/math&gt; (or even all smooth manifolds) and with morphisms smooth (infinitely differentiable) functions &lt;math&gt;f:\mathbb R\to\mathbb R&lt;/math&gt;. Prove that being a bijection does not imply being an isomorphisms. Hint: What about &lt;math&gt;x\mapsto x^3?&lt;/math&gt;. Wikipedia definition of smoothness: [http://en.wikipedia.org/wiki/Smooth_function]. Moral of the definition is that all derivatives and derivatives of derivatives, et.c. are everywhere finite and continuous.<br /> # (try to do this if you don't do 2) In the category of posets, with order-preserving maps as morphisms, show that not all bijective homomorphisms are isomorphisms. See the notes for [[User:Michiexile/MATH198/Lecture 1|Lecture 1]] for details on posets and order-preserving maps, as well as wikipedia links.<br /> # Consider the partially ordered set &lt;math&gt;P&lt;/math&gt; as a category. Prove: every arrow is both monic and epic. Is every arrow thus an isomorphism?<br /> # What are the terminal and initial objects in a poset? Give an example each of a poset that has both, either and none. Give an example of a poset that has a zero object.<br /> # What are the terminal and initial objects in the category with objects graphs and morphisms graph homomorphisms? Definition of a graph and a graph homomorphism occurred in [[User:Michiexile/MATH198/Lecture 1|Lecture 1]].<br /> # Prove that if a category has one zero object, then all initial and all terminal objects are all isomorphic and they are all zero objects. <br /> # Prove that the composition of two monomorphisms is a monomorphism and that the composition of two epimorphisms is an epimorphism. If &lt;math&gt;g\circ f&lt;/math&gt; is monic, do any of &lt;math&gt;g,f&lt;/math&gt; have to be monic? If the composition is epic, do any of the factors have to be epic?<br /> # Verify that the equivalence relation used in defining subobjects really is an equivalence relation. Further verify that this fixes the motivating problem. <br /> # Describe a representative subcategory each of:<br /> #* The category of vectorspaces over the reals.<br /> #* The category formed by the preordered set of the integers &lt;math&gt;\mathbb Z&lt;/math&gt; and the order relation &lt;math&gt;a\leq b&lt;/math&gt; if &lt;math&gt;a|b&lt;/math&gt;. Recall that a preordered set is a set &lt;math&gt;P&lt;/math&gt; equipped with a relation &lt;math&gt;\leq&lt;/math&gt; that fulfills transitivity and reflexivity, but not necessarily anti-symmetry.<br /> # * An arrow &lt;math&gt;f:A\to A&lt;/math&gt; in a category &lt;math&gt;C&lt;/math&gt; is an ''idempotent'' if &lt;math&gt;f\circ f = f&lt;/math&gt;. We say that &lt;math&gt;f&lt;/math&gt; is a ''split idempotent'' if there is some &lt;math&gt;g:A\to B, h:B\to A&lt;/math&gt; such that &lt;math&gt;h\circ g=f&lt;/math&gt; and &lt;math&gt;g\circ h=1_B&lt;/math&gt;. Show that in Set, &lt;math&gt;f&lt;/math&gt; is idempotent if and only if its image equals its set of fixed points. Show that every idempotent in Set is split. Give an example of a category with a non-split idempotent.</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=32079 User:Michiexile/MATH198/Lecture 10 2009-12-02T18:21:17Z <p>Michiexile: </p> <hr /> <div>This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;/math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional programming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that opens up for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bot\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \wedge Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \vee Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\wedge = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;\vee = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. (Note that by admitting several universes, we arrive at a ''typed'' predicate logic, with basically no extra work.)<br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> We can now proceed to define all the familiar logic connectives one by one, using the topos setting. While doing this, we shall introduce the notation &lt;math&gt;t_A: A\to\Omega&lt;/math&gt; for the morphism &lt;math&gt;t_A = A\to 1\to^{true}\Omega&lt;/math&gt; that takes on the value ''true'' on all of A. We note that with this convention, &lt;math&gt;\chi_{A_0}&lt;/math&gt;, the characteristic morphism of a subobject, is the arrow such that &lt;math&gt;\chi_{A_0}\circ i = t_{A_0}&lt;/math&gt;.<br /> <br /> '''Conjunction''': <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we need to define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; as some &lt;math&gt;P\wedge Q: U\to\Omega&lt;/math&gt; that corresponds to both &lt;math&gt;P&lt;/math&gt; and &lt;math&gt;Q&lt;/math&gt; simultaneously.<br /> <br /> We may define &lt;math&gt;true\times true: 1\to\Omega\times\Omega&lt;/math&gt;, a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Being a subobject, this has a characteristic arrow &lt;math&gt;\wedge:\Omega\times\Omega\to\Omega&lt;/math&gt;, that we call the ''conjunction arrow''.<br /> <br /> Now, we may define &lt;math&gt;\chi_P\times\chi_Q:U\to\Omega\times\Omega&lt;/math&gt; for subobjects &lt;math&gt;P,Q\subseteq U&lt;/math&gt; - and we take their composition &lt;math&gt;\wedge\circ\chi_P\times\chi_Q&lt;/math&gt; to be the characteristic arrow of the subobject &lt;math&gt;P\wedge Q&lt;/math&gt;.<br /> <br /> And, indeed, this results in a topoidal version of intersection of subobjects.<br /> <br /> '''Implication''': <br /> Next we define &lt;math&gt;\leq_1: \Omega_1\to\Omega\times\Omega&lt;/math&gt; to be the equalizer of &lt;math&gt;\wedge&lt;/math&gt; and &lt;math&gt;proj_1&lt;/math&gt;. Given &lt;math&gt;v, w: U\to\Omega&lt;/math&gt;, we write &lt;math&gt;v\leq_1 w&lt;/math&gt; if &lt;math&gt;v\times w&lt;/math&gt; factors through &lt;math&gt;\leq_1&lt;/math&gt;.<br /> <br /> Using the definition of an equalizer we arrive at &lt;math&gt;v\leq_1 w&lt;/math&gt; iff &lt;math&gt;v = v\wedge w&lt;/math&gt;. From this, we can deduce<br /> :&lt;math&gt;u\leq_1 true&lt;/math&gt;<br /> :&lt;math&gt;u\leq_1 u&lt;/math&gt;<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 w&lt;/math&gt; then &lt;math&gt;u\leq_1 w&lt;/math&gt;.<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 u&lt;/math&gt; then &lt;math&gt;u=v&lt;/math&gt;<br /> and thus, &lt;math&gt;\leq_1&lt;/math&gt; is a partial order on &lt;math&gt;[U\to\Omega]&lt;/math&gt;. Intuitively, &lt;math&gt;u\leq_1 v&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is at least as true as &lt;math&gt;u&lt;/math&gt;.<br /> <br /> This relation corresponds to inclusion on subobjects. Note that &lt;math&gt;\leq_1:\Omega_1\to\Omega\times\Omega&lt;/math&gt;, given from the equalizer, gives us &lt;math&gt;\Omega_1&lt;/math&gt; as a ''relation'' on &lt;math&gt;\Omega&lt;/math&gt; - a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Specifically, it has a classifying arrow &lt;math&gt;\Rightarrow:\Omega\times\Omega\to\Omega&lt;/math&gt;. We write &lt;math&gt;h\Rightarrow k = (\Rightarrow)\circ h\times k&lt;/math&gt;. And for subobjects &lt;math&gt;P,Q\subseteq A&lt;/math&gt;, we write &lt;math&gt;P\Rightarrow Q&lt;/math&gt; for the subobject classified by &lt;math&gt;\chi_P\Rightarrow\chi_Q&lt;/math&gt;.<br /> <br /> It turns out, without much work, that this &lt;math&gt;P\Rightarrow Q&lt;/math&gt; behaves just like classical implication in its relationship to &lt;math&gt;\wedge&lt;/math&gt;.<br /> <br /> '''Membership''': <br /> We can internalize the notion of ''membership'' as a subobject &lt;math&gt;\in^U\subseteq U\times\Omega^U&lt;/math&gt;, and thus get the membership relation from a pullback:<br /> :[[Image:ToposMembershipPullback.png]]<br /> <br /> For elements &lt;math&gt;x\times h: 1\to U\times\Omega^U&lt;/math&gt;, we write &lt;math&gt;x\in^U h&lt;/math&gt; for &lt;math&gt;x\times h\in\in^U&lt;/math&gt;. Yielding a subset of the product &lt;math&gt;U\times\Omega^U&lt;/math&gt;, this is readily interpretable as a relation relating things in &lt;math&gt;U&lt;/math&gt; with subsets of &lt;math&gt;U&lt;/math&gt;, so that for any &lt;math&gt;x,h&lt;/math&gt; we can answer whether &lt;math&gt;x\in^Uh&lt;/math&gt;. Both notations indicate &lt;math&gt;ev_A\circ h\times x = true&lt;/math&gt;.<br /> <br /> '''Universal quantification''':<br /> For any object &lt;math&gt;U&lt;/math&gt;, the maximal subobject of &lt;math&gt;U&lt;/math&gt; is &lt;math&gt;U&lt;/math&gt; itself, embedded with &lt;math&gt;1_U&lt;/math&gt; into itself. There is an arrow &lt;math&gt;\tau_U:1\to\Omega^U&lt;/math&gt; represents this subobject. Being a map from &lt;math&gt;1&lt;/math&gt;, it is specifically monic, so it has a classifying arrow &lt;math&gt;\forall_U:\Omega^U\to\Omega&lt;/math&gt; that takes a given subobject of &lt;math&gt;U&lt;/math&gt; to &lt;math&gt;true&lt;/math&gt; precisely if it is in fact the maximal subobject.<br /> <br /> Now, with a relation &lt;math&gt;r:R\to B\times A&lt;/math&gt;, we define &lt;math&gt;\forall a. R&lt;/math&gt; by the following pullback:<br /> :[[Image:ToposForallPullback.png]]<br /> where &lt;math&gt;\lambda\chi_R&lt;/math&gt; comes from the universal property of the exponential.<br /> <br /> '''Theorem''' For any &lt;math&gt;s:S\to B&lt;/math&gt; monic, &lt;math&gt;S\subseteq \forall a.R&lt;/math&gt; iff &lt;math&gt;S\times A\subseteq R&lt;/math&gt;.<br /> <br /> This theorem tells us that the subobject given by &lt;math&gt;\forall a.R&lt;/math&gt; is the largest subobject of &lt;math&gt;B&lt;/math&gt; that is related by &lt;math&gt;R&lt;/math&gt; to all of &lt;math&gt;A&lt;/math&gt;.<br /> <br /> '''Falsum''':<br /> We can define the ''false'' truth value using these tools as &lt;math&gt;\forall w\in\Omega.w&lt;/math&gt;. This might be familiar to the more advanced Haskell type hackers - as the type <br /> &lt;haskell&gt;<br /> x :: forall a. a<br /> &lt;/haskell&gt;<br /> which has to be able to give us an element of any type, regardless of the type itself. And in Haskell, the only element that inhabits all types is &lt;hask&gt;undefined&lt;/hask&gt;.<br /> <br /> From a logical perspective, we use a few basic inference rules:<br /> :[[Image:ToposTrivialSequent.png]] [[Image:ToposForallConnective.png]] [[Image:ToposSubstitution.png]]<br /> and connect them up to derive<br /> :[[Image:ToposFalsumDerivation.png]]<br /> for any &lt;math&gt;\phi&lt;/math&gt; not involving &lt;math&gt;w&lt;/math&gt; - and we can always adjust any &lt;math&gt;\phi&lt;/math&gt; to avoid &lt;math&gt;w&lt;/math&gt;.<br /> <br /> Thus, the formula &lt;math&gt;\forall w.w&lt;/math&gt; has the property that it implies everything - and thus is a good candidate for the ''false'' truth value; since the inference<br /> :[[Image:ToposExFalsoQuodlibet.png]]<br /> is the defining introduction rule for false.<br /> <br /> <br /> '''Negation''':<br /> We define negation the same way as in classical logic: &lt;math&gt;\neg \phi = \phi \Rightarrow false&lt;/math&gt;.<br /> <br /> <br /> '''Disjunction''':<br /> We can define <br /> :&lt;math&gt;P\vee Q = \forall w. ((\phi\Rightarrow w)\wedge(\psi\Rightarrow w))\Rightarrow w&lt;/math&gt;<br /> <br /> Note that this definition uses one of our primary inference rules:<br /> :[[Image:ToposDisjunctionConnective.png]]<br /> as the defining property for the disjunction, and we may derive any properties we like from these.<br /> <br /> '''Existential quantifier''':<br /> Finally, the existential quantifier is derived similarly to the disjunction - by figuring out a rule we want it to obey, and using that as a definition for it:<br /> :&lt;math&gt;\exists x.\phi = \forall w. (\forall x. \phi \Rightarrow w)\Rightarrow w&lt;/math&gt;<br /> <br /> Here, the rule we use as defining property is <br /> :[[Image:ToposExistsConnective.png]]<br /> <br /> Before we leave this exploration of logic, some properties worth knowing about:<br /> While we can prove &lt;math&gt;\neg(\phi\wedge\neg\phi)&lt;/math&gt; and &lt;math&gt;\phi\Rightarrow\neg\neg\phi&lt;/math&gt;, we cannot, in just topos logic, prove things like<br /> :&lt;math&gt;\neg(\phi\wedge\psi)\Rightarrow(\neg\phi\vee\neg\psi)&lt;/math&gt;<br /> :&lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt;<br /> nor any statements like<br /> :&lt;math&gt;\neg(\forall x.\neg\phi)\Rightarrow(\exists x.\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\forall x.\phi)\Rightarrow(\exists x.\neg\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\exists x.\neg\phi)\Rightarrow(\forall x.\phi)&lt;/math&gt;<br /> We can, though, prove<br /> :&lt;math&gt;\neg(\exists x.\phi)\Rightarrow(\forall x.\neg\phi)&lt;/math&gt;<br /> <br /> If we include, extra, an additional inference rule (called the ''Boolean negation rule'') given by<br /> :[[Image:BooleanNegation.png]]<br /> then suddenly we're back in classical logic, and can prove &lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt; and &lt;math&gt;\phi\or\neg\phi&lt;/math&gt;.<br /> <br /> ====Examples: Sheaves, topology and time sheaves====<br /> <br /> The first interesting example of a topos is the category of (small enough) sets; in some sense clear already since we've been modelling our axioms and workflows pretty closely on the theory of sets.<br /> <br /> Generating logic and set theory in the topos of sets, we get a theory that captures several properties of ''intuitionistic logic''; such as the lack of Boolean negation, of exclusion of the third, and of double negation rules.<br /> <br /> For the more interesting examples, however, we shall introduce the concepts of ''topology'' and of ''sheaf'':<br /> <br /> '''Definition''' A (set-valued) ''presheaf'' on a category &lt;math&gt;C&lt;/math&gt; is a contravariant functor &lt;math&gt;E: C^{op}\to Set&lt;/math&gt;.<br /> <br /> Presheaves occur all over the place in geometry and topology - and occasionally in computer science too: There is a construction in which a functor &lt;math&gt;A\to Set&lt;/math&gt; for a discrete small category &lt;math&gt;A&lt;/math&gt; identified with its underlying set of objects as a set, corresponds to the data type of ''bags'' of elements from &lt;math&gt;A&lt;/math&gt; - for &lt;math&gt;a\in A&lt;/math&gt;, the image &lt;math&gt;F(a)&lt;/math&gt; denotes the multiplicity of &lt;math&gt;a&lt;/math&gt; in the bag.<br /> <br /> '''Theorem''' The category of all presheaves (with natural transformations as the morphisms) on a category &lt;math&gt;C&lt;/math&gt; form a topos.<br /> <br /> '''Example''' Pick a category on the shape<br /> :[[Image:GraphsAsPresheaves.png]]<br /> A contravariant functor on this category is given by a pair of sets &lt;math&gt;G_0, G_1&lt;/math&gt; and a pair of function &lt;math&gt;source, target: G_1\to G_0&lt;/math&gt;. Identities are sent to identities.<br /> <br /> The category of presheaves on this category, thus, is the category of graphs. Thus graphs form a topos.<br /> <br /> The subobject classifier in the category of graphs is a graph with two nodes: in and out, and five arrows:<br /> :&lt;math&gt;in \to^{all} in&lt;/math&gt;<br /> :&lt;math&gt;in \to^{both} in&lt;/math&gt;<br /> :&lt;math&gt;in \to^{source} out&lt;/math&gt;<br /> :&lt;math&gt;out \to^{target} in&lt;/math&gt;<br /> :&lt;math&gt;out \to^{neither} out&lt;/math&gt;<br /> Now, given a subgraph &lt;math&gt;H \leq G&lt;/math&gt;, we define a function &lt;math&gt;\chi_H:G\to\Omega&lt;/math&gt; by sending nodes to in or out dependent on their membership. For an arrow &lt;math&gt;a&lt;/math&gt;, we send it to all if the arrow is in &lt;math&gt;H&lt;/math&gt;, and otherwise we send it to both/source/target/neither according to where its source and target reside.<br /> <br /> To really get into sheaves, though, we introduce more structure - specifically, we define what we mean by a ''topology'':<br /> <br /> '''Definition''' Suppose &lt;math&gt;P&lt;/math&gt; is a partially ordered set. We call &lt;math&gt;P&lt;/math&gt; a ''complete Heyting algebra'' if<br /> * There is a top element &lt;math&gt;1&lt;/math&gt; such that &lt;math&gt;x\leq 1 \forall x\in P&lt;/math&gt;.<br /> * Any two elements &lt;math&gt;x, y&lt;/math&gt; have an infimum (greatest lower bound) &lt;math&gt;x\wedge y&lt;/math&gt;.<br /> * Every subset &lt;math&gt;Q\subseteq P&lt;/math&gt; has a supremum (least upper bound) &lt;math&gt;\bigvee_{p\in P} p&lt;/math&gt;.<br /> * &lt;math&gt;x\wedge(\bigvee y_i) = \bigvee x\wedge y_i&lt;/math&gt;<br /> <br /> Note that for the partial order by inclusion of a family of subsets of a given set, being a complete Heyting algebra is the same as being a topology in the classical sense - you can take finite unions and any intersections of open sets and still get an open set. <br /> <br /> If &lt;math&gt;\{x_i\}&lt;/math&gt; is a subset with supremum &lt;math&gt;x&lt;/math&gt;, and &lt;math&gt;E&lt;/math&gt; is a presheaf, we get functions &lt;math&gt;e_i:E(x)\to E(x_i)&lt;/math&gt; from functoriality. We can summarize all these &lt;math&gt;e_i&lt;/math&gt; into &lt;math&gt;e = \prod_i e_i: E(x)\to\prod_i E(x_i)&lt;/math&gt;.<br /> <br /> Furthermore, functoriality gives us families of functions &lt;math&gt;c_{ij}: E(x_i)\to E(x_i\wedge x_j)&lt;/math&gt; and &lt;math&gt;d_{ij}: E(x_j)\to E(x_i\wedge x_j)&lt;/math&gt;. These can be collected into &lt;math&gt;c: \prod_i E(x_i)\to\prod_{ij}E(x_i\wedge x_j)&lt;/math&gt; and &lt;math&gt;d:\prod_j E(x_j)\to\prod_{ij}E(x_i\wedge x_j)&lt;/math&gt;.<br /> <br /> '''Definition''' A presheaf &lt;math&gt;E&lt;/math&gt; on a Heyting algebra is called a ''sheaf'' if it satisfies:<br /> :&lt;math&gt;x = \bigvee x_i&lt;/math&gt;<br /> implies that <br /> :[[Image:SheafEqualizer.png]]<br /> is an equalizer. If you have seen sheaves before, you may recognize this as the covering axiom.<br /> <br /> In other words, &lt;math&gt;E&lt;/math&gt; is a sheaf if whenever &lt;math&gt;x=\bigvee x_i&lt;/math&gt; and &lt;math&gt;c(\alpha) = d(\alpha)&lt;/math&gt;, then there is some &lt;math&gt;\bar\alpha&lt;/math&gt; such that &lt;math&gt;\alpha = e(\bar\alpha)&lt;/math&gt;.<br /> <br /> '''Theorem''' The category of sheaves on a Heyting algebra is a topos.<br /> <br /> For context, we can think of sheaves over Heyting algebras as sets in a logic with an expanded notion of truth. Our Heyting algebra is the collection of truth values, and the sheaves are the fuzzy sets with fuzziness introduced by the Heyting algebra.<br /> <br /> Recalling that subsets and predicates are viewed as the same thing, we can view the set &lt;math&gt;E(p)&lt;/math&gt; as the part of the fuzzy set &lt;math&gt;E&lt;/math&gt; that is at least &lt;math&gt;p&lt;/math&gt; true.<br /> <br /> As it turns out, to really make sense of this approach, we realize that ''equality'' is a predicate as well - and thus can hold or not depending on the truth value we use.<br /> <br /> '''Definition''' Let &lt;math&gt;P&lt;/math&gt; be a complete Heyting algebra. A ''&lt;math&gt;P&lt;/math&gt;-valued set'' is a pair &lt;math&gt;(S,\sigma)&lt;/math&gt; of a set &lt;math&gt;S&lt;/math&gt; and a function &lt;math&gt;\sigma: S\to P&lt;/math&gt;. A ''category of fuzzy sets'' is a category of &lt;math&gt;P&lt;/math&gt;-valued sets. A morphism &lt;math&gt;f:(S,\sigma)\to(T,\tau)&lt;/math&gt; of &lt;math&gt;P&lt;/math&gt;-valued sets is a function &lt;math&gt;f:S\to T&lt;/math&gt; such that &lt;math&gt;\tau\circ f = \sigma&lt;/math&gt;.<br /> <br /> From these definitions emerges a fuzzy set theory where all components of it being a kind of set theory emerges from the topoidal approach above. Thus, say, subsets in a fuzzy sense are just monics, thus are injective on the set part, and such that the valuation, on the image of the injection, increases from the previous valuation: &lt;math&gt;(T,\tau)\subseteq(S,\sigma)&lt;/math&gt; if &lt;math&gt;T\subseteq S&lt;/math&gt; and &lt;math&gt;\sigma|_T = \tau&lt;/math&gt;.<br /> <br /> To get to topoi, though, there are a few matters we need to consider. First, we may well have several versions of the empty set - either a bona fide empty set, or just a set where every element is never actually there. This issue is minor. Much more significant though, is that while we can easily make &lt;math&gt;(S,\sigma)&lt;/math&gt; give rise to a presheaf, by defining<br /> :&lt;math&gt;E(x) = \{s\in S: \sigma(s)\geq x\}&lt;/math&gt;<br /> this definition will not yield a sheaf. The reason for this boils down to &lt;math&gt;E(0) = S \neq 1&lt;/math&gt;. We can fix this, though, by adjoining another element - &lt;math&gt;\bot&lt;/math&gt; - to &lt;math&gt;P&lt;/math&gt; giving &lt;math&gt;P^+&lt;/math&gt;. The new element &lt;math&gt;\bot&lt;/math&gt; is imbued with two properties: it is smaller, in &lt;math&gt;P^+&lt;/math&gt;, than any other element, and it is mapped, by &lt;math&gt;E&lt;/math&gt; to &lt;math&gt;1&lt;/math&gt;.<br /> <br /> '''Theorem''' The construction above gives a fuzzy set &lt;math&gt;(S,\sigma)&lt;/math&gt; the structure of a sheaf on the augmented Heyting algebra.<br /> <br /> '''Corollary''' The category of fuzzy sets for a Heyting algebra &lt;math&gt;P&lt;/math&gt; forms a topos.<br /> <br /> '''Final note''' While this construction allows us to make ''membership'' a fuzzy concept, we're not really done fuzzy-izing sets. There are two fundamental predicates on sets: equality and membership. While fuzzy set theory, classically, only allows us to make one of these fuzzy, topos theory allows us - rather easily - to make both these predicates fuzzy. Not only that, but membership reduces - with the power object construction - to equality testing, by which the fuzzy set theory ends up somewhat inconsistent in its treatment of the predicates.<br /> <br /> ===Literature===<br /> <br /> At this point, I would warmly recommend the interested reader to pick up one, or more, of:<br /> * Steve Awodey: Category Theory<br /> * Michael Barr &amp; Charles Wells: Categories for Computing Science<br /> * Colin McLarty: Elementary Categories, Elementary Toposes<br /> <br /> or for more chewy books<br /> * Peter T. Johnstone: Sketches of an Elephant: a Topos Theory compendium<br /> * Michael Barr &amp; Charles Wells: Toposes, Triples and Theories<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # Prove the relations showing that &lt;math&gt;\leq_1&lt;/math&gt; is indeed a partial order on &lt;math&gt;[U\to\Omega]&lt;/math&gt;.<br /> # Prove the universal quantifier theorem.<br /> # The ''extension'' of a formula &lt;math&gt;\phi&lt;/math&gt; over a list of variables &lt;math&gt;x&lt;/math&gt; is the sub-object of the product of domains &lt;math&gt;A_1\times\dots\times A_n&lt;/math&gt; for the variables &lt;math&gt;x_1,\dots,x_n=x&lt;/math&gt; classified by the interpretation of &lt;math&gt;\phi&lt;/math&gt; as a morphism &lt;math&gt;A_1\times\dots\times A_n\to\Omega&lt;/math&gt;. A formula is ''true'' if it classifies the entire product. A ''sequent'', written &lt;math&gt;\Gamma:\phi&lt;/math&gt; is the statement that using the set of formulae &lt;math&gt;\Gamma&lt;/math&gt; we may prove &lt;math&gt;\phi&lt;/math&gt;, or in other words that the intersection of the extensions of the formulae in &lt;math&gt;\Gamma&lt;/math&gt; is contained in the extension of &lt;math&gt;\phi&lt;/math&gt;. If a sequent &lt;math&gt;\Gamma:\phi&lt;/math&gt; is true, we say that &lt;math&gt;\Gamma&lt;/math&gt; ''entails'' &lt;math&gt;\phi&lt;/math&gt;. (some of the questions below are almost embarrassingly immediate from the definitions given above. I include them anyway, so that a ''catalogue'' of sorts of topoidal logic inferences is included here)<br /> ## Prove the following entailments:<br /> ### Trivial sequent: &lt;math&gt;\phi:\phi&lt;/math&gt;<br /> ### True: &lt;math&gt;:true&lt;/math&gt; (note that true classifies the entire object)<br /> ### False: &lt;math&gt;false:\phi&lt;/math&gt; (note that false classifies the global minimum in thepreorder of subobjects)<br /> ## Prove the following inference rules:<br /> ### Implication: &lt;math&gt;\Gamma,\phi:\psi&lt;/math&gt; is equivalent to &lt;math&gt;\Gamma:\phi\Rightarrow\psi&lt;/math&gt;.<br /> ### Thinning: &lt;math&gt;\Gamma:\phi&lt;/math&gt; implies &lt;math&gt;\Gamma,\psi:\phi&lt;/math&gt;<br /> ### Cut: &lt;math&gt;\Gamma,\psi:\phi&lt;/math&gt; and &lt;math&gt;\Gamma:\psi&lt;/math&gt; imply &lt;math&gt;\Gamma:\phi&lt;/math&gt; if every variable free in &lt;math&gt;\psi&lt;/math&gt; is free in &lt;math&gt;\Gamma&lt;/math&gt; or in &lt;math&gt;\phi&lt;/math&gt;.<br /> ### Negation: &lt;math&gt;\Gamma, \phi: false&lt;/math&gt; is equivalent (implications both ways) to &lt;math&gt;\Gamma: \neg\phi&lt;/math&gt;.<br /> ### Conjunction: &lt;math&gt;\Gamma:\phi&lt;/math&gt; and &lt;math&gt;\Gamma:\psi&lt;/math&gt; together are equivalent to &lt;math&gt;\Gamma:\phi\wedge\psi&lt;/math&gt;.<br /> ### Disjunction: &lt;math&gt;\Gamma,\phi:\theta&lt;/math&gt; and &lt;math&gt;\Gamma,\psi:\theta&lt;/math&gt; together imply &lt;math&gt;\Gamma, \phi\vee\psi: \theta&lt;/math&gt;.<br /> ### Universal: &lt;math&gt;\Gamma:\phi&lt;/math&gt; is equivalent to &lt;math&gt;\Gamma:\forall x.\phi&lt;/math&gt; if &lt;math&gt;x&lt;/math&gt; is not free in &lt;math&gt;\Gamma&lt;/math&gt;.<br /> ### Existential: &lt;math&gt;\Gamma,\phi: \psi&lt;/math&gt; is equivalent to &lt;math&gt;\Gamma,\exists x.\phi:\psi&lt;/math&gt; if &lt;math&gt;x&lt;/math&gt; is not free in &lt;math&gt;\Gamma&lt;/math&gt; or &lt;math&gt;\psi&lt;/math&gt;.<br /> ### Equality: &lt;math&gt;:q=q&lt;/math&gt;.<br /> ### Biconditional: &lt;math&gt;(v\Rightarrow w)\wedge(w\Rightarrow v):v=w&lt;/math&gt;. We usually write &lt;math&gt;v\Leftrightarrow w&lt;/math&gt; for &lt;math&gt;v=w&lt;/math&gt; if &lt;math&gt;v,w:A\to\Omega&lt;/math&gt;.<br /> ### Product: &lt;math&gt;p_1u = p_1u', p_2u = p_2u' : u = u'&lt;/math&gt; for &lt;math&gt;u,u'\in A\times B&lt;/math&gt;.<br /> ### Product revisited: &lt;math&gt;:(p_1(s\times s')=s)\wedge(p_2(s\times s')=s')&lt;/math&gt;.<br /> ### Extensionality: &lt;math&gt;\forall x\in A. f(x) = g(x) : f = g&lt;/math&gt; for &lt;math&gt;f,g\in[A\to B]&lt;/math&gt;.<br /> ### Comprehension: &lt;math&gt;(\lambda x\in A. s)x = s&lt;/math&gt; for &lt;math&gt;x\in A&lt;/math&gt;.<br /> ## Prove the following results from the above entailments and inferences -- or directly from the topoidal logic mindset:<br /> ### &lt;math&gt;:\neg(\phi\wedge\neg\phi)&lt;/math&gt;.<br /> ### &lt;math&gt;:\phi\Rightarrow\neg\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;:\neg(\phi\vee\psi)\Rightarrow(\neg\phi\wedge\neg\psi)&lt;/math&gt;.<br /> ### &lt;math&gt;:(\neg\phi\wedge\neg\psi)\Rightarrow\neg(\phi\wedge\psi)&lt;/math&gt;.<br /> ### &lt;math&gt;:(\neg\phi\vee\neg\psi)\Rightarrow\neg(\phi\vee\psi)&lt;/math&gt;.<br /> ### &lt;math&gt;\phi\wedge(\theta\vee\psi)&lt;/math&gt; is equivalent to &lt;math&gt;(\phi\wedge\theta)\vee(\phi\wedge\psi)&lt;/math&gt;.<br /> ### &lt;math&gt;\forall x.\neg\phi&lt;/math&gt; is equivalent to &lt;math&gt;\neg\exists x.\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\exists x\phi\Rightarrow\neg\forall x.\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\exists x\neg\phi\Rightarrow\neg\forall x.\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\forall x\phi\Rightarrow\neg\exists x.\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\phi:\psi&lt;/math&gt; implies &lt;math&gt;\neg\psi:\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\phi:\psi\Rightarrow\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\phi\Rightarrow\not\phi:\not\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\not\phi\vee\psi:\phi\Rightarrow\psi&lt;/math&gt; (but not the converse!).<br /> ### &lt;math&gt;\neg\neg\neg\phi&lt;/math&gt; is equivalent to &lt;math&gt;\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;(\phi\wedge\psi)\Rightarrow\theta&lt;/math&gt; is equivalent to &lt;math&gt;\phi\Rightarrow(\psi\Rightarrow\theta)&lt;/math&gt; (currying!).<br /> ## Using the Boolean negation rule: &lt;math&gt;\Gamma,\neg\phi:false&lt;/math&gt; is equivalent to &lt;math&gt;\Gamma:\phi&lt;/math&gt;, prove the following additional results:<br /> ### &lt;math&gt;\neg\neg\phi:\phi&lt;/math&gt;.<br /> ### &lt;math&gt;:\phi\vee\neg\phi&lt;/math&gt;.<br /> ## Show that either of the three rules above, together with the original negation rule, implies the Boolean negation rule.<br /> ### The converses of the three existential/universal/negation implications above.<br /> ## The restrictions introduced for the cut rule above block the deduction of an entailment &lt;math&gt;:\forall x.\phi\Rightarrow\exists x.\phi&lt;/math&gt;. The issue at hand is that &lt;math&gt;A&lt;/math&gt; might not actually have members; so choosing one is not a sound move. Show that this entailment can be deduced from the premise &lt;math&gt;\exists x\in A. x=x&lt;/math&gt;.<br /> ## Show that if we extend our ruleset by the quantifier negation rule &lt;math&gt;\forall x\Leftrightarrow \neg\exists x.\neg&lt;/math&gt;, then we can derive the entailment &lt;math&gt;:\forall w: w=t \vee w = false&lt;/math&gt;. From this derive &lt;math&gt;:\phi\vee\neg\phi&lt;/math&gt; and hence conclude that this extension gets us Boolean logic again.<br /> # A ''topology'' on a topos &lt;math&gt;E&lt;/math&gt; is an arrow &lt;math&gt;j:\Omega\to\Omega&lt;/math&gt; such that &lt;math&gt;j\circ true=true&lt;/math&gt;, &lt;math&gt;j\circ j=j&lt;math&gt; and &lt;math&gt;j\circ\wedge = \wedge\circ j\times j&lt;/math&gt;. For a subobject &lt;math&gt;S\subseteq A&lt;/math&gt; with characteristic arrow &lt;math&gt;\chi_S:A\to\Omega&lt;/math&gt;, we define its &lt;math&gt;j&lt;/math&gt;-closure as the subobject &lt;math&gt;\bar S\subseteq A&lt;/math&gt; classified by &lt;math&gt;j\circ\chi_S&lt;/math&gt;.<br /> ## Prove:<br /> ### &lt;math&gt;S\subseteq\bar S&lt;/math&gt;.<br /> ### &lt;math&gt;\bar S = \bar{\bar S}&lt;/math&gt;.<br /> ### &lt;math&gt;\bar{S\cap T} = \bar S\cap\bar T&lt;/math&gt;.<br /> ### &lt;math&gt;S\subseteq T&lt;/math&gt; implies &lt;math&gt;\bar S\subseteq\bar T&lt;/math&gt;.<br /> ### &lt;math&gt;\bar{f^{-1}(S)} = f^{-1}(\bar S)&lt;/math&gt;.<br /> ## We define &lt;math&gt;S&lt;/math&gt; to be &lt;math&gt;j&lt;/math&gt;-closed if &lt;math&gt;S=\bar S&lt;/math&gt;. It is &lt;math&gt;j&lt;/math&gt;-dense if &lt;math&gt;\bar S=A&lt;/math&gt;. These terms are chosen due to correspondences to classical pointset topology for the topos of sheaves over some space. For a logical standpoint, it is more helpful to look at &lt;math&gt;j&lt;/math&gt; as a modality operator: &quot;''it is &lt;math&gt;j&lt;/math&gt;-locally true that''&quot; Given any &lt;math&gt;u:1\to\Omega&lt;/math&gt;, prove that the following are topologies:<br /> ### &lt;math&gt;(u\to -): \Omega\to\Omega&lt;/math&gt; (the ''open topology'', where such a &lt;math&gt;u&lt;/math&gt; in a sheaf topos ends up corresponding to an open subset of the underlying space, and the formulae picked out are true on at least all of that subset).<br /> ### &lt;math&gt;u\vee -): \Omega\to\Omega&lt;/math&gt; (the closed topology, where a formula is true if its disjunction with &lt;math&gt;u&lt;/math&gt; is true -- corresponding to formulae holding over at least the closed set complementing the subset picked out)<br /> ### &lt;math&gt;\neg\neg: \Omega\to\Omega&lt;/math&gt;. This may, depending on the topos, end up being interpreted as ''true so far as global elements are concerned'', or ''not false on any open set'', or other interpretations.<br /> ### &lt;math&gt;1_\Omega&lt;/math&gt;.<br /> ## For a topos &lt;math&gt;E&lt;/math&gt; with a topology &lt;math&gt;j&lt;/math&gt;, we define an object &lt;math&gt;A&lt;/math&gt; to be a ''sheaf'' iff for every &lt;math&gt;X&lt;/math&gt; and every &lt;math&gt;j&lt;/math&gt;-dense subobject &lt;math&gt;S\subseteq X&lt;/math&gt; and every &lt;math&gt;f:S\to A&lt;/math&gt; there is a unique &lt;math&gt;g:X\to A&lt;/math&gt; with &lt;math&gt;f=g\circ s&lt;/math&gt;. In other words, &lt;math&gt;A&lt;/math&gt; is an object that cannot see the difference between &lt;math&gt;j&lt;/math&gt;-dense subobjects and objects. We write &lt;math&gt;E_j&lt;/math&gt; for the full subcategory of &lt;math&gt;j&lt;/math&gt;-sheaves. <br /> ### Prove that any object is a sheaf for &lt;math&gt;1_\Omega&lt;/math&gt;.<br /> ### Prove that a subobject is dense for &lt;math&gt;\neg\neg&lt;/math&gt; iff its negation is empty. Show that &lt;math&gt;true+false:1+1\to\Omega&lt;/math&gt; is dense for this topology. Conclude that &lt;math&gt;1+1&lt;/math&gt; is dense in &lt;math&gt;\Omega_{\neg\neg}&lt;/math&gt; and thus that &lt;math&gt;E_{\neg\neg}&lt;/math&gt; is Boolean.</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=32078 User:Michiexile/MATH198/Lecture 10 2009-12-02T18:20:20Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;/math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional programming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that opens up for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bot\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \wedge Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \vee Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\wedge = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;\vee = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. (Note that by admitting several universes, we arrive at a ''typed'' predicate logic, with basically no extra work.)<br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> We can now proceed to define all the familiar logic connectives one by one, using the topos setting. While doing this, we shall introduce the notation &lt;math&gt;t_A: A\to\Omega&lt;/math&gt; for the morphism &lt;math&gt;t_A = A\to 1\to^{true}\Omega&lt;/math&gt; that takes on the value ''true'' on all of A. We note that with this convention, &lt;math&gt;\chi_{A_0}&lt;/math&gt;, the characteristic morphism of a subobject, is the arrow such that &lt;math&gt;\chi_{A_0}\circ i = t_{A_0}&lt;/math&gt;.<br /> <br /> '''Conjunction''': <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we need to define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; as some &lt;math&gt;P\wedge Q: U\to\Omega&lt;/math&gt; that corresponds to both &lt;math&gt;P&lt;/math&gt; and &lt;math&gt;Q&lt;/math&gt; simultaneously.<br /> <br /> We may define &lt;math&gt;true\times true: 1\to\Omega\times\Omega&lt;/math&gt;, a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Being a subobject, this has a characteristic arrow &lt;math&gt;\wedge:\Omega\times\Omega\to\Omega&lt;/math&gt;, that we call the ''conjunction arrow''.<br /> <br /> Now, we may define &lt;math&gt;\chi_P\times\chi_Q:U\to\Omega\times\Omega&lt;/math&gt; for subobjects &lt;math&gt;P,Q\subseteq U&lt;/math&gt; - and we take their composition &lt;math&gt;\wedge\circ\chi_P\times\chi_Q&lt;/math&gt; to be the characteristic arrow of the subobject &lt;math&gt;P\wedge Q&lt;/math&gt;.<br /> <br /> And, indeed, this results in a topoidal version of intersection of subobjects.<br /> <br /> '''Implication''': <br /> Next we define &lt;math&gt;\leq_1: \Omega_1\to\Omega\times\Omega&lt;/math&gt; to be the equalizer of &lt;math&gt;\wedge&lt;/math&gt; and &lt;math&gt;proj_1&lt;/math&gt;. Given &lt;math&gt;v, w: U\to\Omega&lt;/math&gt;, we write &lt;math&gt;v\leq_1 w&lt;/math&gt; if &lt;math&gt;v\times w&lt;/math&gt; factors through &lt;math&gt;\leq_1&lt;/math&gt;.<br /> <br /> Using the definition of an equalizer we arrive at &lt;math&gt;v\leq_1 w&lt;/math&gt; iff &lt;math&gt;v = v\wedge w&lt;/math&gt;. From this, we can deduce<br /> :&lt;math&gt;u\leq_1 true&lt;/math&gt;<br /> :&lt;math&gt;u\leq_1 u&lt;/math&gt;<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 w&lt;/math&gt; then &lt;math&gt;u\leq_1 w&lt;/math&gt;.<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 u&lt;/math&gt; then &lt;math&gt;u=v&lt;/math&gt;<br /> and thus, &lt;math&gt;\leq_1&lt;/math&gt; is a partial order on &lt;math&gt;[U\to\Omega]&lt;/math&gt;. Intuitively, &lt;math&gt;u\leq_1 v&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is at least as true as &lt;math&gt;u&lt;/math&gt;.<br /> <br /> This relation corresponds to inclusion on subobjects. Note that &lt;math&gt;\leq_1:\Omega_1\to\Omega\times\Omega&lt;/math&gt;, given from the equalizer, gives us &lt;math&gt;\Omega_1&lt;/math&gt; as a ''relation'' on &lt;math&gt;\Omega&lt;/math&gt; - a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Specifically, it has a classifying arrow &lt;math&gt;\Rightarrow:\Omega\times\Omega\to\Omega&lt;/math&gt;. We write &lt;math&gt;h\Rightarrow k = (\Rightarrow)\circ h\times k&lt;/math&gt;. And for subobjects &lt;math&gt;P,Q\subseteq A&lt;/math&gt;, we write &lt;math&gt;P\Rightarrow Q&lt;/math&gt; for the subobject classified by &lt;math&gt;\chi_P\Rightarrow\chi_Q&lt;/math&gt;.<br /> <br /> It turns out, without much work, that this &lt;math&gt;P\Rightarrow Q&lt;/math&gt; behaves just like classical implication in its relationship to &lt;math&gt;\wedge&lt;/math&gt;.<br /> <br /> '''Membership''': <br /> We can internalize the notion of ''membership'' as a subobject &lt;math&gt;\in^U\subseteq U\times\Omega^U&lt;/math&gt;, and thus get the membership relation from a pullback:<br /> :[[Image:ToposMembershipPullback.png]]<br /> <br /> For elements &lt;math&gt;x\times h: 1\to U\times\Omega^U&lt;/math&gt;, we write &lt;math&gt;x\in^U h&lt;/math&gt; for &lt;math&gt;x\times h\in\in^U&lt;/math&gt;. Yielding a subset of the product &lt;math&gt;U\times\Omega^U&lt;/math&gt;, this is readily interpretable as a relation relating things in &lt;math&gt;U&lt;/math&gt; with subsets of &lt;math&gt;U&lt;/math&gt;, so that for any &lt;math&gt;x,h&lt;/math&gt; we can answer whether &lt;math&gt;x\in^Uh&lt;/math&gt;. Both notations indicate &lt;math&gt;ev_A\circ h\times x = true&lt;/math&gt;.<br /> <br /> '''Universal quantification''':<br /> For any object &lt;math&gt;U&lt;/math&gt;, the maximal subobject of &lt;math&gt;U&lt;/math&gt; is &lt;math&gt;U&lt;/math&gt; itself, embedded with &lt;math&gt;1_U&lt;/math&gt; into itself. There is an arrow &lt;math&gt;\tau_U:1\to\Omega^U&lt;/math&gt; represents this subobject. Being a map from &lt;math&gt;1&lt;/math&gt;, it is specifically monic, so it has a classifying arrow &lt;math&gt;\forall_U:\Omega^U\to\Omega&lt;/math&gt; that takes a given subobject of &lt;math&gt;U&lt;/math&gt; to &lt;math&gt;true&lt;/math&gt; precisely if it is in fact the maximal subobject.<br /> <br /> Now, with a relation &lt;math&gt;r:R\to B\times A&lt;/math&gt;, we define &lt;math&gt;\forall a. R&lt;/math&gt; by the following pullback:<br /> :[[Image:ToposForallPullback.png]]<br /> where &lt;math&gt;\lambda\chi_R&lt;/math&gt; comes from the universal property of the exponential.<br /> <br /> '''Theorem''' For any &lt;math&gt;s:S\to B&lt;/math&gt; monic, &lt;math&gt;S\subseteq \forall a.R&lt;/math&gt; iff &lt;math&gt;S\times A\subseteq R&lt;/math&gt;.<br /> <br /> This theorem tells us that the subobject given by &lt;math&gt;\forall a.R&lt;/math&gt; is the largest subobject of &lt;math&gt;B&lt;/math&gt; that is related by &lt;math&gt;R&lt;/math&gt; to all of &lt;math&gt;A&lt;/math&gt;.<br /> <br /> '''Falsum''':<br /> We can define the ''false'' truth value using these tools as &lt;math&gt;\forall w\in\Omega.w&lt;/math&gt;. This might be familiar to the more advanced Haskell type hackers - as the type <br /> &lt;haskell&gt;<br /> x :: forall a. a<br /> &lt;/haskell&gt;<br /> which has to be able to give us an element of any type, regardless of the type itself. And in Haskell, the only element that inhabits all types is &lt;hask&gt;undefined&lt;/hask&gt;.<br /> <br /> From a logical perspective, we use a few basic inference rules:<br /> :[[Image:ToposTrivialSequent.png]] [[Image:ToposForallConnective.png]] [[Image:ToposSubstitution.png]]<br /> and connect them up to derive<br /> :[[Image:ToposFalsumDerivation.png]]<br /> for any &lt;math&gt;\phi&lt;/math&gt; not involving &lt;math&gt;w&lt;/math&gt; - and we can always adjust any &lt;math&gt;\phi&lt;/math&gt; to avoid &lt;math&gt;w&lt;/math&gt;.<br /> <br /> Thus, the formula &lt;math&gt;\forall w.w&lt;/math&gt; has the property that it implies everything - and thus is a good candidate for the ''false'' truth value; since the inference<br /> :[[Image:ToposExFalsoQuodlibet.png]]<br /> is the defining introduction rule for false.<br /> <br /> <br /> '''Negation''':<br /> We define negation the same way as in classical logic: &lt;math&gt;\neg \phi = \phi \Rightarrow false&lt;/math&gt;.<br /> <br /> <br /> '''Disjunction''':<br /> We can define <br /> :&lt;math&gt;P\vee Q = \forall w. ((\phi\Rightarrow w)\wedge(\psi\Rightarrow w))\Rightarrow w&lt;/math&gt;<br /> <br /> Note that this definition uses one of our primary inference rules:<br /> :[[Image:ToposDisjunctionConnective.png]]<br /> as the defining property for the disjunction, and we may derive any properties we like from these.<br /> <br /> '''Existential quantifier''':<br /> Finally, the existential quantifier is derived similarly to the disjunction - by figuring out a rule we want it to obey, and using that as a definition for it:<br /> :&lt;math&gt;\exists x.\phi = \forall w. (\forall x. \phi \Rightarrow w)\Rightarrow w&lt;/math&gt;<br /> <br /> Here, the rule we use as defining property is <br /> :[[Image:ToposExistsConnective.png]]<br /> <br /> Before we leave this exploration of logic, some properties worth knowing about:<br /> While we can prove &lt;math&gt;\neg(\phi\wedge\neg\phi)&lt;/math&gt; and &lt;math&gt;\phi\Rightarrow\neg\neg\phi&lt;/math&gt;, we cannot, in just topos logic, prove things like<br /> :&lt;math&gt;\neg(\phi\wedge\psi)\Rightarrow(\neg\phi\vee\neg\psi)&lt;/math&gt;<br /> :&lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt;<br /> nor any statements like<br /> :&lt;math&gt;\neg(\forall x.\neg\phi)\Rightarrow(\exists x.\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\forall x.\phi)\Rightarrow(\exists x.\neg\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\exists x.\neg\phi)\Rightarrow(\forall x.\phi)&lt;/math&gt;<br /> We can, though, prove<br /> :&lt;math&gt;\neg(\exists x.\phi)\Rightarrow(\forall x.\neg\phi)&lt;/math&gt;<br /> <br /> If we include, extra, an additional inference rule (called the ''Boolean negation rule'') given by<br /> :[[Image:BooleanNegation.png]]<br /> then suddenly we're back in classical logic, and can prove &lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt; and &lt;math&gt;\phi\or\neg\phi&lt;/math&gt;.<br /> <br /> ====Examples: Sheaves, topology and time sheaves====<br /> <br /> The first interesting example of a topos is the category of (small enough) sets; in some sense clear already since we've been modelling our axioms and workflows pretty closely on the theory of sets.<br /> <br /> Generating logic and set theory in the topos of sets, we get a theory that captures several properties of ''intuitionistic logic''; such as the lack of Boolean negation, of exclusion of the third, and of double negation rules.<br /> <br /> For the more interesting examples, however, we shall introduce the concepts of ''topology'' and of ''sheaf'':<br /> <br /> '''Definition''' A (set-valued) ''presheaf'' on a category &lt;math&gt;C&lt;/math&gt; is a contravariant functor &lt;math&gt;E: C^{op}\to Set&lt;/math&gt;.<br /> <br /> Presheaves occur all over the place in geometry and topology - and occasionally in computer science too: There is a construction in which a functor &lt;math&gt;A\to Set&lt;/math&gt; for a discrete small category &lt;math&gt;A&lt;/math&gt; identified with its underlying set of objects as a set, corresponds to the data type of ''bags'' of elements from &lt;math&gt;A&lt;/math&gt; - for &lt;math&gt;a\in A&lt;/math&gt;, the image &lt;math&gt;F(a)&lt;/math&gt; denotes the multiplicity of &lt;math&gt;a&lt;/math&gt; in the bag.<br /> <br /> '''Theorem''' The category of all presheaves (with natural transformations as the morphisms) on a category &lt;math&gt;C&lt;/math&gt; form a topos.<br /> <br /> '''Example''' Pick a category on the shape<br /> :[[Image:GraphsAsPresheaves.png]]<br /> A contravariant functor on this category is given by a pair of sets &lt;math&gt;G_0, G_1&lt;/math&gt; and a pair of function &lt;math&gt;source, target: G_1\to G_0&lt;/math&gt;. Identities are sent to identities.<br /> <br /> The category of presheaves on this category, thus, is the category of graphs. Thus graphs form a topos.<br /> <br /> The subobject classifier in the category of graphs is a graph with two nodes: in and out, and five arrows:<br /> :&lt;math&gt;in \to^{all} in&lt;/math&gt;<br /> :&lt;math&gt;in \to^{both} in&lt;/math&gt;<br /> :&lt;math&gt;in \to^{source} out&lt;/math&gt;<br /> :&lt;math&gt;out \to^{target} in&lt;/math&gt;<br /> :&lt;math&gt;out \to^{neither} out&lt;/math&gt;<br /> Now, given a subgraph &lt;math&gt;H \leq G&lt;/math&gt;, we define a function &lt;math&gt;\chi_H:G\to\Omega&lt;/math&gt; by sending nodes to in or out dependent on their membership. For an arrow &lt;math&gt;a&lt;/math&gt;, we send it to all if the arrow is in &lt;math&gt;H&lt;/math&gt;, and otherwise we send it to both/source/target/neither according to where its source and target reside.<br /> <br /> To really get into sheaves, though, we introduce more structure - specifically, we define what we mean by a ''topology'':<br /> <br /> '''Definition''' Suppose &lt;math&gt;P&lt;/math&gt; is a partially ordered set. We call &lt;math&gt;P&lt;/math&gt; a ''complete Heyting algebra'' if<br /> * There is a top element &lt;math&gt;1&lt;/math&gt; such that &lt;math&gt;x\leq 1 \forall x\in P&lt;/math&gt;.<br /> * Any two elements &lt;math&gt;x, y&lt;/math&gt; have an infimum (greatest lower bound) &lt;math&gt;x\wedge y&lt;/math&gt;.<br /> * Every subset &lt;math&gt;Q\subseteq P&lt;/math&gt; has a supremum (least upper bound) &lt;math&gt;\bigvee_{p\in P} p&lt;/math&gt;.<br /> * &lt;math&gt;x\wedge(\bigvee y_i) = \bigvee x\wedge y_i&lt;/math&gt;<br /> <br /> Note that for the partial order by inclusion of a family of subsets of a given set, being a complete Heyting algebra is the same as being a topology in the classical sense - you can take finite unions and any intersections of open sets and still get an open set. <br /> <br /> If &lt;math&gt;\{x_i\}&lt;/math&gt; is a subset with supremum &lt;math&gt;x&lt;/math&gt;, and &lt;math&gt;E&lt;/math&gt; is a presheaf, we get functions &lt;math&gt;e_i:E(x)\to E(x_i)&lt;/math&gt; from functoriality. We can summarize all these &lt;math&gt;e_i&lt;/math&gt; into &lt;math&gt;e = \prod_i e_i: E(x)\to\prod_i E(x_i)&lt;/math&gt;.<br /> <br /> Furthermore, functoriality gives us families of functions &lt;math&gt;c_{ij}: E(x_i)\to E(x_i\wedge x_j)&lt;/math&gt; and &lt;math&gt;d_{ij}: E(x_j)\to E(x_i\wedge x_j)&lt;/math&gt;. These can be collected into &lt;math&gt;c: \prod_i E(x_i)\to\prod_{ij}E(x_i\wedge x_j)&lt;/math&gt; and &lt;math&gt;d:\prod_j E(x_j)\to\prod_{ij}E(x_i\wedge x_j)&lt;/math&gt;.<br /> <br /> '''Definition''' A presheaf &lt;math&gt;E&lt;/math&gt; on a Heyting algebra is called a ''sheaf'' if it satisfies:<br /> :&lt;math&gt;x = \bigvee x_i&lt;/math&gt;<br /> implies that <br /> :[[Image:SheafEqualizer.png]]<br /> is an equalizer. If you have seen sheaves before, you may recognize this as the covering axiom.<br /> <br /> In other words, &lt;math&gt;E&lt;/math&gt; is a sheaf if whenever &lt;math&gt;x=\bigvee x_i&lt;/math&gt; and &lt;math&gt;c(\alpha) = d(\alpha)&lt;/math&gt;, then there is some &lt;math&gt;\bar\alpha&lt;/math&gt; such that &lt;math&gt;\alpha = e(\bar\alpha)&lt;/math&gt;.<br /> <br /> '''Theorem''' The category of sheaves on a Heyting algebra is a topos.<br /> <br /> For context, we can think of sheaves over Heyting algebras as sets in a logic with an expanded notion of truth. Our Heyting algebra is the collection of truth values, and the sheaves are the fuzzy sets with fuzziness introduced by the Heyting algebra.<br /> <br /> Recalling that subsets and predicates are viewed as the same thing, we can view the set &lt;math&gt;E(p)&lt;/math&gt; as the part of the fuzzy set &lt;math&gt;E&lt;/math&gt; that is at least &lt;math&gt;p&lt;/math&gt; true.<br /> <br /> As it turns out, to really make sense of this approach, we realize that ''equality'' is a predicate as well - and thus can hold or not depending on the truth value we use.<br /> <br /> '''Definition''' Let &lt;math&gt;P&lt;/math&gt; be a complete Heyting algebra. A ''&lt;math&gt;P&lt;/math&gt;-valued set'' is a pair &lt;math&gt;(S,\sigma)&lt;/math&gt; of a set &lt;math&gt;S&lt;/math&gt; and a function &lt;math&gt;\sigma: S\to P&lt;/math&gt;. A ''category of fuzzy sets'' is a category of &lt;math&gt;P&lt;/math&gt;-valued sets. A morphism &lt;math&gt;f:(S,\sigma)\to(T,\tau)&lt;/math&gt; of &lt;math&gt;P&lt;/math&gt;-valued sets is a function &lt;math&gt;f:S\to T&lt;/math&gt; such that &lt;math&gt;\tau\circ f = \sigma&lt;/math&gt;.<br /> <br /> From these definitions emerges a fuzzy set theory where all components of it being a kind of set theory emerges from the topoidal approach above. Thus, say, subsets in a fuzzy sense are just monics, thus are injective on the set part, and such that the valuation, on the image of the injection, increases from the previous valuation: &lt;math&gt;(T,\tau)\subseteq(S,\sigma)&lt;/math&gt; if &lt;math&gt;T\subseteq S&lt;/math&gt; and &lt;math&gt;\sigma|_T = \tau&lt;/math&gt;.<br /> <br /> To get to topoi, though, there are a few matters we need to consider. First, we may well have several versions of the empty set - either a bona fide empty set, or just a set where every element is never actually there. This issue is minor. Much more significant though, is that while we can easily make &lt;math&gt;(S,\sigma)&lt;/math&gt; give rise to a presheaf, by defining<br /> :&lt;math&gt;E(x) = \{s\in S: \sigma(s)\geq x\}&lt;/math&gt;<br /> this definition will not yield a sheaf. The reason for this boils down to &lt;math&gt;E(0) = S \neq 1&lt;/math&gt;. We can fix this, though, by adjoining another element - &lt;math&gt;\bot&lt;/math&gt; - to &lt;math&gt;P&lt;/math&gt; giving &lt;math&gt;P^+&lt;/math&gt;. The new element &lt;math&gt;\bot&lt;/math&gt; is imbued with two properties: it is smaller, in &lt;math&gt;P^+&lt;/math&gt;, than any other element, and it is mapped, by &lt;math&gt;E&lt;/math&gt; to &lt;math&gt;1&lt;/math&gt;.<br /> <br /> '''Theorem''' The construction above gives a fuzzy set &lt;math&gt;(S,\sigma)&lt;/math&gt; the structure of a sheaf on the augmented Heyting algebra.<br /> <br /> '''Corollary''' The category of fuzzy sets for a Heyting algebra &lt;math&gt;P&lt;/math&gt; forms a topos.<br /> <br /> '''Final note''' While this construction allows us to make ''membership'' a fuzzy concept, we're not really done fuzzy-izing sets. There are two fundamental predicates on sets: equality and membership. While fuzzy set theory, classically, only allows us to make one of these fuzzy, topos theory allows us - rather easily - to make both these predicates fuzzy. Not only that, but membership reduces - with the power object construction - to equality testing, by which the fuzzy set theory ends up somewhat inconsistent in its treatment of the predicates.<br /> <br /> ===Literature===<br /> <br /> At this point, I would warmly recommend the interested reader to pick up one, or more, of:<br /> * Steve Awodey: Category Theory<br /> * Michael Barr &amp; Charles Wells: Categories for Computing Science<br /> * Colin McLarty: Elementary Categories, Elementary Toposes<br /> <br /> or for more chewy books<br /> * Peter T. Johnstone: Sketches of an Elephant: a Topos Theory compendium<br /> * Michael Barr &amp; Charles Wells: Toposes, Triples and Theories<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # Prove the relations showing that &lt;math&gt;\leq_1&lt;/math&gt; is indeed a partial order on &lt;math&gt;[U\to\Omega]&lt;/math&gt;.<br /> # Prove the universal quantifier theorem.<br /> # The ''extension'' of a formula &lt;math&gt;\phi&lt;/math&gt; over a list of variables &lt;math&gt;x&lt;/math&gt; is the sub-object of the product of domains &lt;math&gt;A_1\times\dots\times A_n&lt;/math&gt; for the variables &lt;math&gt;x_1,\dots,x_n=x&lt;/math&gt; classified by the interpretation of &lt;math&gt;\phi&lt;/math&gt; as a morphism &lt;math&gt;A_1\times\dots\times A_n\to\Omega&lt;/math&gt;. A formula is ''true'' if it classifies the entire product. A ''sequent'', written &lt;math&gt;\Gamma:\phi&lt;/math&gt; is the statement that using the set of formulae &lt;math&gt;\Gamma&lt;/math&gt; we may prove &lt;math&gt;\phi&lt;/math&gt;, or in other words that the intersection of the extensions of the formulae in &lt;math&gt;\Gamma&lt;/math&gt; is contained in the extension of &lt;math&gt;\phi&lt;/math&gt;. If a sequent &lt;math&gt;\Gamma:\phi&lt;/math&gt; is true, we say that &lt;math&gt;\Gamma&lt;/math&gt; ''entails'' &lt;math&gt;\phi&lt;/math&gt;. (some of the questions below are almost embarrassingly immediate from the definitions given above. I include them anyway, so that a ''catalogue'' of sorts of topoidal logic inferences is included here)<br /> ## Prove the following entailments:<br /> ### Trivial sequent: &lt;math&gt;\phi:\phi&lt;/math&gt;<br /> ### True: &lt;math&gt;:true&lt;/math&gt; (note that true classifies the entire object)<br /> ### False: &lt;math&gt;false:\phi&lt;/math&gt; (note that false classifies the global minimum in thepreorder of subobjects)<br /> ## Prove the following inference rules:<br /> ### Implication: &lt;math&gt;\Gamma,\phi:\psi&lt;/math&gt; is equivalent to &lt;math&gt;\Gamma:\phi\Rightarrow\psi&lt;/math&gt;.<br /> ### Thinning: &lt;math&gt;\Gamma:\phi&lt;/math&gt; implies &lt;math&gt;\Gamma,\psi:\phi&lt;/math&gt;<br /> ### Cut: &lt;math&gt;\Gamma,\psi:\phi&lt;/math&gt; and &lt;math&gt;\Gamma:\psi&lt;/math&gt; imply &lt;math&gt;\Gamma:\phi&lt;/math&gt; if every variable free in &lt;math&gt;\psi&lt;/math&gt; is free in &lt;math&gt;\Gamma&lt;/math&gt; or in &lt;math&gt;\phi&lt;/math&gt;.<br /> ### Negation: &lt;math&gt;\Gamma, \phi: false&lt;/math&gt; is equivalent (implications both ways) to &lt;math&gt;\Gamma: \neg\phi&lt;/math&gt;.<br /> ### Conjunction: &lt;math&gt;\Gamma:\phi&lt;/math&gt; and &lt;math&gt;\Gamma:\psi&lt;/math&gt; together are equivalent to &lt;math&gt;\Gamma:\phi\wedge\psi&lt;/math&gt;.<br /> ### Disjunction: &lt;math&gt;\Gamma,\phi:\theta&lt;/math&gt; and &lt;math&gt;\Gamma,\psi:\theta&lt;/math&gt; together imply &lt;math&gt;\Gamma, \phi\vee\psi: \theta&lt;/math&gt;.<br /> ### Universal: &lt;math&gt;\Gamma:\phi&lt;/math&gt; is equivalent to &lt;math&gt;\Gamma:\forall x.\phi&lt;/math&gt; if &lt;math&gt;x&lt;/math&gt; is not free in &lt;math&gt;\Gamma&lt;/math&gt;.<br /> ### Existential: &lt;math&gt;\Gamma,\phi: \psi&lt;/math&gt; is equivalent to &lt;math&gt;\Gamma,\exists x.\phi:\psi&lt;/math&gt; if &lt;math&gt;x&lt;/math&gt; is not free in &lt;math&gt;\Gamma&lt;/math&gt; or &lt;math&gt;\psi&lt;/math&gt;.<br /> ### Equality: &lt;math&gt;:q=q&lt;/math&gt;.<br /> ### Biconditional: &lt;math&gt;(v\Rightarrow w)\wedge(w\Rightarrow v):v=w&lt;/math&gt;. We usually write &lt;math&gt;v\Leftrightarrow w&lt;/math&gt; for &lt;math&gt;v=w&lt;/math&gt; if &lt;math&gt;v,w:A\to\Omega&lt;/math&gt;.<br /> ### Product: &lt;math&gt;p_1u = p_1u', p_2u = p_2u' : u = u'&lt;/math&gt; for &lt;math&gt;u,u'\in A\times B&lt;/math&gt;.<br /> ### Product revisited: &lt;math&gt;:(p_1(s\times s')=s)\wedge(p_2(s\times s')=s')&lt;/math&gt;.<br /> ### Extensionality: &lt;math&gt;\forall x\in A. f(x) = g(x) : f = g&lt;/math&gt; for &lt;math&gt;f,g\in[A\to B]&lt;/math&gt;.<br /> ### Comprehension: &lt;math&gt;(\lambda x\in A. s)x = s&lt;/math&gt; for &lt;math&gt;x\in A&lt;/math&gt;.<br /> ## Prove the following results from the above entailments and inferences -- or directly from the topoidal logic mindset:<br /> ### &lt;math&gt;:\neg(\phi\wedge\neg\phi)&lt;/math&gt;.<br /> ### &lt;math&gt;:\phi\Rightarrow\neg\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;:\neg(\phi\vee\psi)\Rightarrow(\neg\phi\wedge\neg\psi)&lt;/math&gt;.<br /> ### &lt;math&gt;:(\neg\phi\wedge\neg\psi)\Rightarrow\neg(\phi\wedge\psi)&lt;/math&gt;.<br /> ### &lt;math&gt;:(\neg\phi\vee\neg\psi)\Rightarrow\neg(\phi\vee\psi)&lt;/math&gt;.<br /> ### &lt;math&gt;\phi\wedge(\theta\vee\psi)&lt;/math&gt; is equivalent to &lt;math&gt;(\phi\wedge\theta)\vee(\phi\wedge\psi)&lt;/math&gt;.<br /> ### &lt;math&gt;\forall x.\neg\phi&lt;/math&gt; is equivalent to &lt;math&gt;\neg\exists x.\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\exists x\phi\Rightarrow\neg\forall x.\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\exists x\neg\phi\Rightarrow\neg\forall x.\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\forall x\phi\Rightarrow\neg\exists x.\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\phi:\psi&lt;/math&gt; implies &lt;math&gt;\neg\psi:\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\phi:\psi\Rightarrow\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\phi\Rightarrow\not\phi:\not\phi&lt;/math&gt;.<br /> ### &lt;math&gt;\not\phi\vee\psi:\phi\Rightarrow\psi&lt;/math&gt; (but not the converse!).<br /> ### &lt;math&gt;\neg\neg\neg\phi&lt;/math&gt; is equivalent to &lt;math&gt;\neg\phi&lt;/math&gt;.<br /> ### &lt;math&gt;(\phi\wedge\psi)\Rightarrow\theta&lt;/math&gt; is equivalent to &lt;math&gt;\phi\Rightarrow(\psi\Rightarrow\theta)&lt;/math&gt; (currying!).<br /> ## Using the Boolean negation rule: &lt;math&gt;\Gamma,\neg\phi:false&lt;/math&gt; is equivalent to &lt;math&gt;\Gamma:\phi&lt;/math&gt;, prove the following additional results:<br /> ### &lt;math&gt;\neg\neg\phi:\phi&lt;/math&gt;.<br /> ### &lt;math&gt;:\phi\vee\neg\phi&lt;/math&gt;.<br /> ## Show that either of the three rules above, together with the original negation rule, implies the Boolean negation rule.<br /> ### The converses of the three existential/universal/negation implications above.<br /> ## The restrictions introduced for the cut rule above block the deduction of an entailment &lt;math&gt;:\forall x.\phi\Rightarrow\exists x.\phi&lt;/math&gt;. The issue at hand is that &lt;math&gt;A&lt;/math&gt; might not actually have members; so choosing one is not a sound move. Show that this entailment can be deduced from the premise &lt;math&gt;\exists x\in A. x=x&lt;/math&gt;.<br /> ## Show that if we extend our ruleset by the quantifier negation rule &lt;math&gt;\forall x\Leftrightarrow \neg\exists x.\neg&lt;/math&gt;, then we can derive the entailment &lt;math&gt;:\forall w: w=t \vee w = false&lt;/math&gt;. From this derive &lt;math&gt;:\phi\vee\neg\phi&lt;/math&gt; and hence conclude that this extension gets us Boolean logic again.<br /> # A ''topology'' on a topos &lt;math&gt;E&lt;/math&gt; is an arrow &lt;math&gt;j:\Omega\to\Omega&lt;/math&gt; such that &lt;math&gt;j\circ true=true&lt;/math&gt;, &lt;math&gt;j\circ j=j&lt;math&gt; and &lt;math&gt;j\circ\wedge = \wedge\circ j\times j&lt;/math&gt;. For a subobject &lt;math&gt;S\subseteq A&lt;/math&gt; with characteristic arrow &lt;math&gt;\chi_S:A\to\Omega&lt;/math&gt;, we define its &lt;math&gt;j&lt;/math&gt;-closure as the subobject &lt;math&gt;\bar S\subseteq A&lt;/math&gt; classified by &lt;math&gt;j\circ\chi_S&lt;/math&gt;.<br /> ## Prove:<br /> ### &lt;math&gt;S\subseteq\bar S&lt;/math&gt;.<br /> ### &lt;math&gt;\bar S = \bar{\bar S}&lt;/math&gt;.<br /> ### &lt;math&gt;\bar{S\cap T} = \bar S\cap\bar T&lt;/math&gt;.<br /> ### &lt;math&gt;S\subseteq T&lt;/math&gt; implies &lt;math&gt;\bar S\subseteq\bar T&lt;/math&gt;.<br /> ### &lt;math&gt;\bar{f^{-1}(S)} = f^{-1}(\bar S)&lt;/math&gt;.<br /> ## We define &lt;math&gt;S&lt;/math&gt; to be &lt;math&gt;j&lt;/math&gt;-closed if &lt;math&gt;S=\bar S&lt;/math&gt;. It is &lt;math&gt;j&lt;/math&gt;-dense if &lt;math&gt;\bar S=A&lt;/math&gt;. These terms are chosen due to correspondences to classical pointset topology for the topos of sheaves over some space. For a logical standpoint, it is more helpful to look at &lt;math&gt;j&lt;/math&gt; as a modality operator: &quot;''it is &lt;math&gt;j&lt;/math&gt;-locally true that''&quot; Given any &lt;math&gt;u:1\to\Omega&lt;/math&gt;, prove that the following are topologies:<br /> ### &lt;math&gt;(u\to -): \Omega\to\Omega&lt;/math&gt; (the ''open topology'', where such a &lt;math&gt;u&lt;/math&gt; in a sheaf topos ends up corresponding to an open subset of the underlying space, and the formulae picked out are true on at least all of that subset).<br /> ### &lt;math&gt;u\vee -): \Omega\to\Omega&lt;/math&gt; (the closed topology, where a formula is true if its disjunction with &lt;math&gt;u&lt;/math&gt; is true -- corresponding to formulae holding over at least the closed set complementing the subset picked out)<br /> ### &lt;math&gt;\neg\neg: \Omega\to\Omega&lt;/math&gt;. This may, depending on the topos, end up being interpreted as ''true so far as global elements are concerned'', or ''not false on any open set'', or other interpretations.<br /> ### &lt;math&gt;1_\Omega&lt;/math&gt;.<br /> ## For a topos &lt;math&gt;E&lt;/math&gt; with a topology &lt;math&gt;j&lt;/math&gt;, we define an object &lt;math&gt;A&lt;/math&gt; to be a ''sheaf'' iff for every &lt;math&gt;X&lt;/math&gt; and every &lt;math&gt;j&lt;/math&gt;-dense subobject &lt;math&gt;S\subseteq X&lt;/math&gt; and every &lt;math&gt;f:S\to A&lt;/math&gt; there is a unique &lt;math&gt;g:X\to A&lt;/math&gt; with &lt;math&gt;f=g\circ s&lt;/math&gt;. In other words, &lt;math&gt;A&lt;/math&gt; is an object that cannot see the difference between &lt;math&gt;j&lt;/math&gt;-dense subobjects and objects. We write &lt;math&gt;E_j&lt;/math&gt; for the full subcategory of &lt;math&gt;j&lt;/math&gt;-sheaves. <br /> ### Prove that any object is a sheaf for &lt;math&gt;1_\Omega&lt;/math&gt;.<br /> ### Prove that a subobject is dense for &lt;math&gt;\neg\neg&lt;/math&gt; iff its negation is empty. Show that &lt;math&gt;true+false:1+1\to\Omega&lt;/math&gt; is dense for this topology. Conclude that &lt;math&gt;1+1&lt;/math&gt; is dense in &lt;math&gt;\Omega_{\neg\neg}&lt;/math&gt; and thus that &lt;math&gt;E_{\neg\neg}&lt;/math&gt; is Boolean.</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=32053 User:Michiexile/MATH198/Lecture 10 2009-12-01T15:22:09Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;/math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional programming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that opens up for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bot\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \wedge Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \vee Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\wedge = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;\vee = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. (Note that by admitting several universes, we arrive at a ''typed'' predicate logic, with basically no extra work.)<br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> We can now proceed to define all the familiar logic connectives one by one, using the topos setting. While doing this, we shall introduce the notation &lt;math&gt;t_A: A\to\Omega&lt;/math&gt; for the morphism &lt;math&gt;t_A = A\to 1\to^{true}\Omega&lt;/math&gt; that takes on the value ''true'' on all of A. We note that with this convention, &lt;math&gt;\chi_{A_0}&lt;/math&gt;, the characteristic morphism of a subobject, is the arrow such that &lt;math&gt;\chi_{A_0}\circ i = t_{A_0}&lt;/math&gt;.<br /> <br /> '''Conjunction''': <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we need to define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; as some &lt;math&gt;P\wedge Q: U\to\Omega&lt;/math&gt; that corresponds to both &lt;math&gt;P&lt;/math&gt; and &lt;math&gt;Q&lt;/math&gt; simultaneously.<br /> <br /> We may define &lt;math&gt;true\times true: 1\to\Omega\times\Omega&lt;/math&gt;, a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Being a subobject, this has a characteristic arrow &lt;math&gt;\wedge:\Omega\times\Omega\to\Omega&lt;/math&gt;, that we call the ''conjunction arrow''.<br /> <br /> Now, we may define &lt;math&gt;\chi_P\times\chi_Q:U\to\Omega\times\Omega&lt;/math&gt; for subobjects &lt;math&gt;P,Q\subseteq U&lt;/math&gt; - and we take their composition &lt;math&gt;\wedge\circ\chi_P\times\chi_Q&lt;/math&gt; to be the characteristic arrow of the subobject &lt;math&gt;P\wedge Q&lt;/math&gt;.<br /> <br /> And, indeed, this results in a topoidal version of intersection of subobjects.<br /> <br /> '''Implication''': <br /> Next we define &lt;math&gt;\leq_1: \Omega_1\to\Omega\times\Omega&lt;/math&gt; to be the equalizer of &lt;math&gt;\wedge&lt;/math&gt; and &lt;math&gt;proj_1&lt;/math&gt;. Given &lt;math&gt;v, w: U\to\Omega&lt;/math&gt;, we write &lt;math&gt;v\leq_1 w&lt;/math&gt; if &lt;math&gt;v\times w&lt;/math&gt; factors through &lt;math&gt;\leq_1&lt;/math&gt;.<br /> <br /> Using the definition of an equalizer we arrive at &lt;math&gt;v\leq_1 w&lt;/math&gt; iff &lt;math&gt;v = v\wedge w&lt;/math&gt;. From this, we can deduce<br /> :&lt;math&gt;u\leq_1 true&lt;/math&gt;<br /> :&lt;math&gt;u\leq_1 u&lt;/math&gt;<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 w&lt;/math&gt; then &lt;math&gt;u\leq_1 w&lt;/math&gt;.<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 u&lt;/math&gt; then &lt;math&gt;u=v&lt;/math&gt;<br /> and thus, &lt;math&gt;\leq_1&lt;/math&gt; is a partial order on &lt;math&gt;[U\to\Omega]&lt;/math&gt;. Intuitively, &lt;math&gt;u\leq_1 v&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is at least as true as &lt;math&gt;u&lt;/math&gt;.<br /> <br /> This relation corresponds to inclusion on subobjects. Note that &lt;math&gt;\leq_1:\Omega_1\to\Omega\times\Omega&lt;/math&gt;, given from the equalizer, gives us &lt;math&gt;\Omega_1&lt;/math&gt; as a ''relation'' on &lt;math&gt;\Omega&lt;/math&gt; - a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Specifically, it has a classifying arrow &lt;math&gt;\Rightarrow:\Omega\times\Omega\to\Omega&lt;/math&gt;. We write &lt;math&gt;h\Rightarrow k = (\Rightarrow)\circ h\times k&lt;/math&gt;. And for subobjects &lt;math&gt;P,Q\subseteq A&lt;/math&gt;, we write &lt;math&gt;P\Rightarrow Q&lt;/math&gt; for the subobject classified by &lt;math&gt;\chi_P\Rightarrow\chi_Q&lt;/math&gt;.<br /> <br /> It turns out, without much work, that this &lt;math&gt;P\Rightarrow Q&lt;/math&gt; behaves just like classical implication in its relationship to &lt;math&gt;\wedge&lt;/math&gt;.<br /> <br /> '''Membership''': <br /> We can internalize the notion of ''membership'' as a subobject &lt;math&gt;\in^U\subseteq U\times\Omega^U&lt;/math&gt;, and thus get the membership relation from a pullback:<br /> :[[Image:ToposMembershipPullback.png]]<br /> <br /> For elements &lt;math&gt;x\times h: 1\to U\times\Omega^U&lt;/math&gt;, we write &lt;math&gt;x\in^U h&lt;/math&gt; for &lt;math&gt;x\times h\in\in^U&lt;/math&gt;. Yielding a subset of the product &lt;math&gt;U\times\Omega^U&lt;/math&gt;, this is readily interpretable as a relation relating things in &lt;math&gt;U&lt;/math&gt; with subsets of &lt;math&gt;U&lt;/math&gt;, so that for any &lt;math&gt;x,h&lt;/math&gt; we can answer whether &lt;math&gt;x\in^Uh&lt;/math&gt;. Both notations indicate &lt;math&gt;ev_A\circ h\times x = true&lt;/math&gt;.<br /> <br /> '''Universal quantification''':<br /> For any object &lt;math&gt;U&lt;/math&gt;, the maximal subobject of &lt;math&gt;U&lt;/math&gt; is &lt;math&gt;U&lt;/math&gt; itself, embedded with &lt;math&gt;1_U&lt;/math&gt; into itself. There is an arrow &lt;math&gt;\tau_U:1\to\Omega^U&lt;/math&gt; represents this subobject. Being a map from &lt;math&gt;1&lt;/math&gt;, it is specifically monic, so it has a classifying arrow &lt;math&gt;\forall_U:\Omega^U\to\Omega&lt;/math&gt; that takes a given subobject of &lt;math&gt;U&lt;/math&gt; to &lt;math&gt;true&lt;/math&gt; precisely if it is in fact the maximal subobject.<br /> <br /> Now, with a relation &lt;math&gt;r:R\to B\times A&lt;/math&gt;, we define &lt;math&gt;\forall a. R&lt;/math&gt; by the following pullback:<br /> :[[Image:ToposForallPullback.png]]<br /> where &lt;math&gt;\lambda\chi_R&lt;/math&gt; comes from the universal property of the exponential.<br /> <br /> '''Theorem''' For any &lt;math&gt;s:S\to B&lt;/math&gt; monic, &lt;math&gt;S\subseteq \forall a.R&lt;/math&gt; iff &lt;math&gt;S\times A\subseteq R&lt;/math&gt;.<br /> <br /> This theorem tells us that the subobject given by &lt;math&gt;\forall a.R&lt;/math&gt; is the largest subobject of &lt;math&gt;B&lt;/math&gt; that is related by &lt;math&gt;R&lt;/math&gt; to all of &lt;math&gt;A&lt;/math&gt;.<br /> <br /> '''Falsum''':<br /> We can define the ''false'' truth value using these tools as &lt;math&gt;\forall w\in\Omega.w&lt;/math&gt;. This might be familiar to the more advanced Haskell type hackers - as the type <br /> &lt;haskell&gt;<br /> x :: forall a. a<br /> &lt;/haskell&gt;<br /> which has to be able to give us an element of any type, regardless of the type itself. And in Haskell, the only element that inhabits all types is &lt;hask&gt;undefined&lt;/hask&gt;.<br /> <br /> From a logical perspective, we use a few basic inference rules:<br /> :[[Image:ToposTrivialSequent.png]] [[Image:ToposForallConnective.png]] [[Image:ToposSubstitution.png]]<br /> and connect them up to derive<br /> :[[Image:ToposFalsumDerivation.png]]<br /> for any &lt;math&gt;\phi&lt;/math&gt; not involving &lt;math&gt;w&lt;/math&gt; - and we can always adjust any &lt;math&gt;\phi&lt;/math&gt; to avoid &lt;math&gt;w&lt;/math&gt;.<br /> <br /> Thus, the formula &lt;math&gt;\forall w.w&lt;/math&gt; has the property that it implies everything - and thus is a good candidate for the ''false'' truth value; since the inference<br /> :[[Image:ToposExFalsoQuodlibet.png]]<br /> is the defining introduction rule for false.<br /> <br /> <br /> '''Negation''':<br /> We define negation the same way as in classical logic: &lt;math&gt;\neg \phi = \phi \Rightarrow false&lt;/math&gt;.<br /> <br /> <br /> '''Disjunction''':<br /> We can define <br /> :&lt;math&gt;P\vee Q = \forall w. ((\phi\Rightarrow w)\wedge(\psi\Rightarrow w))\Rightarrow w&lt;/math&gt;<br /> <br /> Note that this definition uses one of our primary inference rules:<br /> :[[Image:ToposDisjunctionConnective.png]]<br /> as the defining property for the disjunction, and we may derive any properties we like from these.<br /> <br /> '''Existential quantifier''':<br /> Finally, the existential quantifier is derived similarly to the disjunction - by figuring out a rule we want it to obey, and using that as a definition for it:<br /> :&lt;math&gt;\exists x.\phi = \forall w. (\forall x. \phi \Rightarrow w)\Rightarrow w&lt;/math&gt;<br /> <br /> Here, the rule we use as defining property is <br /> :[[Image:ToposExistsConnective.png]]<br /> <br /> Before we leave this exploration of logic, some properties worth knowing about:<br /> While we can prove &lt;math&gt;\neg(\phi\wedge\neg\phi)&lt;/math&gt; and &lt;math&gt;\phi\Rightarrow\neg\neg\phi&lt;/math&gt;, we cannot, in just topos logic, prove things like<br /> :&lt;math&gt;\neg(\phi\wedge\psi)\Rightarrow(\neg\phi\vee\neg\psi)&lt;/math&gt;<br /> :&lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt;<br /> nor any statements like<br /> :&lt;math&gt;\neg(\forall x.\neg\phi)\Rightarrow(\exists x.\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\forall x.\phi)\Rightarrow(\exists x.\neg\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\exists x.\neg\phi)\Rightarrow(\forall x.\phi)&lt;/math&gt;<br /> We can, though, prove<br /> :&lt;math&gt;\neg(\exists x.\phi)\Rightarrow(\forall x.\neg\phi)&lt;/math&gt;<br /> <br /> If we include, extra, an additional inference rule (called the ''Boolean negation rule'') given by<br /> :[[Image:BooleanNegation.png]]<br /> then suddenly we're back in classical logic, and can prove &lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt; and &lt;math&gt;\phi\or\neg\phi&lt;/math&gt;.<br /> <br /> ====Examples: Sheaves, topology and time sheaves====<br /> <br /> The first interesting example of a topos is the category of (small enough) sets; in some sense clear already since we've been modelling our axioms and workflows pretty closely on the theory of sets.<br /> <br /> Generating logic and set theory in the topos of sets, we get a theory that captures several properties of ''intuitionistic logic''; such as the lack of Boolean negation, of exclusion of the third, and of double negation rules.<br /> <br /> For the more interesting examples, however, we shall introduce the concepts of ''topology'' and of ''sheaf'':<br /> <br /> '''Definition''' A (set-valued) ''presheaf'' on a category &lt;math&gt;C&lt;/math&gt; is a contravariant functor &lt;math&gt;E: C^{op}\to Set&lt;/math&gt;.<br /> <br /> Presheaves occur all over the place in geometry and topology - and occasionally in computer science too: There is a construction in which a functor &lt;math&gt;A\to Set&lt;/math&gt; for a discrete small category &lt;math&gt;A&lt;/math&gt; identified with its underlying set of objects as a set, corresponds to the data type of ''bags'' of elements from &lt;math&gt;A&lt;/math&gt; - for &lt;math&gt;a\in A&lt;/math&gt;, the image &lt;math&gt;F(a)&lt;/math&gt; denotes the multiplicity of &lt;math&gt;a&lt;/math&gt; in the bag.<br /> <br /> '''Theorem''' The category of all presheaves (with natural transformations as the morphisms) on a category &lt;math&gt;C&lt;/math&gt; form a topos.<br /> <br /> '''Example''' Pick a category on the shape<br /> :[[Image:GraphsAsPresheaves.png]]<br /> A contravariant functor on this category is given by a pair of sets &lt;math&gt;G_0, G_1&lt;/math&gt; and a pair of function &lt;math&gt;source, target: G_1\to G_0&lt;/math&gt;. Identities are sent to identities.<br /> <br /> The category of presheaves on this category, thus, is the category of graphs. Thus graphs form a topos.<br /> <br /> The subobject classifier in the category of graphs is a graph with two nodes: in and out, and five arrows:<br /> :&lt;math&gt;in \to^{all} in&lt;/math&gt;<br /> :&lt;math&gt;in \to^{both} in&lt;/math&gt;<br /> :&lt;math&gt;in \to^{source} out&lt;/math&gt;<br /> :&lt;math&gt;out \to^{target} in&lt;/math&gt;<br /> :&lt;math&gt;out \to^{neither} out&lt;/math&gt;<br /> Now, given a subgraph &lt;math&gt;H \leq G&lt;/math&gt;, we define a function &lt;math&gt;\chi_H:G\to\Omega&lt;/math&gt; by sending nodes to in or out dependent on their membership. For an arrow &lt;math&gt;a&lt;/math&gt;, we send it to all if the arrow is in &lt;math&gt;H&lt;/math&gt;, and otherwise we send it to both/source/target/neither according to where its source and target reside.<br /> <br /> To really get into sheaves, though, we introduce more structure - specifically, we define what we mean by a ''topology'':<br /> <br /> '''Definition''' Suppose &lt;math&gt;P&lt;/math&gt; is a partially ordered set. We call &lt;math&gt;P&lt;/math&gt; a ''complete Heyting algebra'' if<br /> * There is a top element &lt;math&gt;1&lt;/math&gt; such that &lt;math&gt;x\leq 1 \forall x\in P&lt;/math&gt;.<br /> * Any two elements &lt;math&gt;x, y&lt;/math&gt; have an infimum (greatest lower bound) &lt;math&gt;x\wedge y&lt;/math&gt;.<br /> * Every subset &lt;math&gt;Q\subseteq P&lt;/math&gt; has a supremum (least upper bound) &lt;math&gt;\bigvee_{p\in P} p&lt;/math&gt;.<br /> * &lt;math&gt;x\wedge(\bigvee y_i) = \bigvee x\wedge y_i&lt;/math&gt;<br /> <br /> Note that for the partial order by inclusion of a family of subsets of a given set, being a complete Heyting algebra is the same as being a topology in the classical sense - you can take finite unions and any intersections of open sets and still get an open set. <br /> <br /> If &lt;math&gt;\{x_i\}&lt;/math&gt; is a subset with supremum &lt;math&gt;x&lt;/math&gt;, and &lt;math&gt;E&lt;/math&gt; is a presheaf, we get functions &lt;math&gt;e_i:E(x)\to E(x_i)&lt;/math&gt; from functoriality. We can summarize all these &lt;math&gt;e_i&lt;/math&gt; into &lt;math&gt;e = \prod_i e_i: E(x)\to\prod_i E(x_i)&lt;/math&gt;.<br /> <br /> Furthermore, functoriality gives us families of functions &lt;math&gt;c_{ij}: E(x_i)\to E(x_i\wedge x_j)&lt;/math&gt; and &lt;math&gt;d_{ij}: E(x_j)\to E(x_i\wedge x_j)&lt;/math&gt;. These can be collected into &lt;math&gt;c: \prod_i E(x_i)\to\prod_{ij}E(x_i\wedge x_j)&lt;/math&gt; and &lt;math&gt;d:\prod_j E(x_j)\to\prod_{ij}E(x_i\wedge x_j)&lt;/math&gt;.<br /> <br /> '''Definition''' A presheaf &lt;math&gt;E&lt;/math&gt; on a Heyting algebra is called a ''sheaf'' if it satisfies:<br /> :&lt;math&gt;x = \bigvee x_i&lt;/math&gt;<br /> implies that <br /> :[[Image:SheafEqualizer.png]]<br /> is an equalizer. If you have seen sheaves before, you may recognize this as the covering axiom.<br /> <br /> In other words, &lt;math&gt;E&lt;/math&gt; is a sheaf if whenever &lt;math&gt;x=\bigvee x_i&lt;/math&gt; and &lt;math&gt;c(\alpha) = d(\alpha)&lt;/math&gt;, then there is some &lt;math&gt;\bar\alpha&lt;/math&gt; such that &lt;math&gt;\alpha = e(\bar\alpha)&lt;/math&gt;.<br /> <br /> '''Theorem''' The category of sheaves on a Heyting algebra is a topos.<br /> <br /> For context, we can think of sheaves over Heyting algebras as sets in a logic with an expanded notion of truth. Our Heyting algebra is the collection of truth values, and the sheaves are the fuzzy sets with fuzziness introduced by the Heyting algebra.<br /> <br /> Recalling that subsets and predicates are viewed as the same thing, we can view the set &lt;math&gt;E(p)&lt;/math&gt; as the part of the fuzzy set &lt;math&gt;E&lt;/math&gt; that is at least &lt;math&gt;p&lt;/math&gt; true.<br /> <br /> As it turns out, to really make sense of this approach, we realize that ''equality'' is a predicate as well - and thus can hold or not depending on the truth value we use.<br /> <br /> '''Definition''' Let &lt;math&gt;P&lt;/math&gt; be a complete Heyting algebra. A ''&lt;math&gt;P&lt;/math&gt;-valued set'' is a pair &lt;math&gt;(S,\sigma)&lt;/math&gt; of a set &lt;math&gt;S&lt;/math&gt; and a function &lt;math&gt;\sigma: S\to P&lt;/math&gt;. A ''category of fuzzy sets'' is a category of &lt;math&gt;P&lt;/math&gt;-valued sets. A morphism &lt;math&gt;f:(S,\sigma)\to(T,\tau)&lt;/math&gt; of &lt;math&gt;P&lt;/math&gt;-valued sets is a function &lt;math&gt;f:S\to T&lt;/math&gt; such that &lt;math&gt;\tau\circ f = \sigma&lt;/math&gt;.<br /> <br /> From these definitions emerges a fuzzy set theory where all components of it being a kind of set theory emerges from the topoidal approach above. Thus, say, subsets in a fuzzy sense are just monics, thus are injective on the set part, and such that the valuation, on the image of the injection, increases from the previous valuation: &lt;math&gt;(T,\tau)\subseteq(S,\sigma)&lt;/math&gt; if &lt;math&gt;T\subseteq S&lt;/math&gt; and &lt;math&gt;\sigma|_T = \tau&lt;/math&gt;.<br /> <br /> To get to topoi, though, there are a few matters we need to consider. First, we may well have several versions of the empty set - either a bona fide empty set, or just a set where every element is never actually there. This issue is minor. Much more significant though, is that while we can easily make &lt;math&gt;(S,\sigma)&lt;/math&gt; give rise to a presheaf, by defining<br /> :&lt;math&gt;E(x) = \{s\in S: \sigma(s)\geq x\}&lt;/math&gt;<br /> this definition will not yield a sheaf. The reason for this boils down to &lt;math&gt;E(0) = S \neq 1&lt;/math&gt;. We can fix this, though, by adjoining another element - &lt;math&gt;\bot&lt;/math&gt; - to &lt;math&gt;P&lt;/math&gt; giving &lt;math&gt;P^+&lt;/math&gt;. The new element &lt;math&gt;\bot&lt;/math&gt; is imbued with two properties: it is smaller, in &lt;math&gt;P^+&lt;/math&gt;, than any other element, and it is mapped, by &lt;math&gt;E&lt;/math&gt; to &lt;math&gt;1&lt;/math&gt;.<br /> <br /> '''Theorem''' The construction above gives a fuzzy set &lt;math&gt;(S,\sigma)&lt;/math&gt; the structure of a sheaf on the augmented Heyting algebra.<br /> <br /> '''Corollary''' The category of fuzzy sets for a Heyting algebra &lt;math&gt;P&lt;/math&gt; forms a topos.<br /> <br /> '''Final note''' While this construction allows us to make ''membership'' a fuzzy concept, we're not really done fuzzy-izing sets. There are two fundamental predicates on sets: equality and membership. While fuzzy set theory, classically, only allows us to make one of these fuzzy, topos theory allows us - rather easily - to make both these predicates fuzzy. Not only that, but membership reduces - with the power object construction - to equality testing, by which the fuzzy set theory ends up somewhat inconsistent in its treatment of the predicates.<br /> <br /> ===Literature===<br /> <br /> At this point, I would warmly recommend the interested reader to pick up one, or more, of:<br /> * Steve Awodey: Category Theory<br /> * Michael Barr &amp; Charles Wells: Categories for Computing Science<br /> * Colin McLarty: Elementary Categories, Elementary Toposes<br /> <br /> or for more chewy books<br /> * Peter T. Johnstone: Sketches of an Elephant: a Topos Theory compendium<br /> * Michael Barr &amp; Charles Wells: Toposes, Triples and Theories<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> #</div> Michiexile https://wiki.haskell.org/index.php?title=File:GraphsAsPresheaves.png&diff=31924 File:GraphsAsPresheaves.png 2009-11-25T01:32:14Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:SheafEqualizer.png&diff=31923 File:SheafEqualizer.png 2009-11-25T01:30:14Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=31922 User:Michiexile/MATH198/Lecture 10 2009-11-25T01:21:20Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;/math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional proogramming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that opens up for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bot\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \wedge Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \vee Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\wedge = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;\vee = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. <br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> We can now proceed to define all the familiar logic connectives one by one, using the topos setting. While doing this, we shall introduce the notation &lt;math&gt;t_A: A\to\Omega&lt;/math&gt; for the morphism &lt;math&gt;t_A = A\to 1\to^{true}\Omega&lt;/math&gt; that takes on the value ''true'' on all of A. We note that with this convention, &lt;math&gt;\chi_{A_0}&lt;/math&gt;, the characteristic morphism of a subobject, is the arrow such that &lt;math&gt;\chi_{A_0}\circ i = t_{A_0}&lt;/math&gt;.<br /> <br /> '''Conjunction''': <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we need to define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; as some &lt;math&gt;P\wedge Q: U\to\Omega&lt;/math&gt; that corresponds to both &lt;math&gt;P&lt;/math&gt; and &lt;math&gt;Q&lt;/math&gt; simultaneously.<br /> <br /> We may define &lt;math&gt;true\times true: 1\to\Omega\times\Omega&lt;/math&gt;, a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Being a subobject, this has a characteristic arrow &lt;math&gt;\wedge:\Omega\times\Omega\to\Omega&lt;/math&gt;, that we call the ''conjunction arrow''.<br /> <br /> Now, we may define &lt;math&gt;\chi_P\times\chi_Q:U\to\Omega\times\Omega&lt;/math&gt; for subobjects &lt;math&gt;P,Q\subseteq U&lt;/math&gt; - and we take their composition &lt;math&gt;\wedge\circ\chi_P\times\chi_Q&lt;/math&gt; to be the characteristic arrow of the subobject &lt;math&gt;P\wedge Q&lt;/math&gt;.<br /> <br /> And, indeed, this results in a topoidal version of intersection of subobjects.<br /> <br /> '''Implication''': <br /> Next we define &lt;math&gt;\leq_1: \Omega_1\to\Omega\times\Omega&lt;/math&gt; to be the equalizer of &lt;math&gt;\wedge&lt;/math&gt; and &lt;math&gt;proj_1&lt;/math&gt;. Given &lt;math&gt;v, w: U\to\Omega&lt;/math&gt;, we write &lt;math&gt;v\leq_1 w&lt;/math&gt; if &lt;math&gt;v\times w&lt;/math&gt; factors through &lt;math&gt;\leq_1&lt;/math&gt;.<br /> <br /> Using the definition of an equalizer we arrive at &lt;math&gt;v\leq_1 w&lt;/math&gt; iff &lt;math&gt;v = v\wedge w&lt;/math&gt;. From this, we can deduce<br /> :&lt;math&gt;u\leq_1 true&lt;/math&gt;<br /> :&lt;math&gt;u\leq_1 u&lt;/math&gt;<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 w&lt;/math&gt; then &lt;math&gt;u\leq_1 w&lt;/math&gt;.<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 u&lt;/math&gt; then &lt;math&gt;u=v&lt;/math&gt;<br /> and thus, &lt;math&gt;\leq_1&lt;/math&gt; is a partial order on &lt;math&gt;[U\to\Omega]&lt;/math&gt;. Intuitively, &lt;math&gt;u\leq_1 v&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is at least as true as &lt;math&gt;u&lt;/math&gt;.<br /> <br /> This relation corresponds to inclusion on subobjects. Note that &lt;math&gt;\leq_1:\Omega_1\to\Omega\times\Omega&lt;/math&gt;, given from the equalizer, gives us &lt;math&gt;\Omega_1&lt;/math&gt; as a ''relation'' on &lt;math&gt;\Omega&lt;/math&gt; - a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Specifically, it has a classifying arrow &lt;math&gt;\Rightarrow:\Omega\times\Omega\to\Omega&lt;/math&gt;. We write &lt;math&gt;h\Rightarrow k = (\Rightarrow)\circ h\times k&lt;/math&gt;. And for subobjects &lt;math&gt;P,Q\subseteq A&lt;/math&gt;, we write &lt;math&gt;P\Rightarrow Q&lt;/math&gt; for the subobject classified by &lt;math&gt;\chi_P\Rightarrow\chi_Q&lt;/math&gt;.<br /> <br /> It turns out, without much work, that this &lt;math&gt;P\Rightarrow Q&lt;/math&gt; behaves just like classical implication in its relationship to &lt;math&gt;\wedge&lt;/math&gt;.<br /> <br /> '''Membership''': <br /> We can internalize the notion of ''membership'' as a subobject &lt;math&gt;\in^U\subseteq U\times\Omega^U&lt;/math&gt;, and thus get the membership relation from a pullback:<br /> :[[Image:ToposMembershipPullback.png]]<br /> <br /> For elements &lt;math&gt;x\times h: 1\to U\times\Omega^U&lt;/math&gt;, we write &lt;math&gt;x\in^U h&lt;/math&gt; for &lt;math&gt;x\times h\in\in^U&lt;/math&gt;. Yielding a subset of the product &lt;math&gt;U\times\Omega^U&lt;/math&gt;, this is readily interpretable as a relation relating things in &lt;math&gt;U&lt;/math&gt; with subsets of &lt;math&gt;U&lt;/math&gt;, so that for any &lt;math&gt;x,h&lt;/math&gt; we can answer whether &lt;math&gt;x\in^Uh&lt;/math&gt;. Both notations indicate &lt;math&gt;ev_A\circ h\times x = true&lt;/math&gt;.<br /> <br /> '''Universal quantification''':<br /> For any object &lt;math&gt;U&lt;/math&gt;, the maximal subobject of &lt;math&gt;U&lt;/math&gt; is &lt;math&gt;U&lt;/math&gt; itself, embedded with &lt;math&gt;1_U&lt;/math&gt; into itself. There is an arrow &lt;math&gt;\tau_U:1\to\Omega^U&lt;/math&gt; represents this subobject. Being a map from &lt;math&gt;1&lt;/math&gt;, it is specifically monic, so it has a classifying arrow &lt;math&gt;\forall_U:\Omega^U\to\Omega&lt;/math&gt; that takes a given subobject of &lt;math&gt;U&lt;/math&gt; to &lt;math&gt;true&lt;/math&gt; precisely if it is in fact the maximal subobject.<br /> <br /> Now, with a relation &lt;math&gt;r:R\to B\times A&lt;/math&gt;, we define &lt;math&gt;\forall a. R&lt;/math&gt; by the following pullback:<br /> :[[Image:ToposForallPullback.png]]<br /> where &lt;math&gt;\lambda\chi_R&lt;/math&gt; comes from the universal property of the exponential.<br /> <br /> '''Theorem''' For any &lt;math&gt;s:S\to B&lt;/math&gt; monic, &lt;math&gt;S\subseteq \forall a.R&lt;/math&gt; iff &lt;math&gt;S\times A\subseteq R&lt;/math&gt;.<br /> <br /> This theorem tells us that the subobject given by &lt;math&gt;\forall a.R&lt;/math&gt; is the largest subobject of &lt;math&gt;B&lt;/math&gt; that is related by &lt;math&gt;R&lt;/math&gt; to all of &lt;math&gt;A&lt;/math&gt;.<br /> <br /> '''Falsum''':<br /> We can define the ''false'' truth value using these tools as &lt;math&gt;\forall w\in\Omega.w&lt;/math&gt;. This might be familiar to the more advanced Haskell type hackers - as the type <br /> &lt;haskell&gt;<br /> x :: forall a. a<br /> &lt;/haskell&gt;<br /> which has to be able to give us an element of any type, regardless of the type itself. And in Haskell, the only element that inhabits all types is &lt;hask&gt;undefined&lt;/hask&gt;.<br /> <br /> From a logical perspective, we use a few basic inference rules:<br /> :[[Image:ToposTrivialSequent.png]] [[Image:ToposForallConnective.png]] [[Image:ToposSubstitution.png]]<br /> and connect them up to derive<br /> :[[Image:ToposFalsumDerivation.png]]<br /> for any &lt;math&gt;\phi&lt;/math&gt; not involving &lt;math&gt;w&lt;/math&gt; - and we can always adjust any &lt;math&gt;\phi&lt;/math&gt; to avoid &lt;math&gt;w&lt;/math&gt;.<br /> <br /> Thus, the formula &lt;math&gt;\forall w.w&lt;/math&gt; has the property that it implies everything - and thus is a good candidate for the ''false'' truth value; since the inference<br /> :[[Image:ToposExFalsoQuodlibet.png]]<br /> is the defining introduction rule for false.<br /> <br /> <br /> '''Negation''':<br /> We define negation the same way as in classical logic: &lt;math&gt;\neg \phi = \phi \Rightarrow false&lt;/math&gt;.<br /> <br /> <br /> '''Disjunction''':<br /> We can define <br /> :&lt;math&gt;P\vee Q = \forall w. ((\phi\Rightarrow w)\wedge(\psi\Rightarrow w))\Rightarrow w&lt;/math&gt;<br /> <br /> Note that this definition uses one of our primary inference rules:<br /> :[[Image:ToposDisjunctionConnective.png]]<br /> as the defining property for the disjunction, and we may derive any properties we like from these.<br /> <br /> '''Existential quantifier''':<br /> Finally, the existential quantifier is derived similarly to the disjunction - by figuring out a rule we want it to obey, and using that as a definition for it:<br /> :&lt;math&gt;\exists x.\phi = \forall w. (\forall x. \phi \Rightarrow w)\Rightarrow w&lt;/math&gt;<br /> <br /> Here, the rule we use as defining property is <br /> :[[Image:ToposExistsConnective.png]]<br /> <br /> Before we leave this exploration of logic, some properties worth knowing about:<br /> While we can prove &lt;math&gt;\neg(\phi\wedge\neg\phi)&lt;/math&gt; and &lt;math&gt;\phi\Rightarrow\neg\neg\phi&lt;/math&gt;, we cannot, in just topos logic, prove things like<br /> :&lt;math&gt;\neg(\phi\wedge\psi)\Rightarrow(\neg\phi\vee\neg\psi)&lt;/math&gt;<br /> :&lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt;<br /> nor any statements like<br /> :&lt;math&gt;\neg(\forall x.\neg\phi)\Rightarrow(\exists x.\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\forall x.\phi)\Rightarrow(\exists x.\neg\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\exists x.\neg\phi)\Rightarrow(\forall x.\phi)&lt;/math&gt;<br /> We can, though, prove<br /> :&lt;math&gt;\neg(\exists x.\phi)\Rightarrow(\forall x.\neg\phi)&lt;/math&gt;<br /> <br /> If we include, extra, an additional inference rule (called the ''Boolean negation rule'') given by<br /> :[[Image:BooleanNegation.png]]<br /> then suddenly we're back in classical logic, and can prove &lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt; and &lt;math&gt;\phi\or\neg\phi&lt;/math&gt;.<br /> <br /> ====Examples: Sheaves, topology and time sheaves====<br /> <br /> The first interesting example of a topos is the category of (small enough) sets; in some sense clear already since we've been modelling our axioms and workflows pretty closely on the theory of sets.<br /> <br /> Generating logic and set theory in the topos of sets, we get a theory that captures several properties of ''intuitionistic logic''; such as the lack of Boolean negation, of exclusion of the third, and of double negation rules.<br /> <br /> For the more interesting examples, however, we shall introduce the concepts of ''topology'' and of ''sheaf'':<br /> <br /> '''Definition''' A (set-valued) ''presheaf'' on a category &lt;math&gt;C&lt;/math&gt; is a contravariant functor &lt;math&gt;E: C^{op}\to Set&lt;/math&gt;.<br /> <br /> Presheaves occur all over the place in geometry and topology - and occasionally in computer science too: There is a construction in which a functor &lt;math&gt;A\to Set&lt;/math&gt; for a discrete small category &lt;math&gt;A&lt;/math&gt; identified with its underlying set of objects as a set, corresponds to the data type of ''bags'' of elements from &lt;math&gt;A&lt;/math&gt; - for &lt;math&gt;a\in A&lt;/math&gt;, the image &lt;math&gt;F(a)&lt;/math&gt; denotes the multiplicity of &lt;math&gt;a&lt;/math&gt; in the bag.<br /> <br /> '''Theorem''' The category of all presheaves (with natural transformations as the morphisms) on a category &lt;math&gt;C&lt;/math&gt; form a topos.<br /> <br /> '''Example''' Pick a category on the shape<br /> :[[Image:GraphsAsPresheaves.png]]<br /> A contravariant functor on this category is given by a pair of sets &lt;math&gt;G_0, G_1&lt;/math&gt; and a pair of function &lt;math&gt;source, target: G_1\to G_0&lt;/math&gt;. Identities are sent to identities.<br /> <br /> The category of presheaves on this category, thus, is the category of graphs. Thus graphs form a topos.<br /> <br /> The subobject classifier in the category of graphs is a graph with two nodes: in and out, and five arrows:<br /> :&lt;math&gt;in \to^{all} in&lt;/math&gt;<br /> :&lt;math&gt;in \to^{both} in&lt;/math&gt;<br /> :&lt;math&gt;in \to^{source} out&lt;/math&gt;<br /> :&lt;math&gt;out \to^{target} in&lt;/math&gt;<br /> :&lt;math&gt;out \to^{neither} out&lt;/math&gt;<br /> Now, given a subgraph &lt;math&gt;H \leq G&lt;/math&gt;, we define a function &lt;math&gt;\chi_H:G\to\Omega&lt;/math&gt; by sending nodes to in or out dependent on their membership. For an arrow &lt;math&gt;a&lt;/math&gt;, we send it to all if the arrow is in &lt;math&gt;H&lt;/math&gt;, and otherwise we send it to both/source/target/neither according to where its source and target reside.<br /> <br /> To really get into sheaves, though, we introduce more structure - specifically, we define what we mean by a ''topology'':<br /> <br /> '''Definition''' Suppose &lt;math&gt;P&lt;/math&gt; is a partially ordered set. We call &lt;/math&gt;P&lt;/math&gt; a ''complete Heyting algebra'' if<br /> * There is a top element &lt;math&gt;1&lt;/math&gt; such that &lt;math&gt;x\leq 1 \forall x\in P&lt;/math&gt;.<br /> * Any two elements &lt;math&gt;x, y&lt;/math&gt; have an infimum (greatest lower bound) &lt;math&gt;x\wedge y&lt;/math&gt;.<br /> * Every subset &lt;math&gt;Q\subseteq P&lt;/math&gt; has a supremum (least upper bound) &lt;math&gt;\bigvee_{p\in P} p&lt;/math&gt;.<br /> * &lt;math&gt;x\wedge(\bigvee y_i) = \bigvee x\wedge y_i&lt;/math&gt;<br /> <br /> Note that for the partial order by inclusion of a family of subsets of a given set, being a complete Heyting algebra is the same as being a topology in the classical sense - you can take finite unions and any intersections of open sets and still get an open set. <br /> <br /> If &lt;math&gt;\{x_i\}&lt;/math&gt; is a subset with supremum &lt;math&gt;x&lt;/math&gt;, and &lt;math&gt;E&lt;/math&gt; is a presheaf, we get functions &lt;math&gt;e_i:E(x)\to E(x_i)&lt;/math&gt; from functoriality. We can summarize all these &lt;math&gt;e_i&lt;/math&gt; into &lt;math&gt;e = \prod_i e_i: E(x)\to\prod_i E(x_i)&lt;/math&gt;.<br /> <br /> Furthermore, functoriality gives us families of functions &lt;math&gt;c_{ij}: E(x_i)\to E(x_i\wedge x_j)&lt;/math&gt; and &lt;math&gt;d_{ij}: E(x_j)\to E(x_i\wedge x_j)&lt;/math&gt;. These can be collected into &lt;math&gt;c: \prod_i E(x_i)\to\prod_{ij}E(x_i\wedge x_j)?&lt;/math&gt; and &lt;math&gt;d:\prod_j E(x_j)\to\prod_{ij}E(x_i\wedge x_j)&lt;/math&gt;.<br /> <br /> '''Definition''' A presheaf &lt;math&gt;E&lt;/math&gt; on a Heyting algebra is called a ''sheaf'' if it satisfies:<br /> :&lt;math&gt;x = \bigvee x_i&lt;/math&gt;<br /> implies that <br /> :[[Image:SheafEqualizer.png]]<br /> is an equalizer.<br /> <br /> In other words, &lt;math&gt;E&lt;/math&gt; is a sheaf if whenever &lt;math&gt;x=\bigvee x_i&lt;/math&gt; and &lt;math&gt;c(\alpha) = d(\alpha)&lt;/math&gt;, then there is some &lt;math&gt;\bar\alpha&lt;/math&gt; such that &lt;math&gt;\alpha = e(\bar\alpha)&lt;/math&gt;.<br /> <br /> '''Theorem''' The category of sheaves on a Heyting algebra is a topos.<br /> <br /> For context, we can think of sheaves over Heyting algebras as sets in a logic with an expanded notion of truth. Our Heyting algebra is the collection of truth values, and the sheaves are the fuzzy sets with fuzziness introduced by the Heyting algebra.<br /> <br /> Recalling that subsets and predicates are viewed as the same thing, we can view the set &lt;math&gt;E(p)&lt;/math&gt; as the part of the fuzzy set &lt;math&gt;E&lt;/math&gt; that is at least &lt;math&gt;p&lt;/math&gt; true.<br /> <br /> As it turns out, to really make sense of this approach, we realize that ''equality'' is a predicate as well - and thus can hold or not depending on the truth value we use.<br /> <br /> '''Definition''' Let &lt;math&gt;P&lt;/math&gt; be a complete Heyting algebra. A ''&lt;math&gt;P&lt;/math&gt;-valued set'' is a pair &lt;math&gt;(S,\sigma)&lt;/math&gt; of a set &lt;math&gt;S&lt;/math&gt; and a function &lt;math&gt;\sigma: S\to P&lt;/math&gt;. A ''category of fuzzy sets'' is a category of &lt;math&gt;P&lt;/math&gt;-valued sets. A morphism &lt;math&gt;f:(S,\sigma)\to(T,\tau)&lt;/math&gt; of &lt;math&gt;P&lt;/math&gt;-valued sets is a function &lt;math&gt;f:S\to T&lt;/math&gt; such that &lt;math&gt;\tau\circ f = \sigma&lt;/math&gt;.<br /> <br /> From these definitions emerges a fuzzy set theory where all components of it being a kind of set theory emerges from the topoidal approach above. Thus, say, subsets in a fuzzy sense are just monics, thus are injective on the set part, and such that the valuation, on the image of the injection, increases from the previous valuation: &lt;math&gt;(T,\tau)\subseteq(S,\sigma) if &lt;math&gt;T\subseteq S&lt;/math&gt; and &lt;math&gt;\sigma|_T = \tau&lt;/math&gt;.<br /> <br /> To get to topoi, though, there are a few matters we need to consider. First, we may well have several versions of the empty set - either a bona fide empty set, or just a set where every element is never actually there. This issue is minor. Much more significant though, is that while we can easily make &lt;math&gt;(S,\sigma)&lt;/math&gt; give rise to a presheaf, by defining<br /> :&lt;math&gt;E(x) = \{s\in S: \sigma(s)\geq x\}&lt;/math&gt;<br /> this definition will not yield a sheaf. The reason for this boils down to &lt;math&gt;E(0) = S \neq 1&lt;/math&gt;. We can fix this, though, by adjoining another element - &lt;math&gt;\bot&lt;/math&gt; - to &lt;math&gt;P&lt;/math&gt; giving &lt;math&gt;P^+&lt;/math&gt;. The new element &lt;math&gt;\bot&lt;/math&gt; is imbued with two properties: it is smaller, in &lt;math&gt;P^+&lt;/math&gt;, than any other element, and it is mapped, by &lt;math&gt;E&lt;/math&gt; to &lt;math&gt;1&lt;/math&gt;.<br /> <br /> '''Theorem''' The construction above gives a fuzzy set &lt;math&gt;(S,\sigma)&lt;/math&gt; the structure of a sheaf on the augmented Heyting algebra.<br /> <br /> '''Corollary''' The category of fuzzy sets for a Heyting algebra &lt;math&gt;P&lt;/math&gt; forms a topos.<br /> <br /> '''Final note''' While this construction allows us to make ''membership'' a fuzzy concept, we're not really done fuzzy-izing sets. There are two fundamental predicates on sets: equality and membership. While fuzzy set theory, classically, only allows us to make one of these fuzzy, topos theory allows us - rather easily - to make both these predicates fuzzy. Not only that, but membership reduces - with the power object construction - to equality testing, by which the fuzzy set theory ends up somewhat inconsistent in its treatment of the predicates.<br /> <br /> ===Literature===<br /> <br /> At this point, I would warmly recommend the interested reader to pick up one, or more, of:<br /> * Steve Awodey: Category Theory<br /> * Michael Barr &amp; Charles Wells: Categories for Computing Science<br /> * Colin McLarty: Elementary Categories, Elementary Toposes<br /> <br /> or for more chewy books<br /> * Peter T. Johnstone: Sketches of an Elephant: a Topos Theory compendium<br /> * Michael Barr &amp; Charles Wells: Toposes, Triples and Theories<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # blah</div> Michiexile https://wiki.haskell.org/index.php?title=File:BooleanNegation.png&diff=31919 File:BooleanNegation.png 2009-11-24T19:52:13Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:ToposExistsConnective.png&diff=31918 File:ToposExistsConnective.png 2009-11-24T19:51:52Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:ToposDisjunctionConnective.png&diff=31917 File:ToposDisjunctionConnective.png 2009-11-24T19:51:14Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:ToposExFalsoQuodlibet.png&diff=31916 File:ToposExFalsoQuodlibet.png 2009-11-24T19:45:42Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:ToposFalsumDerivation.png&diff=31915 File:ToposFalsumDerivation.png 2009-11-24T19:45:19Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:ToposSubstitution.png&diff=31914 File:ToposSubstitution.png 2009-11-24T19:44:59Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:ToposForallConnective.png&diff=31913 File:ToposForallConnective.png 2009-11-24T19:44:39Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:ToposTrivialSequent.png&diff=31912 File:ToposTrivialSequent.png 2009-11-24T19:44:22Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:ToposForallPullback.png&diff=31911 File:ToposForallPullback.png 2009-11-24T19:44:00Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:ToposMembershipPullback.png&diff=31910 File:ToposMembershipPullback.png 2009-11-24T19:43:02Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:SubobjectClassifierPullback.png&diff=31909 File:SubobjectClassifierPullback.png 2009-11-24T19:42:19Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:SubobjectFunctorMorphismPullback.png&diff=31908 File:SubobjectFunctorMorphismPullback.png 2009-11-24T19:42:01Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=31907 User:Michiexile/MATH198/Lecture 10 2009-11-24T19:40:55Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;/math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional proogramming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that open sup for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bot\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \wedge Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \vee Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\wedge = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;\vee = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. <br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> We can now proceed to define all the familiar logic connectives one by one, using the topos setting. While doing this, we shall introduce the notation &lt;math&gt;t_A: A\to\Omega&lt;/math&gt; for the morphism &lt;math&gt;t_A = A\to 1\to^{true}\Omega&lt;/math&gt; that takes on the value ''true'' on all of A. We note that with this convention, &lt;math&gt;\chi_{A_0}&lt;/math&gt;, the characteristic morphism of a subobject, is the arrow such that &lt;math&gt;\chi_{A_0}\circ i = t_{A_0}&lt;/math&gt;.<br /> <br /> '''Conjunction''': <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we need to define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; as some &lt;math&gt;P\wedge Q: U\to\Omega&lt;/math&gt; that corresponds to both &lt;math&gt;P&lt;/math&gt; and &lt;math&gt;Q&lt;/math&gt; simultaneously.<br /> <br /> We may define &lt;math&gt;true\times true: 1\to\Omega\times\Omega&lt;/math&gt;, a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Being a subobject, this has a characteristic arrow &lt;math&gt;\wedge:\Omega\times\Omega\to\Omega&lt;/math&gt;, that we call the ''conjunction arrow''.<br /> <br /> Now, we may define &lt;math&gt;\chi_P\times\chi_Q:U\to\Omega\times\Omega&lt;/math&gt; for subobjects &lt;math&gt;P,Q\subseteq U&lt;/math&gt; - and we take their composition &lt;math&gt;\wedge\circ\chi_P\times\chi_Q&lt;/math&gt; to be the characteristic arrow of the subobject &lt;math&gt;P\wedge Q&lt;/math&gt;.<br /> <br /> And, indeed, this results in a topoidal version of intersection of subobjects.<br /> <br /> '''Implication''': <br /> Next we define &lt;math&gt;\leq_1: \Omega_1\to\Omega\times\Omega&lt;/math&gt; to be the equalizer of &lt;math&gt;\wedge&lt;/math&gt; and &lt;math&gt;proj_1&lt;/math&gt;. Given &lt;math&gt;v, w: U\to\Omega&lt;/math&gt;, we write &lt;math&gt;v\leq_1 w&lt;/math&gt; if &lt;math&gt;v\times w&lt;/math&gt; factors through &lt;math&gt;\leq_1&lt;/math&gt;.<br /> <br /> Using the definition of an equalizer we arrive at &lt;math&gt;v\leq_1 w&lt;/math&gt; iff &lt;math&gt;v = v\wedge w&lt;/math&gt;. From this, we can deduce<br /> :&lt;math&gt;u\leq_1 true&lt;/math&gt;<br /> :&lt;math&gt;u\leq_1 u&lt;/math&gt;<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 w&lt;/math&gt; then &lt;math&gt;u\leq_1 w&lt;/math&gt;.<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 u&lt;/math&gt; then &lt;math&gt;u=v&lt;/math&gt;<br /> and thus, &lt;math&gt;\leq_1&lt;/math&gt; is a partial order on &lt;math&gt;[U\to\Omega]&lt;/math&gt;. Intuitively, &lt;math&gt;u\leq_1 v&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is at least as true as &lt;math&gt;u&lt;/math&gt;.<br /> <br /> This relation corresponds to inclusion on subobjects. Note that &lt;math&gt;\leq_1:\Omega_1\to\Omega\times\Omega&lt;/math&gt;, given from the equalizer, gives us &lt;math&gt;\Omega_1&lt;/math&gt; as a ''relation'' on &lt;math&gt;\Omega&lt;/math&gt; - a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Specifically, it has a classifying arrow &lt;math&gt;\Rightarrow:\Omega\times\Omega\to\Omega&lt;/math&gt;. We write &lt;math&gt;h\Rightarrow k = (\Rightarrow)\circ h\times k&lt;/math&gt;. And for subobjects &lt;math&gt;P,Q\subseteq A&lt;/math&gt;, we write &lt;math&gt;P\Rightarrow Q&lt;/math&gt; for the subobject classified by &lt;math&gt;\chi_P\Rightarrow\chi_Q&lt;/math&gt;.<br /> <br /> It turns out, without much work, that this &lt;math&gt;P\Rightarrow Q&lt;/math&gt; behaves just like classical implication in its relationship to &lt;math&gt;\wedge&lt;/math&gt;.<br /> <br /> '''Membership''': <br /> We can internalize the notion of ''membership'' as a subobject &lt;math&gt;\in^A\subseteq A\times\Omega^A&lt;/math&gt;, and thus get the membership relation from a pullback:<br /> :[[Image:ToposMembershipPullback.png]]<br /> <br /> For elements &lt;math&gt;x\times h: 1\to U\times\Omega^U&lt;/math&gt;, we write &lt;math&gt;x\in^U h&lt;/math&gt; for &lt;math&gt;x\times h\in\in^U&lt;/math&gt;. Yielding a subset of the product &lt;math&gt;U\times\Omega^U&lt;/math&gt;, this is readily interpretable as a relation relating things in &lt;math&gt;U&lt;/math&gt; with subsets of &lt;math&gt;U&lt;/math&gt;, so that for any &lt;math&gt;x,h&lt;/math&gt; we can answer whether &lt;math&gt;x\in^Uh&lt;/math&gt;. Both notations indicate &lt;math&gt;ev_A\circ h\times x = true&lt;/math&gt;.<br /> <br /> '''Universal quantification''':<br /> For any object &lt;math&gt;U&lt;/math&gt;, the maximal subobject of &lt;math&gt;U&lt;/math&gt; is &lt;math&gt;U&lt;/math&gt; itself, embedded with &lt;math&gt;1_U&lt;/math&gt; into itself. There is an arrow &lt;math&gt;\tau_U:1\to\Omega^U&lt;/math&gt; represents this subobject. Being a map from &lt;math&gt;1&lt;/math&gt;, it is specifically monic, so it has a classifying arrow &lt;math&gt;\forall_U:\Omega^U\to\Omega&lt;/math&gt; that takes a given subobject of &lt;math&gt;U&lt;/math&gt; to &lt;math&gt;true&lt;/math&gt; precisely if it is in fact the maximal subobject.<br /> <br /> Now, with a relation &lt;math&gt;r:R\to B\times A&lt;/math&gt;, we define &lt;math&gt;\forall a. R&lt;/math&gt; by the following pullback:<br /> :[[Image:ToposForallPullback.png]]<br /> where &lt;math&gt;\lambda\chi_R&lt;/math&gt; comes from the universal property of the exponential.<br /> <br /> '''Theorem''' For any &lt;math&gt;s:S\to B&lt;/math&gt; monic, &lt;math&gt;S\subseteq \forall a.R&lt;/math&gt; iff &lt;math&gt;S\times A\subseteq R&lt;/math&gt;.<br /> <br /> This theorem tells us that the subobject given by &lt;math&gt;\forall a.R&lt;/math&gt; is the largest subobject of &lt;math&gt;B&lt;/math&gt; that is related by &lt;math&gt;R&lt;/math&gt; to all of &lt;math&gt;A&lt;/math&gt;.<br /> <br /> '''Falsum''':<br /> We can define the ''false'' truth value using these tools as &lt;math&gt;\forall w\in\Omega.w&lt;/math&gt;. This might be familiar to the more advanced Haskell type hackers - as the type <br /> &lt;haskell&gt;<br /> x :: forall a. a<br /> &lt;/haskell&gt;<br /> which has to be able to give us an element of any type, regardless of the type itself. And in Haskell, the only element that inhabits all types is &lt;hask&gt;undefined&lt;/hask&gt;.<br /> <br /> From a logical perspective, we use a few basic inference rules:<br /> :[[Image:ToposTrivialSequent.png]] [[Image:ToposForallConnective.png]] [[Image:ToposSubstitution.png]]<br /> and connect them up to derive<br /> :[[Image:ToposFalsumDerivation.png]]<br /> for any &lt;math&gt;\phi&lt;/math&gt; not involving &lt;math&gt;w&lt;/math&gt; - and we can always adjust any &lt;math&gt;\phi&lt;/math&gt; to avoid &lt;math&gt;w&lt;/math&gt;.<br /> <br /> Thus, the formula &lt;math&gt;\forall w.w&lt;/math&gt; has the property that it implies everything - and thus is a good candidate for the ''false'' truth value; since the inference<br /> :[[Image:ToposExFalsoQuodlibet.png]]<br /> is the defining introduction rule for false.<br /> <br /> <br /> '''Negation''':<br /> We define negation the same way as in classical logic: &lt;math&gt;\neg \phi = \phi \Rightarrow false&lt;/math&gt;.<br /> <br /> <br /> '''Disjunction''':<br /> We can define <br /> :&lt;math&gt;P\vee Q = \forall w. ((\phi\Rightarrow w)\wedge(\psi\Rightarrow w))\Rightarrow w&lt;/math&gt;<br /> <br /> Note that this definition uses one of our primary inference rules:<br /> :[[Image:ToposDisjunctionConnective.png]]<br /> as the defining property for the disjunction, and we may derive any properties we like from these.<br /> <br /> '''Existential quantifier''':<br /> Finally, the existential quantifier is derived similarly to the disjunction - by figuring out a rule we want it to obey, and using that as a definition for it:<br /> :&lt;math&gt;\exists x.\phi = \forall w. (\forall x. \phi \Rightarrow w)\Rightarrow w&lt;/math&gt;<br /> <br /> Here, the rule we use as defining property is <br /> :[[Image:ToposExistsConnective.png]]<br /> <br /> Before we leave this exploration of logic, some properties worth knowing about:<br /> While we can prove &lt;math&gt;\neg(\phi\wedge\neg\phi)&lt;/math&gt; and &lt;math&gt;\phi\Rightarrow\neg\neg\phi&lt;/math&gt;, we cannot, in just topos logic, prove things like<br /> :&lt;math&gt;\neg(\phi\wedge\psi)\Rightarrow(\neg\phi\vee\neg\psi)&lt;/math&gt;<br /> :&lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt;<br /> nor any statements like<br /> :&lt;math&gt;\neg(\forall x.\neg\phi)\Rightarrow(\exists x.\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\forall x.\phi)\Rightarrow(\exists x.\neg\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\exists x.\neg\phi)\Rightarrow(\forall x.\phi)&lt;/math&gt;<br /> We can, though, prove<br /> :&lt;math&gt;\neg(\exists x.\phi)\Rightarrow(\forall x.\neg\phi)&lt;/math&gt;<br /> <br /> If we include, extra, an additional inference rule (called the ''Boolean negation rule'') given by<br /> :[[Image:BooleanNegation.png]]<br /> then suddenly we're back in classical logic, and can prove &lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt; and &lt;math&gt;\phi\or\neg\phi&lt;/math&gt;.<br /> <br /> ====Examples====<br /> <br /> ====Sheaves, topology and time sheaves====<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # blah</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=31906 User:Michiexile/MATH198/Lecture 10 2009-11-24T19:03:46Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;/math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional proogramming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that open sup for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bot\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \wedge Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \vee Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\wedge = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;\vee = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. <br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> We can now proceed to define all the familiar logic connectives one by one, using the topos setting. While doing this, we shall introduce the notation &lt;math&gt;t_A: A\to\Omega&lt;/math&gt; for the morphism &lt;math&gt;t_A = A\to 1\to^{true}\Omega&lt;/math&gt; that takes on the value ''true'' on all of A. We note that with this convention, &lt;math&gt;\chi_{A_0}&lt;/math&gt;, the characteristic morphism of a subobject, is the arrow such that &lt;math&gt;\chi_{A_0}\circ i = t_{A_0}&lt;/math&gt;.<br /> <br /> '''Conjunction''': <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we need to define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; as some &lt;math&gt;P\wedge Q: U\to\Omega&lt;/math&gt; that corresponds to both &lt;math&gt;P&lt;/math&gt; and &lt;math&gt;Q&lt;/math&gt; simultaneously.<br /> <br /> We may define &lt;math&gt;true\times true: 1\to\Omega\times\Omega&lt;/math&gt;, a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Being a subobject, this has a characteristic arrow &lt;math&gt;\wedge:\Omega\times\Omega\to\Omega&lt;/math&gt;, that we call the ''conjunction arrow''.<br /> <br /> Now, we may define &lt;math&gt;\chi_P\times\chi_Q:U\to\Omega\times\Omega&lt;/math&gt; for subobjects &lt;math&gt;P,Q\subseteq U&lt;/math&gt; - and we take their composition &lt;math&gt;\wedge\circ\chi_P\times\chi_Q&lt;/math&gt; to be the characteristic arrow of the subobject &lt;math&gt;P\wedge Q&lt;/math&gt;.<br /> <br /> And, indeed, this results in a topoidal version of intersection of subobjects.<br /> <br /> '''Implication''': <br /> Next we define &lt;math&gt;\leq_1: \Omega_1\to\Omega\times\Omega&lt;/math&gt; to be the equalizer of &lt;math&gt;\wedge&lt;/math&gt; and &lt;math&gt;proj_1&lt;/math&gt;. Given &lt;math&gt;v, w: U\to\Omega&lt;/math&gt;, we write &lt;math&gt;v\leq_1 w&lt;/math&gt; if &lt;math&gt;v\times w&lt;/math&gt; factors through &lt;math&gt;\leq_1&lt;/math&gt;.<br /> <br /> Using the definition of an equalizer we arrive at &lt;math&gt;v\leq_1 w&lt;/math&gt; iff &lt;math&gt;v = v\wedge w&lt;/math&gt;. From this, we can deduce<br /> :&lt;math&gt;u\leq_1 true&lt;/math&gt;<br /> :&lt;math&gt;u\leq_1 u&lt;/math&gt;<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 w&lt;/math&gt; then &lt;math&gt;u\leq_1 w&lt;/math&gt;.<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 u&lt;/math&gt; then &lt;math&gt;u=v&lt;/math&gt;<br /> and thus, &lt;math&gt;\leq_1&lt;/math&gt; is a partial order on &lt;math&gt;[U\to\Omega]&lt;/math&gt;. Intuitively, &lt;math&gt;u\leq_1 v&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is at least as true as &lt;math&gt;u&lt;/math&gt;.<br /> <br /> This relation corresponds to inclusion on subobjects. Note that &lt;math&gt;\leq_1:\Omega_1\to\Omega\times\Omega&lt;/math&gt;, given from the equalizer, gives us &lt;math&gt;\Omega_1&lt;/math&gt; as a ''relation'' on &lt;math&gt;\Omega&lt;/math&gt; - a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Specifically, it has a classifying arrow &lt;math&gt;\Rightarrow:\Omega\times\Omega\to\Omega&lt;/math&gt;. We write &lt;math&gt;h\Rightarrow k = (\Rightarrow)\circ h\times k&lt;/math&gt;. And for subobjects &lt;math&gt;P,Q\subseteq A&lt;/math&gt;, we write &lt;math&gt;P\Rightarrow Q&lt;/math&gt; for the subobject classified by &lt;math&gt;\chi_P\Rightarrow\chi_Q&lt;/math&gt;.<br /> <br /> It turns out, without much work, that this &lt;math&gt;P\Rightarrow Q&lt;/math&gt; behaves just like classical implication in its relationship to &lt;math&gt;\wedge&lt;/math&gt;.<br /> <br /> '''Membership''': <br /> We can internalize the notion of ''membership'' as a subobject &lt;math&gt;\in^A\subseteq A\times\Omega^A&lt;/math&gt;, and thus get the membership relation from a pullback:<br /> :[[Image:ToposMembershipPullback.png]]<br /> <br /> For generalized elements &lt;math&gt;x\times h: T\to A\times\Omega^A&lt;/math&gt;, we write &lt;math&gt;x\in^A h&lt;math&gt; for &lt;math&gt;x\times h\in\in^A&lt;/math&gt;. Both notations indicate &lt;math&gt;ev_A\circ h\times x = true&lt;/math&gt;.<br /> <br /> '''Universal quantification''':<br /> For any object &lt;math&gt;A&lt;/math&gt;, the maximal subobject of &lt;math&gt;A&lt;/math&gt; is &lt;math&gt;A&lt;/math&gt; itself, embedded with &lt;math&gt;1_A&lt;/math&gt; into itself. Thus, we have an arrow &lt;math&gt;t_A:1\to\Omega^A&lt;/math&gt; representing this subobject. Being a map from &lt;math&gt;1&lt;/math&gt;, it is specifically monic, so it has a classifying arrow &lt;math&gt;\forall_A:\Omega^A\to\Omega&lt;/math&gt; that takes a given subobject of &lt;math&gt;A&lt;/math&gt; to &lt;math&gt;true&lt;/math&gt; precisely if it is in fact the maximal subobject.<br /> <br /> Now, with a relation &lt;math&gt;r:R\to B\times A&lt;/math&gt;, we define &lt;math&gt;\forall a. R&lt;/math&gt; by the following pullback:<br /> :[[Image:ToposForallPullback.png]]<br /> where &lt;math&gt;\lambda\chi_r&lt;/math&gt; comes from the universal property of the exponential.<br /> <br /> '''Theorem''' For any &lt;math&gt;s:S\to B&lt;/math&gt; monic, &lt;math&gt;S\subseteq \forall a.R&lt;/math&gt; iff &lt;math&gt;S\times A\subseteq R&lt;/math&gt;.<br /> <br /> This theorem tells us that the subobject given by &lt;math&gt;\forall a.R&lt;/math&gt; is the largest subobject of &lt;math&gt;B&lt;/math&gt; that is related by &lt;math&gt;R&lt;/math&gt; to all of &lt;math&gt;A&lt;/math&gt;.<br /> <br /> '''Falsum''':<br /> We can define the ''false'' truth value using these tools as &lt;math&gt;\forall w\in\Omega.w&lt;/math&gt;. This might be familiar to the more advanced Haskell type hackers - as the type <br /> &lt;haskell&gt;<br /> x :: forall a. a<br /> &lt;/haskell&gt;<br /> which has to be able to give us an element of any type, regardless of the type itself. And in Haskell, the only element that inhabits all types is &lt;hask&gt;undefined&lt;/hask&gt;.<br /> <br /> From a logical perspective, we use a few basic inference rules:<br /> :[[Image:ToposTrivialSequent.png]] [[Image:ToposForallConnective.png]] [[Image:ToposSubstitution.png]]<br /> and connect them up to derive<br /> :&lt;math&gt;*&lt;/math&gt;<br /> :&lt;math&gt;\forall w.w : \forall w.w&lt;/math&gt; <br /> :&lt;math&gt;\forall w.w : w&lt;/math&gt;<br /> :&lt;math&gt;\forall w.w : \phi&lt;/math&gt;<br /> for any &lt;math&gt;\phi&lt;/math&gt; not involving &lt;math&gt;w&lt;/math&gt; - and we can always adjust any &lt;math&gt;\phi&lt;/math&gt; to avoid &lt;math&gt;w&lt;/math&gt;.<br /> <br /> Thus, the formula &lt;math&gt;\forall w.w&lt;/math&gt; has the property that it implies everything - and thus is a good candidate for the ''false'' truth value; since the inference<br /> :[[Image:ToposExFalsoQuodlibet.png]]<br /> is the defining introduction rule for false.<br /> <br /> <br /> '''Negation''':<br /> We define negation the same way as in classical logic: &lt;math&gt;\neg \phi = \phi \Rightarrow false&lt;/math&gt;.<br /> <br /> <br /> '''Disjunction''':<br /> We can define <br /> :&lt;math&gt;P\vee Q = \forall w. ((\phi\Rightarrow w)\wedge(\psi\Rightarrow w))\Rightarrow w&lt;/math&gt;<br /> <br /> Note that this definition uses one of our primary inference rules:<br /> :[[Image:ToposDisjunctionConnective.png]]<br /> as the defining property for the disjunction, and we may derive any properties we like from these.<br /> <br /> '''Existential quantifier''':<br /> Finally, the existential quantifier is derived similarly to the disjunction - by figuring out a rule we want it to obey, and using that as a definition for it:<br /> :&lt;math&gt;\exists x.\phi = \forall w. (\forall x. \phi \Rightarrow w)\Rightarrow w&lt;/math&gt;<br /> <br /> Here, the rule we use as defining property is <br /> :[[Image:ToposExistentsConnective.png]]<br /> <br /> Before we leave this exploration of logic, some properties worth knowing about:<br /> While we can prove &lt;math&gt;\neg(\phi\wedge\neg\phi)&lt;/math&gt; and &lt;math&gt;\phi\Rightarrow\neg\neg\phi&lt;/math&gt;, we cannot, in just topos logic, prove things like<br /> :&lt;math&gt;\neg(\phi\wedge\psi)\Rightarrow(\neg\phi\vee\neg\psi)&lt;/math&gt;<br /> :&lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt;<br /> nor any statements like<br /> :&lt;math&gt;\neg(\forall x.\neg\phi)\Rightarrow(\exists x.\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\forall x.\phi)\Rightarrow(\exists x.\neg\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\exists x.\neg\phi)\Rightarrow(\forall x.\phi)&lt;/math&gt;<br /> We can, though, prove<br /> :&lt;math&gt;\neg(\exists x.\phi)\Rightarrow(\forall x.\neg\phi)&lt;/math&gt;<br /> <br /> If we include, extra, an additional inference rule (called the ''Boolean negation rule'') given by<br /> :[[Image:BooleanNegation.png]]<br /> then suddenly we're back in classical logic, and can prove &lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt; and &lt;math&gt;\phi\or\neg\phi&lt;/math&gt;.<br /> <br /> ====Examples====<br /> <br /> ====Sheaves, topology and time sheaves====<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # blah</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=31896 User:Michiexile/MATH198/Lecture 10 2009-11-24T18:43:03Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;/math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional proogramming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that open sup for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bot\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \wedge Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \vee Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\wedge = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;\vee = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. <br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> <br /> '''Conjunction''': <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we need to define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; as some &lt;math&gt;P\wedge Q: U\to\Omega&lt;/math&gt; that corresponds to both &lt;math&gt;P&lt;/math&gt; and &lt;math&gt;Q&lt;/math&gt; simultaneously. <br /> <br /> We can construct pullback diagrams<br /> :[[Image:ToposConjunctionPart1.png]] [[Image:ToposConjunctionPart2.png]]<br /> in which &lt;math&gt;u = \chi_P\times\chi_Q&lt;/math&gt;. Furthermore, the arrow &lt;math&gt;true\times true: 1\to\Omega\times\Omega&lt;/math&gt; is monic, and thus has a classifier &lt;math&gt;\wedge:\Omega\times\Omega\to\Omega&lt;/math&gt;.<br /> <br /> Now, we define &lt;math&gt;P\wedge Q&lt;/math&gt; as the composition &lt;math&gt;\wedge\circ\chi_P\times\chi_Q&lt;/math&gt;, and observe that &lt;math&gt;P\wedge Q&lt;/math&gt; classifies the intersection &lt;math&gt;P\cap Q&lt;/math&gt;.<br /> <br /> '''Implication''': <br /> Next we define &lt;math&gt;\leq_1&lt;/math&gt; to be the equalizer of &lt;math&gt;\wedge&lt;/math&gt; and &lt;math&gt;proj_1&lt;/math&gt;. Given &lt;math&gt;v\times w: T\to\Omega\times\Omega&lt;/math&gt;, we write &lt;math&gt;v\leq_1 w&lt;/math&gt; if &lt;math&gt;v\times w&lt;/math&gt; factors through &lt;math&gt;\leq_1&lt;/math&gt;.<br /> <br /> Using the definition of an equalizer we arrive at &lt;math&gt;v\leq_1 w&lt;/math&gt; iff &lt;math&gt;v = v\wedge w&lt;/math&gt;. From this, we can deduce<br /> :&lt;math&gt;u\leq_1 true&lt;/math&gt;<br /> :&lt;math&gt;u\leq_1 u&lt;/math&gt;<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 w&lt;/math&gt; then &lt;math&gt;u\leq_1 w&lt;/math&gt;.<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 u&lt;/math&gt; then &lt;math&gt;u=v&lt;/math&gt;<br /> and thus, &lt;math&gt;\leq_1&lt;/math&gt; is a partial order on &lt;math&gt;[T\to\Omega]&lt;/math&gt;. Intuitively, &lt;math&gt;u\leq_1 v&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is at least as true as &lt;math&gt;u&lt;/math&gt;.<br /> <br /> This relation corresponds to inclusion on subobjects. Note that &lt;math&gt;\leq_1:\Omega_1\to\Omega\times\Omega&lt;/math&gt;, given from the equalizer, gives us &lt;math&gt;\Omega_1&lt;/math&gt; as a ''relation'' on &lt;math&gt;\Omega&lt;/math&gt; - a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Specifically, it has a classifying arrow &lt;math&gt;\Rightarrow:\Omega\times\Omega\to\Omega&lt;/math&gt;. We write &lt;math&gt;h\Rightarrow k = \Rightarrow\circ h\times k&lt;/math&gt;. And for subobjects &lt;math&gt;P,Q\subseteq A&lt;/math&gt;, we write &lt;math&gt;P\Rightarrow Q&lt;/math&gt; for the subobject classified by &lt;math&gt;\chi_P\Rightarrow\chi_Q&lt;/math&gt;.<br /> <br /> It turns out, without much work, that this &lt;math&gt;P\Rightarrow Q&lt;/math&gt; behaves just like classical implication in its relationship to &lt;math&gt;\wedge&lt;/math&gt;.<br /> <br /> '''Membership''': <br /> We can internalize the notion of ''membership'' as a subobject &lt;math&gt;\in^A\subseteq A\times\Omega^A&lt;/math&gt;, and thus get the membership relation from a pullback:<br /> :[[Image:ToposMembershipPullback.png]]<br /> <br /> For generalized elements &lt;math&gt;x\times h: T\to A\times\Omega^A&lt;/math&gt;, we write &lt;math&gt;x\in^A h&lt;math&gt; for &lt;math&gt;x\times h\in\in^A&lt;/math&gt;. Both notations indicate &lt;math&gt;ev_A\circ h\times x = true&lt;/math&gt;.<br /> <br /> '''Universal quantification''':<br /> For any object &lt;math&gt;A&lt;/math&gt;, the maximal subobject of &lt;math&gt;A&lt;/math&gt; is &lt;math&gt;A&lt;/math&gt; itself, embedded with &lt;math&gt;1_A&lt;/math&gt; into itself. Thus, we have an arrow &lt;math&gt;t_A:1\to\Omega^A&lt;/math&gt; representing this subobject. Being a map from &lt;math&gt;1&lt;/math&gt;, it is specifically monic, so it has a classifying arrow &lt;math&gt;\forall_A:\Omega^A\to\Omega&lt;/math&gt; that takes a given subobject of &lt;math&gt;A&lt;/math&gt; to &lt;math&gt;true&lt;/math&gt; precisely if it is in fact the maximal subobject.<br /> <br /> Now, with a relation &lt;math&gt;r:R\to B\times A&lt;/math&gt;, we define &lt;math&gt;\forall a. R&lt;/math&gt; by the following pullback:<br /> :[[Image:ToposForallPullback.png]]<br /> where &lt;math&gt;\lambda\chi_r&lt;/math&gt; comes from the universal property of the exponential.<br /> <br /> '''Theorem''' For any &lt;math&gt;s:S\to B&lt;/math&gt; monic, &lt;math&gt;S\subseteq \forall a.R&lt;/math&gt; iff &lt;math&gt;S\times A\subseteq R&lt;/math&gt;.<br /> <br /> This theorem tells us that the subobject given by &lt;math&gt;\forall a.R&lt;/math&gt; is the largest subobject of &lt;math&gt;B&lt;/math&gt; that is related by &lt;math&gt;R&lt;/math&gt; to all of &lt;math&gt;A&lt;/math&gt;.<br /> <br /> '''Falsum''':<br /> We can define the ''false'' truth value using these tools as &lt;math&gt;\forall w\in\Omega.w&lt;/math&gt;. This might be familiar to the more advanced Haskell type hackers - as the type <br /> &lt;haskell&gt;<br /> x :: forall a. a<br /> &lt;/haskell&gt;<br /> which has to be able to give us an element of any type, regardless of the type itself. And in Haskell, the only element that inhabits all types is &lt;hask&gt;undefined&lt;/hask&gt;.<br /> <br /> From a logical perspective, we use a few basic inference rules:<br /> :[[Image:ToposTrivialSequent.png]] [[Image:ToposForallConnective.png]] [[Image:ToposSubstitution.png]]<br /> and connect them up to derive<br /> :&lt;math&gt;*&lt;/math&gt;<br /> :&lt;math&gt;\forall w.w : \forall w.w&lt;/math&gt; <br /> :&lt;math&gt;\forall w.w : w&lt;/math&gt;<br /> :&lt;math&gt;\forall w.w : \phi&lt;/math&gt;<br /> for any &lt;math&gt;\phi&lt;/math&gt; not involving &lt;math&gt;w&lt;/math&gt; - and we can always adjust any &lt;math&gt;\phi&lt;/math&gt; to avoid &lt;math&gt;w&lt;/math&gt;.<br /> <br /> Thus, the formula &lt;math&gt;\forall w.w&lt;/math&gt; has the property that it implies everything - and thus is a good candidate for the ''false'' truth value; since the inference<br /> :[[Image:ToposExFalsoQuodlibet.png]]<br /> is the defining introduction rule for false.<br /> <br /> <br /> '''Negation''':<br /> We define negation the same way as in classical logic: &lt;math&gt;\neg \phi = \phi \Rightarrow false&lt;/math&gt;.<br /> <br /> <br /> '''Disjunction''':<br /> We can define <br /> :&lt;math&gt;P\vee Q = \forall w. ((\phi\Rightarrow w)\wedge(\psi\Rightarrow w))\Rightarrow w&lt;/math&gt;<br /> <br /> Note that this definition uses one of our primary inference rules:<br /> :[[Image:ToposDisjunctionConnective.png]]<br /> as the defining property for the disjunction, and we may derive any properties we like from these.<br /> <br /> '''Existential quantifier''':<br /> Finally, the existential quantifier is derived similarly to the disjunction - by figuring out a rule we want it to obey, and using that as a definition for it:<br /> :&lt;math&gt;\exists x.\phi = \forall w. (\forall x. \phi \Rightarrow w)\Rightarrow w&lt;/math&gt;<br /> <br /> Here, the rule we use as defining property is <br /> :[[Image:ToposExistentsConnective.png]]<br /> <br /> Before we leave this exploration of logic, some properties worth knowing about:<br /> While we can prove &lt;math&gt;\neg(\phi\wedge\neg\phi)&lt;/math&gt; and &lt;math&gt;\phi\Rightarrow\neg\neg\phi&lt;/math&gt;, we cannot, in just topos logic, prove things like<br /> :&lt;math&gt;\neg(\phi\wedge\psi)\Rightarrow(\neg\phi\vee\neg\psi)&lt;/math&gt;<br /> :&lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt;<br /> nor any statements like<br /> :&lt;math&gt;\neg(\forall x.\neg\phi)\Rightarrow(\exists x.\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\forall x.\phi)\Rightarrow(\exists x.\neg\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\exists x.\neg\phi)\Rightarrow(\forall x.\phi)&lt;/math&gt;<br /> We can, though, prove<br /> :&lt;math&gt;\neg(\exists x.\phi)\Rightarrow(\forall x.\neg\phi)&lt;/math&gt;<br /> <br /> If we include, extra, an additional inference rule (called the ''Boolean negation rule'') given by<br /> :[[Image:BooleanNegation.png]]<br /> then suddenly we're back in classical logic, and can prove &lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt; and &lt;math&gt;\phi\or\neg\phi&lt;/math&gt;.<br /> <br /> ====Examples====<br /> <br /> ====Sheaves, topology and time sheaves====<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # blah</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=31893 User:Michiexile/MATH198/Lecture 10 2009-11-24T17:05:21Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;/math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional proogramming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that open sup for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bot\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \wedge Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \vee Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\wedge = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;\vee = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. <br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> <br /> '''Conjunction''': <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we need to define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; as some &lt;math&gt;P\wedge Q: U\to\Omega&lt;/math&gt; that corresponds to both &lt;math&gt;P&lt;/math&gt; and &lt;math&gt;Q&lt;/math&gt; simultaneously. <br /> <br /> We can construct pullback diagrams<br /> :[[Image:ToposConjunctionPart1.png]] [[Image:ToposConjunctionPart2.png]]<br /> in which &lt;math&gt;u = \chi_P\times\chi_Q&lt;/math&gt;. Furthermore, the arrow &lt;math&gt;true\times\true: 1\to\Omega\times\Omega&lt;/math&gt; is monic, and thus has a classifier &lt;math&gt;\wedge:\Omega\times\Omega\to\Omega&lt;/math&gt;.<br /> <br /> Now, we define &lt;math&gt;P\wedge Q&lt;/math&gt; as the composition &lt;math&gt;\wedge\circ\chi_P\times\chi_Q&lt;/math&gt;, and observe that &lt;math&gt;P\wedge Q&lt;/math&gt; classifies the intersection &lt;math&gt;P\cap Q&lt;/math&gt;.<br /> <br /> '''Implication''': <br /> Next we define &lt;math&gt;\leq_1&lt;/math&gt; to be the equalizer of &lt;math&gt;\wedge&lt;/math&gt; and &lt;math&gt;proj_1&lt;/math&gt;. Given &lt;math&gt;v\times w: T\to\Omega\times\Omega&lt;/math&gt;, we write &lt;math&gt;v\leq_1 w&lt;/math&gt; if &lt;math&gt;v\times w&lt;/math&gt; factors through &lt;math&gt;\leq_1&lt;/math&gt;.<br /> <br /> Using the definition of an equalizer we arrive at &lt;math&gt;v\leq_1 w&lt;/math&gt; iff &lt;math&gt;v = v\wedge w&lt;/math&gt;. From this, we can deduce<br /> :&lt;math&gt;u\leq_1 true&lt;/math&gt;<br /> :&lt;math&gt;u\leq_1 u&lt;/math&gt;<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 w&lt;/math&gt; then &lt;math&gt;u\leq_1 w&lt;/math&gt;.<br /> :If &lt;math&gt;u\leq_1 v&lt;/math&gt; and &lt;math&gt;v\leq_1 u&lt;/math&gt; then &lt;math&gt;u=v&lt;/math&gt;<br /> and thus, &lt;math&gt;\leq_1&lt;/math&gt; is a partial order on &lt;math&gt;[T\to\Omega]&lt;/math&gt;. Intuitively, &lt;math&gt;u\leq_1 v&lt;/math&gt; if &lt;math&gt;v&lt;/math&gt; is at least as true as &lt;math&gt;u&lt;/math&gt;.<br /> <br /> This relation corresponds to inclusion on subobjects. Note that &lt;math&gt;\leq_1:\Omega_1\to\Omega\times\Omega&lt;/math&gt;, given from the equalizer, gives us &lt;math&gt;\Omega_1&lt;/math&gt; as a ''relation'' on &lt;math&gt;\Omega&lt;/math&gt; - a subobject of &lt;math&gt;\Omega\times\Omega&lt;/math&gt;. Specifically, it has a classifying arrow &lt;math&gt;\Rightarrow:\Omega\times\Omega\to\Omega&lt;/math&gt;. We write &lt;math&gt;h\Rightarrow k = \Rightarrow\circ h\times k&lt;/math&gt;. And for subobjects &lt;math&gt;P,Q\subseteq A&lt;/math&gt;, we write &lt;math&gt;P\Rightarrow Q&lt;/math&gt; for the subobject classified by &lt;math&gt;\chi_P\Rightarrow\chi_Q&lt;/math&gt;.<br /> <br /> It turns out, without much work, that this &lt;math&gt;P\Rightarrow Q&lt;/math&gt; behaves just like classical implication in its relationship to &lt;math&gt;\wedge&lt;/math&gt;.<br /> <br /> '''Membership''': <br /> We can internalize the notion of ''membership'' as a subobject &lt;math&gt;\in^A\subseteq A\times\Omega^A&lt;/math&gt;, and thus get the membership relation from a pullback:<br /> :[[Image:ToposMembershipPullback.png]]<br /> <br /> For generalized elements &lt;math&gt;x\times h: T\to A\times\Omega^A&lt;/math&gt;, we write &lt;math&gt;x\in^A h&lt;math&gt; for &lt;math&gt;x\times h\in\in^A&lt;/math&gt;. Both notations indicate &lt;math&gt;ev_A\circ h\times x = true&lt;/math&gt;.<br /> <br /> '''Universal quantification''':<br /> For any object &lt;math&gt;A&lt;/math&gt;, the maximal subobject of &lt;math&gt;A&lt;/math&gt; is &lt;math&gt;A&lt;/math&gt; itself, embedded with &lt;math&gt;1_A&lt;/math&gt; into itself. Thus, we have an arrow &lt;math&gt;t_A:1\to\Omega^A&lt;/math&gt; representing this subobject. Being a map from &lt;math&gt;1&lt;/math&gt;, it is specifically monic, so it has a classifying arrow &lt;math&gt;\forall_A:\Omega^A\to\Omega&lt;/math&gt; that takes a given subobject of &lt;math&gt;A&lt;/math&gt; to &lt;math&gt;true&lt;/math&gt; precisely if it is in fact the maximal subobject.<br /> <br /> Now, with a relation &lt;math&gt;r:R\to B\times A&lt;/math&gt;, we define &lt;math&gt;\forall a. R&lt;/math&gt; by the following pullback:<br /> :[[Image:ToposForallPullback.png]]<br /> where &lt;math&gt;\lambda\chi_r&lt;/math&gt; comes from the universal property of the exponential.<br /> <br /> '''Theorem''' For any &lt;math&gt;s:S\to B&lt;/math&gt; monic, &lt;math&gt;S\subseteq \forall a.R&lt;/math&gt; iff &lt;math&gt;S\times A\subseteq R&lt;/math&gt;.<br /> <br /> This theorem tells us that the subobject given by &lt;math&gt;\forall a.R&lt;/math&gt; is the largest subobject of &lt;math&gt;B&lt;/math&gt; that is related by &lt;math&gt;R&lt;/math&gt; to all of &lt;math&gt;A&lt;/math&gt;.<br /> <br /> '''Falsum''':<br /> We can define the ''false'' truth value using these tools as &lt;math&gt;\forall w\in\Omega.w&lt;/math&gt;. This might be familiar to the more advanced Haskell type hackers - as the type <br /> &lt;haskell&gt;<br /> x :: forall a. a<br /> &lt;/haskell&gt;<br /> which has to be able to give us an element of any type, regardless of the type itself. And in Haskell, the only element that inhabits all types is &lt;hask&gt;undefined&lt;/hask&gt;.<br /> <br /> From a logical perspective, we use a few basic inference rules:<br /> :[[Image:ToposTrivialSequent.png]] [[Image:ToposForallConnective.png]] [[Image:ToposSubstitution.png]]<br /> and connect them up to derive<br /> :&lt;math&gt;*&lt;/math&gt;<br /> :&lt;math&gt;\forall w.w : \forall w.w&lt;/math&gt; <br /> :&lt;math&gt;\forall w.w : w&lt;/math&gt;<br /> :&lt;math&gt;\forall w.w : \phi&lt;/math&gt;<br /> for any &lt;math&gt;\phi&lt;/math&gt; not involving &lt;math&gt;w&lt;/math&gt; - and we can always adjust any &lt;math&gt;\phi&lt;/math&gt; to avoid &lt;math&gt;w&lt;/math&gt;.<br /> <br /> Thus, the formula &lt;math&gt;\forall w.w&lt;/math&gt; has the property that it implies everything - and thus is a good candidate for the ''false'' truth value; since the inference<br /> :[[Image:ToposExFalsoQuodlibet.png]]<br /> is the defining introduction rule for false.<br /> <br /> <br /> '''Negation''':<br /> We define negation the same way as in classical logic: &lt;math&gt;\neg \phi = \phi \Rightarrow false&lt;/math&gt;.<br /> <br /> <br /> '''Disjunction''':<br /> We can define <br /> :&lt;math&gt;P\vee Q = \forall w. ((\phi\Rightarrow w)\wedge(\psi\Rightarrow w))\Rightarrow w&lt;/math&gt;<br /> <br /> Note that this definition uses one of our primary inference rules:<br /> :[[Image:ToposDisjunctionConnective.png]]<br /> as the defining property for the disjunction, and we may derive any properties we like from these.<br /> <br /> '''Existential quantifier''':<br /> Finally, the existential quantifier is derived similarly to the disjunction - by figuring out a rule we want it to obey, and using that as a definition for it:<br /> :&lt;math&gt;\exists x.\phi = \forall w. (\forall x. \phi \Rightarrow w)\Rightarrow w&lt;/math&gt;<br /> <br /> Here, the rule we use as defining property is <br /> :[[Image:ToposExistentsConnective.png]]<br /> <br /> Before we leave this exploration of logic, some properties worth knowing about:<br /> While we can prove &lt;math&gt;\neg(\phi\wedge\neg\phi)&lt;/math&gt; and &lt;math&gt;\phi\Rightarrow\neg\neg\phi&lt;/math&gt;, we cannot, in just topos logic, prove things like<br /> :&lt;math&gt;\neg(\phi\wedge\psi)\Rightarrow(\neg\phi\vee\neg\psi)&lt;/math&gt;<br /> :&lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt;<br /> nor any statements like<br /> :&lt;math&gt;\neg(\forall x.\neg\phi)\Rightarrow(\exists x.\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\forall x.\phi)\Rightarrow(\exists x.\neg\phi)&lt;/math&gt;<br /> :&lt;math&gt;\neg(\exists x.\neg\phi)\Rightarrow(\forall x.\phi)&lt;/math&gt;<br /> We can, though, prove<br /> :&lt;math&gt;\neg(\exists x.\phi)\Rightarrow(\forall x.\neg\phi)&lt;/math&gt;<br /> <br /> If we include, extra, an additional inference rule (called the ''Boolean negation rule'') given by<br /> :[[Image:BooleanNegation.png]]<br /> then suddenly we're back in classical logic, and can prove &lt;math&gt;\neg\neg\phi\Rightarrow\phi&lt;/math&gt; and &lt;math&gt;\phi\or\neg\phi&lt;/math&gt;.<br /> <br /> ====Examples====<br /> <br /> ====Sheaves, topology and time sheaves====<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # blah</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=31703 User:Michiexile/MATH198/Lecture 10 2009-11-22T22:01:54Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;/math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional proogramming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ((universal property of power object?))<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that open sup for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bot\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \wedge Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \vee Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : \exists y. P(x,y) \}&lt;/math&gt; is given by the construction (...)<br /> :&lt;math&gt;\{x : \forall y. P(x,y) \}&lt;/math&gt; is given by the construction (...)<br /> <br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\wedge = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;\vee = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. <br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; to be the pullback (pushout?)<br /> :[[Image:ToposConjunction.png]]<br /> <br /> This mimics, closely, the idea of the conjunction as an intersection.<br /> <br /> We further define the ''disjunction'' &lt;math&gt;P\vee Q&lt;/math&gt; to be the pushout (pullback?)<br /> :[[Image:ToposDisjunction.png]]<br /> <br /> And we define ''negation'' &lt;math&gt;\neg P&lt;/math&gt; by (...)<br /> <br /> We can expand this language further - and introduce predicative connectives. <br /> <br /> Now, a statement on the form &lt;math&gt;\forall x. P(x)&lt;/math&gt; is usually taken to mean that on all &lt;math&gt;x\in U&lt;/math&gt;, the predicate &lt;math&gt;P&lt;/math&gt; holds true. Thus, translating to the operations-on-subsets paradigm, &lt;math&gt;\forall x. P(x)&lt;/math&gt; corresponds to the statement &lt;math&gt;P = U&lt;/math&gt;.<br /> <br /> ((double check in Awodey &amp; Barr-Wells!!!!))<br /> <br /> So we can define a topoidal &lt;math&gt;\forall x. P(x)&lt;/math&gt; by ((diagrams))<br /> <br /> And similarily, the statement &lt;math&gt;\exists x. P(x)&lt;/math&gt; means that &lt;math&gt;P&lt;/math&gt; is non-empty.<br /> <br /> ====Examples====<br /> <br /> ====Sheaves, topology and time sheaves====<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # blah</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=31702 User:Michiexile/MATH198/Lecture 10 2009-11-22T21:48:53Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional proogramming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ((universal property of power object?))<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, and predicate logic, we would say that a ''predicate'' is some function from a universe to a set of truth values. So a predicate takes some sort of objects, and returns either True or False.<br /> <br /> Furthermore, we allow the definition of sets using predicates:<br /> :&lt;math&gt;\{x\in U: P(x)\}&lt;/math&gt;<br /> <br /> Looking back, though, there is no essential difference between this, and defining the predicate as the subset of the universe directly; the predicate-as-function appears, then, as the characteristic function of the subset. And types are added as easily - we specify each variable, each object, to have a set it belongs to.<br /> <br /> This way, predicates really are subsets. Type annotations decide which set the predicate lives in. And we have everything set up in a way that open sup for the topos language above.<br /> <br /> We'd define, for predicates &lt;math&gt;P, Q&lt;/math&gt; acting on the same type:<br /> :&lt;math&gt;\{x\in A : \top\} = A&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : \bottom\} = \emptyset&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P \&amp; Q)(x)\} = \{x : P(x)\} \cap \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : (P | Q)(x)\} = \{x : P(x)\} \cup \{x : Q(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x\in A : (\neg P)(x) \} = A \setminus \{x\in A : P(x)\}&lt;/math&gt;<br /> :&lt;math&gt;\{x : \exists y. P(x,y) \}&lt;/math&gt; is given by the construction (...)<br /> :&lt;math&gt;\{x : \forall y. P(x,y) \}&lt;/math&gt; is given by the construction (...)<br /> <br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\&amp; = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;| = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. <br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; to be the pullback (pushout?)<br /> :[[Image:ToposConjunction.png]]<br /> <br /> This mimics, closely, the idea of the conjunction as an intersection.<br /> <br /> We further define the ''disjunction'' &lt;math&gt;P\vee Q&lt;/math&gt; to be the pushout (pullback?)<br /> :[[Image:ToposDisjunction.png]]<br /> <br /> And we define ''negation'' &lt;math&gt;\neg P&lt;/math&gt; by (...)<br /> <br /> We can expand this language further - and introduce predicative connectives. <br /> <br /> Now, a statement on the form &lt;math&gt;\forall x. P(x)&lt;/math&gt; is usually taken to mean that on all &lt;math&gt;x\in U&lt;/math&gt;, the predicate &lt;math&gt;P&lt;/math&gt; holds true. Thus, translating to the operations-on-subsets paradigm, &lt;math&gt;\forall x. P(x)&lt;/math&gt; corresponds to the statement &lt;math&gt;P = U&lt;/math&gt;.<br /> <br /> ((double check in Awodey &amp; Barr-Wells!!!!))<br /> <br /> So we can define a topoidal &lt;math&gt;\forall x. P(x)&lt;/math&gt; by ((diagrams))<br /> <br /> And similarily, the statement &lt;math&gt;\exists x. P(x)&lt;/math&gt; means that &lt;math&gt;P&lt;/math&gt; is non-empty.<br /> <br /> ====Examples====<br /> <br /> ====Sheaves, topology and time sheaves====<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # blah</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=31701 User:Michiexile/MATH198/Lecture 10 2009-11-22T18:43:29Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> This lecture will be shallow, and leave many things undefined, hinted at, and is mostly meant as an appetizer, enticing the audience to go forth and seek out the literature on topos theory for further studies.<br /> <br /> ===Subobject classifier===<br /> <br /> One very useful property of the category &lt;math&gt;Set&lt;/math&gt; is that the powerset of a given set is still a set; we have an internal concept of ''object of all subobjects''. Certainly, for any category (small enough) &lt;math&gt;C&lt;/math&gt;, we have a contravariant functor &lt;math&gt;Sub(-): C\to Set&lt;/math&gt; taking an object to the set of all equivalence classes of monomorphisms into that object; with the image &lt;math&gt;Sub(f)&lt;/math&gt; given by the pullback diagram<br /> :[[Image:SubobjectFunctorMorphismPullback.png]]<br /> <br /> If the functor &lt;math&gt;Sub(-)&lt;/math&gt; is ''representable'' - meaning that there is some object &lt;math&gt;X\in C_0&lt;/math&gt; such that &lt;math&gt;Sub(-) = hom(-,X)&lt;/math&gt; - then the theory surrounding representable functors, connected to the Yoneda lemma - give us a number of good properties.<br /> <br /> One of them is that every representable functor has a ''universal element''; a generalization of the kind of universal mapping properties we've seen in definitions over and over again during this course; all the definitions that posit the unique existence of some arrow in some diagram given all other arrows.<br /> <br /> Thus, in a category with a representable subobject functor, we can pick a representing object &lt;math&gt;\Omega\in C_0&lt;/math&gt;, such that &lt;math&gt;Sub(X) = hom(X,\Omega)&lt;/math&gt;. Furthermore, picking a universal element corresponds to picking a subobject &lt;math&gt;\Omega_0\hookrightarrow\Omega&lt;/math&gt; such that for any object &lt;math&gt;A&lt;/math&gt; and subobject &lt;math&gt;A_0\hookrightarrow A&lt;/math&gt;, there is a unique arrow &lt;math&gt;\chi: A\to\Omega&lt;/math&gt; such that there is a pullback diagram<br /> :[[Image:SubobjectClassifierPullback.png]]<br /> <br /> One can prove that &lt;math&gt;\Omega_0&lt;/math&gt; is terminal in &lt;math&gt;C&lt;/math&gt;, and we shall call &lt;math&gt;\Omega&lt;math&gt; the ''subobject classifier'', and this arrow &lt;math&gt;\Omega_0=1\to\Omega&lt;/math&gt; ''true''. The arrow &lt;math&gt;\chi&lt;/math&gt; is called the characteristic arrow of the subobject.<br /> <br /> In Set, all this takes on a familiar tone: the subobject classifier is a 2-element set, with a ''true'' element distinguished; and a characteristic function of a subset takes on the ''true'' value for every element in the subset, and the other (false) value for every element not in the subset.<br /> <br /> ===Defining topoi===<br /> <br /> '''Definition''' A ''topos'' is a cartesian closed category with all finite limits and with a subobject classifier.<br /> <br /> It is worth noting that this is a far stronger condition than anything we can even hope to fulfill for the category of Haskell types and functions. The functional proogramming relevance will take a back seat in this lecture, in favour of usefulness in logic and set theory replacements.<br /> <br /> ===Properties of topoi===<br /> <br /> The meat is in the properties we can prove about topoi, and in the things that turn out to be topoi. <br /> <br /> '''Theorem''' Let &lt;math&gt;E&lt;/math&gt; be a topos. <br /> * &lt;math&gt;E&lt;/math&gt; has finite colimits.<br /> <br /> ====Power object====<br /> <br /> Since a topos is closed, we can take exponentials. Specifically, we can consider &lt;math&gt;[A\to\Omega]&lt;/math&gt;. This is an object such that &lt;math&gt;hom(B,[A\to\Omega]) = hom(A\times B, \Omega) = Sub(A\times B)&lt;/math&gt;. Hence, we get an internal version of the subobject functor. (pick &lt;math&gt;B&lt;/math&gt; to be the terminal object to get a sense for how global elements of &lt;math&gt;[A\to\Omega]&lt;/math&gt; correspond to subobjects of &lt;math&gt;A&lt;/math&gt;)<br /> <br /> ((universal property of power object?))<br /> <br /> ====Internal logic====<br /> <br /> We can use the properties of a topos to develop a logic theory - mimicking the development of logic by considering operations on subsets in a given universe:<br /> <br /> Classically, in Set, we would say that a ''predicate'' corresponds to the set of elements on which the predicate holds true. Thus, say, for statements about integers, the set &lt;math&gt;\{n\in\mathbb Z: n&gt;0\}&lt;/math&gt; would correspond to the predicate &lt;math&gt;n&gt;0&lt;/math&gt;.<br /> <br /> We could then start to define primitive logic connectives as set operations; the intersection of two sets is the set on which '''both''' the corresponding predicates hold true, so &lt;math&gt;\&amp; = \cap&lt;/math&gt;. Similarily, the union of two sets is the set on which either of the corresponding predicates holds true, so &lt;math&gt;| = \cup&lt;/math&gt;. The complement of a set, in the universe, is the negation of the predicate, and all other propositional connectives (implication, equivalence, ...) can be built with conjunction (and), disjunction (or) and negation (not).<br /> <br /> So we can mimic all these in a given topos:<br /> <br /> We say that a ''universe'' &lt;math&gt;U&lt;/math&gt; is just an object in a given topos. <br /> <br /> A ''predicate'' is a subobject of the universe.<br /> <br /> Given predicates &lt;math&gt;P, Q&lt;/math&gt;, we define the ''conjunction'' &lt;math&gt;P\wedge Q&lt;/math&gt; to be the pullback (pushout?)<br /> :[[Image:ToposConjunction.png]]<br /> <br /> This mimics, closely, the idea of the conjunction as an intersection.<br /> <br /> We further define the ''disjunction'' &lt;math&gt;P\vee Q&lt;/math&gt; to be the pushout (pullback?)<br /> :[[Image:ToposDisjunction.png]]<br /> <br /> And we define ''negation'' &lt;math&gt;\neg P&lt;/math&gt; by (...)<br /> <br /> We can expand this language further - and introduce predicative connectives. <br /> <br /> Now, a statement on the form &lt;math&gt;\forall x. P(x)&lt;/math&gt; is usually taken to mean that on all &lt;math&gt;x\in U&lt;/math&gt;, the predicate &lt;math&gt;P&lt;/math&gt; holds true. Thus, translating to the operations-on-subsets paradigm, &lt;math&gt;\forall x. P(x)&lt;/math&gt; corresponds to the statement &lt;math&gt;P = U&lt;/math&gt;.<br /> <br /> ((double check in Awodey &amp; Barr-Wells!!!!))<br /> <br /> So we can define a topoidal &lt;math&gt;\forall x. P(x)&lt;/math&gt; by ((diagrams))<br /> <br /> And similarily, the statement &lt;math&gt;\exists x. P(x)&lt;/math&gt; means that &lt;math&gt;P&lt;/math&gt; is non-empty.<br /> <br /> ====Examples====<br /> <br /> ====Sheaves, topology and time sheaves====<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # blah</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_10&diff=31626 User:Michiexile/MATH198/Lecture 10 2009-11-17T18:44:57Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Power objects===<br /> <br /> ===Classifying objects===<br /> <br /> ===Topoi===<br /> <br /> ===Internal logic===<br /> <br /> ===Exercises===<br /> <br /> No homework at this point. However, if you want something to think about, a few questions and exercises:<br /> <br /> # blah</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198&diff=31625 User:Michiexile/MATH198 2009-11-17T18:43:14Z <p>Michiexile: </p> <hr /> <div>==Course overview==<br /> <br /> Page is work in progress for background material for the Fall 2009 lecture course MATH198[http://coursework.stanford.edu/homepage/F09/F09-MATH-198-01.html] on Category Theory and Functional Programming that I am planning to give at Stanford University.<br /> <br /> Single unit course. 10 lectures. Each lecture is Wednesday 4.15-5.05 in 380F.<br /> <br /> <br /> * [[User:Michiexile/MATH198/Lecture 1]]<br /> ** Category: Definition and examples.<br /> ** Concrete categories.<br /> *** Set.<br /> *** Various categories capturing linear algebra.<br /> ** Small categories.<br /> *** Partial orders.<br /> *** Monoids.<br /> *** Finite groups.<br /> ** Haskell-Curry isomorphism.<br /> <br /> <br /> * [[User:Michiexile/MATH198/Lecture 2]]<br /> ** Special morphisms<br /> *** Epimorphism.<br /> *** Monomorphism.<br /> *** Isomorphism.<br /> *** Endomorphism.<br /> *** Automorphism.<br /> ** Special objects<br /> *** Initial. <br /> *** Terminal. <br /> *** Null.<br /> <br /> * [[User:Michiexile/MATH198/Lecture 3]]<br /> ** Functors.<br /> ** Category of categories.<br /> ** Natural transformations.<br /> <br /> * [[User:Michiexile/MATH198/Lecture 4]]<br /> ** Products, coproducts.<br /> ** The power of dualization.<br /> ** The algebra of datatypes<br /> <br /> <br /> * [[User:Michiexile/MATH198/Lecture 5]]<br /> ** Limits, colimits.<br /> <br /> * [[User:Michiexile/MATH198/Lecture 6]]<br /> ** Equalizers, coequalizers.<br /> ** Pushouts/pullbacks<br /> ** Adjunctions.<br /> ** Free and forgetful.<br /> <br /> <br /> * [[User:Michiexile/MATH198/Lecture 7]]<br /> ** Monoid objects.<br /> ** Monads.<br /> ** Triples.<br /> ** Kleisli category.<br /> ** Monad factorization.<br /> <br /> * [[User:Michiexile/MATH198/Lecture 8]]<br /> ** Algebras over monads<br /> ** Algebras over endofunctors<br /> ** Initial algebras and recursion<br /> ** Lambek's lemma<br /> <br /> * [[User:Michiexile/MATH198/Lecture 9]]<br /> ** Catamorphisms<br /> ** Anamorphisms<br /> ** Hylomorphisms<br /> ** Metamorphisms<br /> ** Paramorphisms<br /> ** Apomorphisms<br /> ** Properties of adjunctions, examples of adjunctions<br /> <br /> * [[User:Michiexile/MATH198/Lecture 10]]<br /> ** Power objects<br /> ** Classifying objects<br /> ** Topoi<br /> ** Internal logic</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_9&diff=31624 User:Michiexile/MATH198/Lecture 9 2009-11-17T18:40:38Z <p>Michiexile: </p> <hr /> <div>===Recursion patterns===<br /> <br /> Meijer, Fokkinga &amp; Patterson identified in the paper ''Functional programming with bananas, lenses, envelopes and barbed wire'' a number of generic patterns for recursive programming that they had observed, catalogued and systematized. The aim of that paper is to establish a number of ''rules'' for modifying and rewriting expressions involving these generic recursion patterns.<br /> <br /> As it turns out, these patterns are instances of the same phenomenon we saw last lecture: where the recursion comes from specifying a different algebra, and then take a uniquely existing morphism induced by initiality (or, as we shall see, finality). <br /> <br /> Before we go through the recursion patterns, we need to establish a few pieces of theoretical language, dualizing the Eilenberg-Moore algebra constructions from the last lecture.<br /> <br /> ====Coalgebras for endofunctors====<br /> <br /> '''Definition''' If &lt;math&gt;P: C\to C&lt;/math&gt; is an endofunctor, then a &lt;math&gt;P&lt;/math&gt;-''coalgebra'' on &lt;math&gt;A&lt;/math&gt; is a morphism &lt;math&gt;a: A\to PA&lt;/math&gt;.<br /> <br /> A ''morphism of coalgebras'': &lt;math&gt;f: a\to b&lt;/math&gt; is some &lt;math&gt;f: A\to B&lt;/math&gt; such that the diagram <br /> :[[Image:CoalgebraMorphism.png]]<br /> commutes. <br /> <br /> Just as with algebras, we get a category of coalgebras. And the interesting objects here are the ''final coalgebras''. Just as with algebras, we have<br /> <br /> '''Lemma''' (''Lambek'') If &lt;math&gt;a: A\to PA&lt;/math&gt; is a final coalgebra, it is an isomorphism.<br /> <br /> Finally, one thing that makes us care highly about these entities: in an appropriate category (such as &lt;math&gt;\omega-CPO&lt;/math&gt;), initial algebras and final coalgebras coincide, with the correspondence given by inverting the algebra/coalgebra morphism. In Haskell not quite true (specifically, the final coalgebra for the lists functor gives us streams...).<br /> <br /> Onwards to recursion schemes!<br /> <br /> We shall define a few specific morphisms we'll use repeatedly. This notation, introduced here, occurs all over the place in these corners of the literature, and are good to be aware of in general: <br /> * If &lt;math&gt;a: TA\to A&lt;/math&gt; is an initial algebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = in_A&lt;/math&gt;.<br /> * If &lt;math&gt;a: A\to TA&lt;/math&gt; is a final coalgebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = out_A&lt;/math&gt;.<br /> * We write &lt;math&gt;\mu f&lt;/math&gt; for the fixed point operator<br /> &lt;haskell&gt;<br /> mu f = x where x = f x<br /> &lt;/haskell&gt;<br /> <br /> We note that in the situation considered by MFP, inital algebras and final coalgebras coincide, and thus &lt;math&gt;in_A, out_A&lt;/math&gt; are the pair of isomorphic maps induced by either the initial algebra- or the final coalgebra-structure.<br /> <br /> ====Catamorphisms====<br /> <br /> A ''catamorphism'' is the uniquely existing morphism from an initial algebra to a different algebra. We have to define maps down to the return value type for each of the constructors of the complex data type we're recursing over, and the catamorphism will deconstruct the structure (trees, lists, ...) and do a generalized ''fold'' over the structure at hand before returning the final value.<br /> <br /> The intuition is that for catamorphisms we start essentially structured, and dismantle the structure.<br /> <br /> '''Example''': the length function from last lecture. This is the catamorphism for the functor &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; given by the maps<br /> &lt;haskell&gt;<br /> u :: Int<br /> u = 0<br /> <br /> m :: (A, Int) -&gt; Int<br /> m (a, n) = n+1<br /> &lt;/haskell&gt;<br /> <br /> MFP define the catamorphism by, supposing &lt;hask&gt;T&lt;/hask&gt; is initial for the functor &lt;hask&gt;F&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> cata :: (F a b -&gt; b) -&gt; T a -&gt; b<br /> cata phi = mu (\x -&gt; phi . fmap x . outT)<br /> &lt;/haskell&gt;<br /> <br /> We can reframe the example above as a catamorphism by observing that here, <br /> &lt;haskell&gt;<br /> data F a b = Nil | Cons a b deriving (Eq, Show)<br /> type T a = [a]<br /> <br /> instance Functor (F a) where<br /> fmap _ Nil = Nil<br /> fmap f (Cons n a) = Cons n (f a)<br /> <br /> outT :: T a -&gt; F a (T a)<br /> outT [] = Nil<br /> outT (a:as) = Cons a as<br /> <br /> lphi :: F a Int -&gt; Int<br /> lphi Nil = 0<br /> lphi (Cons a n) = n + 1<br /> <br /> l = cata lphi<br /> &lt;/haskell&gt;<br /> where we observe that &lt;hask&gt;mu&lt;/hask&gt; has a global definition for everything we do and &lt;hask&gt;out&lt;/hask&gt; is defined once we settle on the functor &lt;hask&gt;F&lt;/hask&gt; and its initial algebra. Thus, the definition of &lt;hask&gt;phi&lt;/hask&gt; really is the only place that the recursion data shows up. <br /> <br /> ====Anamorphisms====<br /> <br /> An ''anamorphism'' is the categorical dual to the catamorphism. It is the canonical morphism from a coalgebra to the final coalgebra for that endofunctor. <br /> <br /> Here, we start unstructured, and erect a structure, induced by the coalgebra structures involved. <br /> <br /> '''Example''': we can write a recursive function <br /> &lt;haskell&gt;<br /> first :: Int -&gt; [Int]<br /> first 1 = <br /> first n = n : first (n - 1)<br /> &lt;/haskell&gt;<br /> This is an anamorphism from the coalgebra for &lt;math&gt;P_{\mathbb N}(X) = 1 + \mathbb N\times X&lt;/math&gt; on &lt;math&gt;\mathbb N&lt;/math&gt; generated by the two maps<br /> &lt;haskell&gt;<br /> c 0 = Left ()<br /> c n = Right (n, n-1)<br /> &lt;/haskell&gt;<br /> and we observe that we can chase through the diagram<br /> :[[Image:CoalgebraMorphism.png]]<br /> to conclude that therefore<br /> &lt;haskell&gt;<br /> f 0 = []<br /> f n = n : f (n - 1)<br /> &lt;/haskell&gt;<br /> which is exactly the recursion we wrote to begin with.<br /> <br /> MFP define the anamorphism by a fixpoint as well, namely:<br /> &lt;haskell&gt;<br /> ana :: (b -&gt; F a b) -&gt; b -&gt; T a<br /> ana psi = mu (\x -&gt; inT . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> We can, again, recast our illustration above into a structural anamorphism, by:<br /> &lt;haskell&gt;<br /> -- Reuse mu, F, T from above<br /> inT :: F a (T a) -&gt; T a<br /> inT Nil = []<br /> inT (Cons a as) = a:as<br /> <br /> fpsi :: Int -&gt; F Int Int<br /> fpsi 0 = Nil<br /> fpsi n = Cons n (n-1)<br /> &lt;/haskell&gt;<br /> <br /> Again, we can note that the implementation of &lt;hask&gt;fpsi&lt;/hask&gt; here is exactly the &lt;hask&gt;c&lt;/hask&gt; above, and the resulting function will - as we can verify by compiling and running - give us the same kind of reversed list of the n first integers as the &lt;hask&gt;first&lt;/hask&gt; function above would.<br /> <br /> ====Hylomorphisms====<br /> <br /> The ''hylomorphisms'' capture one of the two possible compositions of anamorphisms and catamorphisms. Parametrized over an algebra &lt;math&gt;\phi: T A\to A&lt;/math&gt; and a coalgebra &lt;math&gt;\psi: B \to T B&lt;/math&gt; the hylomorphism is a recursion pattern that computes a value in &lt;math&gt;A&lt;/math&gt; from a value in &lt;math&gt;A&lt;/math&gt; by generating some sort of intermediate structure and then collapsing it again.<br /> <br /> It is, thus the composition of the uniquely existing morphism from a coalgebra to the final coalgebra for an endofunctor, followed by the uniquely existing morphism from the initial algebra to some other algebra.<br /> <br /> MFP define it, again, as a fix point: <br /> &lt;haskell&gt;<br /> hylo :: (F a b2 -&gt; b2) -&gt; (b1 -&gt; F a b1) -&gt; b1 -&gt; b2<br /> hylo phi psi = mu (\x -&gt; phi . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> First off, we can observe that by picking one or the other of &lt;math&gt;in_A, out_A&lt;/math&gt; as a parameter, we can recover both the anamorphisms and the catamorphisms as hylomorphisms.<br /> <br /> As an example, we'll compute the factorial function using a hylomorphism:<br /> <br /> &lt;haskell&gt;<br /> phi :: F Int Int -&gt; Int<br /> phi Nil = 1<br /> phi (Cons n m) = n*m<br /> <br /> psi :: Int -&gt; F Int Int<br /> psi 0 = Int<br /> psi n = Cons n (n-1)<br /> <br /> factorial = hylo phi psi<br /> &lt;/haskell&gt;<br /> <br /> ====Metamorphisms====<br /> <br /> The ''metamorphism'' is the ''other'' composition of an anamorphism with a catamorphism. It takes some structure, deconstructs it, and then reconstructs a new structure from it. <br /> <br /> As a recursion pattern, it's kinda boring - it'll take an interesting structure, deconstruct it into a ''scalar'' value, and then reconstruct some structure from that scalar. As such, it won't even capture the richness of &lt;math&gt;hom(F x, G y)&lt;/math&gt;, since any morphism expressed as a metamorphism will factor through a map &lt;math&gt;x\to y&lt;/math&gt;.<br /> <br /> ====Paramorphisms====<br /> <br /> ''Paramorphisms'' were discussed in the MFP paper as a way to extend the catamorphisms so that the operating function can access its arguments in computation as well as in recursion. We gave the factorial above as a hylomorphism instead of a catamorphism precisely because no simple enough catamorphic structure exists.<br /> <br /> ====Apomorphisms====<br /> <br /> The ''apomorphism'' is the dual of the paramorphism - it does with retention of values along the way what anamorphisms do compared to catamorphisms.<br /> <br /> ===Further reading===<br /> <br /> * Erik Meijer, Maarten Fokkinga, Ross Paterson: ''Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire'' [http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.41.125&amp;rep=rep1&amp;type=pdf]<br /> * L. Augusteijn: ''Sorting morphisms'' [http://www.springerlink.com/index/w543447353067h67.pdf]<br /> <br /> ===Further properties of adjunctions===<br /> <br /> ====RAPL====<br /> <br /> '''Proposition''' If &lt;math&gt;F&lt;/math&gt; is a ''right adjoint'', thus if &lt;math&gt;F&lt;/math&gt; has a left adjoint, then &lt;math&gt;F&lt;/math&gt; preserves limits in the sense that &lt;math&gt;F(\lim_{\leftarrow} A_i) = \lim_{\leftarrow} F(A_i)&lt;/math&gt;.<br /> <br /> Example: &lt;math&gt;(\lim_{\leftarrow_i} A_i)\times X = \lim_{\leftarrow_i} A_i\times X&lt;/math&gt;. <br /> <br /> We can use this to prove that things cannot be adjoints - since all right adjoints preserve limits, if a functor &lt;math&gt;G&lt;/math&gt; doesn't preserve limits, then it doesn't have a left adjoint.<br /> <br /> Similarly, and dually, left adjoints preserve colimits. Thus if a functor doesn't preserve colimits, it cannot be a left adjoint, thus cannot have a right adjoint.<br /> <br /> The proof of these statements build on the ''Yoneda lemma'': <br /> <br /> '''Lemma''' If &lt;math&gt;C&lt;/math&gt; is a locally small category (i.e. all hom-sets are sets). Then for any &lt;math&gt;c\in C_0&lt;/math&gt; and any functor &lt;math&gt;F: C^{op}\to Sets&lt;/math&gt; there is an isomorphism<br /> :&lt;math&gt;hom_{hom_{Sets^{C^{op}}}}(yC, F) = FC&lt;/math&gt;<br /> where we define &lt;math&gt;yC = d\mapsto hom_C(d,c) : C^{op}\to Sets&lt;/math&gt;.<br /> <br /> The Yoneda lemma has one important corollary: <br /> <br /> '''Corollary''' If &lt;math&gt;yA = yB&lt;/math&gt; then &lt;math&gt;A = B&lt;/math&gt;.<br /> <br /> Which, in turn has a number of important corollaries:<br /> <br /> '''Corollary''' &lt;math&gt;(A^B)^C = A^{B\times C}&lt;/math&gt;<br /> <br /> '''Corollary''' Adjoints are unique up to isomorphism - in particular, if &lt;math&gt;F: C\to D&lt;/math&gt; is a functor with right adjoints &lt;math&gt;U, V: D\to C&lt;/math&gt;, then &lt;math&gt;U = V&lt;/math&gt;.<br /> <br /> '''Proof''' &lt;math&gt;hom_C(C, UD) = hom_D(FC, D) = hom_C(C, VD)&lt;/math&gt;, and thus by the corollary to the Yoneda lemma, &lt;math&gt;UD = VD&lt;/math&gt;, natural in &lt;math&gt;D&lt;/math&gt;. <br /> <br /> ====Functors that are adjoints====<br /> <br /> * The functor &lt;math&gt;X\mapsto X\times A&lt;/math&gt; has right adjoint &lt;math&gt;Y\mapsto Y^A&lt;/math&gt;. The universal mapping property of the exponentials follows from the adjointness property.<br /> * The functor &lt;math&gt;\Delta: C\to C\times C, c\mapsto (c,c)&lt;/math&gt; has a left adjoint given by the coproduct &lt;math&gt;(X,Y)\mapsto X + Y&lt;/math&gt; and right adjoint the product &lt;math&gt;(X,Y)\mapsto X\times Y&lt;/math&gt;.<br /> * More generally, the functor &lt;math&gt;C\to C^J&lt;/math&gt; that takes &lt;math&gt;c&lt;/math&gt; to the constant functor &lt;math&gt;const_c(j) = c, const_c(f) = 1_c&lt;/math&gt; has left andright adjoints given by colimits and limits:<br /> :&lt;math&gt;\lim_\rightarrow -| \Delta -| \lim_\leftarrow&lt;/math&gt;<br /> * Pointed rings are pairs &lt;math&gt;(R, r\in R)&lt;/math&gt; of rings and one element singled out for attention. Homomorphisms of pointed rings need to take the distinguished point to the distinguished point. There is an obvious forgetful functor &lt;math&gt;U: Rings_* \to Rings&lt;/math&gt;, and this has a left adjoint - a free ring functor that adjoins a new indeterminate &lt;math&gt;R\mapsto (R[x], x)&lt;/math&gt;. This gives a formal definition of what we mean by ''formal polynomial expressions'' et.c.<br /> * Given sets &lt;math&gt;A, B&lt;/math&gt;, we can consider the powersets &lt;math&gt;P(A), P(B)&lt;/math&gt; containing, as elements, all subsets of &lt;math&gt;A, B&lt;/math&gt; respectively. Suppose &lt;math&gt;f:A\to B&lt;/math&gt; is a function, then &lt;math&gt;f^{-1}: P(B)\to P(A)&lt;/math&gt; takes subsets of &lt;math&gt;B&lt;/math&gt; to subsets of &lt;math&gt;A&lt;/math&gt;. <br /> :Viewing &lt;math&gt;P(A)&lt;/math&gt; and &lt;math&gt;P(B)&lt;/math&gt; as partially ordered sets by the inclusion operations, and then as categories induced by the partial order, &lt;math&gt;f^{-1}&lt;/math&gt; turns into a functor between partial orders. And it turns out &lt;math&gt;f^{-1}&lt;/math&gt; has a left adjoint given by the operation &lt;math&gt;im(f)&lt;/math&gt; taking a subset to the set of images under the function &lt;math&gt;f&lt;/math&gt;. And it has a right adjoint &lt;math&gt;f_*(U) = \{b\in B: f^{-1}(b)\subseteq U\}&lt;/math&gt;<br /> * We can introduce a categorical structure to logic. We let &lt;math&gt;L&lt;/math&gt; be a formal language, say of predicate logic. Then for any list &lt;math&gt;x = x_1, x_2, ..., x_n&lt;/math&gt; of variables, we have a preorder &lt;math&gt;Form(x)&lt;/math&gt; of formulas with no free variables not occuring in &lt;math&gt;x&lt;/math&gt;. The preorder on &lt;math&gt;Form(x)&lt;/math&gt; comes from the ''entailment'' operation - &lt;math&gt; f |- g&lt;/math&gt; if in every interpretation of the language, &lt;math&gt;f \Rightarrow g&lt;/math&gt;.<br /> : We can build an operation on these preorders - a functor on the underlying categories - by adjoining a single new variable: &lt;math&gt;*: Form(x) \to Form(x, y)&lt;/math&gt;, sending each form to itself. Obviously, if &lt;math&gt;f |- g&lt;/math&gt; with &lt;math&gt;x&lt;/math&gt; the source of free variables, if we introduce a new allowable free variable, but don't actually change the formulas, the entailment stays the same.<br /> : It turns out that there is a right adjoint to &lt;math&gt;*&lt;/math&gt; given by &lt;math&gt;f\mapsto \forall y. f&lt;/math&gt;. And a left adjoint to &lt;math&gt;*&lt;/math&gt; given by &lt;math&gt;f\mapsto \exists y. f&lt;/math&gt;. Adjointness properties give us classical deduction rules from logic.<br /> <br /> ===Homework===<br /> <br /> # Write a fold for the data type &lt;hask&gt;data T a = L a | B a a | C a a a&lt;/hask&gt; and demonstrate how this can be written as a catamorphism by giving the algebra it maps to. <br /> # Write the fibonacci function as a hylomorphism.<br /> # Write the Towers of Hanoi as a hylomorphism. You'll probably want to use binary trees as the intermediate data structure.<br /> # Write a prime numbers generator as an anamorphism.<br /> # * The integers have a partial order induced by the divisibility relation. We can thus take any integer and arrange all its divisors in a tree by having an edge &lt;math&gt;n \to d&lt;/math&gt; if &lt;math&gt;d|n&lt;/math&gt; and &lt;math&gt;d&lt;/math&gt; doesn't divide any other divisor of &lt;math&gt;n&lt;/math&gt;. Write an anamorphic function that will generate this tree for a given starting integer. Demonstrate how this function is an anamorphism by giving the algebra it maps from.<br /> :''Hint'': You will be helped by having a function to generate a list of all primes. One suggestion is:<br /> &lt;haskell&gt;<br /> primes :: [Integer]<br /> primes = sieve [2..]<br /> where<br /> sieve (p:xs) = p : sieve [x|x &lt;- xs, x mod p &gt; 0]<br /> &lt;/haskell&gt;<br /> :''Hint'': A good data structure to use is; with expected output of running the algorithm:<br /> &lt;haskell&gt;<br /> data Tree = Leaf Integer | Node Integer [Tree]<br /> <br /> divisionTree 60 = <br /> Node 60 [<br /> Node 30 [<br /> Node 15 [<br /> Leaf 5,<br /> Leaf 3],<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2]],<br /> Node 20 [<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]],<br /> Node 12 [<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]]]<br /> &lt;/haskell&gt;</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_9&diff=31623 User:Michiexile/MATH198/Lecture 9 2009-11-17T18:40:00Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Recursion patterns===<br /> <br /> Meijer, Fokkinga &amp; Patterson identified in the paper ''Functional programming with bananas, lenses, envelopes and barbed wire'' a number of generic patterns for recursive programming that they had observed, catalogued and systematized. The aim of that paper is to establish a number of ''rules'' for modifying and rewriting expressions involving these generic recursion patterns.<br /> <br /> As it turns out, these patterns are instances of the same phenomenon we saw last lecture: where the recursion comes from specifying a different algebra, and then take a uniquely existing morphism induced by initiality (or, as we shall see, finality). <br /> <br /> Before we go through the recursion patterns, we need to establish a few pieces of theoretical language, dualizing the Eilenberg-Moore algebra constructions from the last lecture.<br /> <br /> ====Coalgebras for endofunctors====<br /> <br /> '''Definition''' If &lt;math&gt;P: C\to C&lt;/math&gt; is an endofunctor, then a &lt;math&gt;P&lt;/math&gt;-''coalgebra'' on &lt;math&gt;A&lt;/math&gt; is a morphism &lt;math&gt;a: A\to PA&lt;/math&gt;.<br /> <br /> A ''morphism of coalgebras'': &lt;math&gt;f: a\to b&lt;/math&gt; is some &lt;math&gt;f: A\to B&lt;/math&gt; such that the diagram <br /> :[[Image:CoalgebraMorphism.png]]<br /> commutes. <br /> <br /> Just as with algebras, we get a category of coalgebras. And the interesting objects here are the ''final coalgebras''. Just as with algebras, we have<br /> <br /> '''Lemma''' (''Lambek'') If &lt;math&gt;a: A\to PA&lt;/math&gt; is a final coalgebra, it is an isomorphism.<br /> <br /> Finally, one thing that makes us care highly about these entities: in an appropriate category (such as &lt;math&gt;\omega-CPO&lt;/math&gt;), initial algebras and final coalgebras coincide, with the correspondence given by inverting the algebra/coalgebra morphism. In Haskell not quite true (specifically, the final coalgebra for the lists functor gives us streams...).<br /> <br /> Onwards to recursion schemes!<br /> <br /> We shall define a few specific morphisms we'll use repeatedly. This notation, introduced here, occurs all over the place in these corners of the literature, and are good to be aware of in general: <br /> * If &lt;math&gt;a: TA\to A&lt;/math&gt; is an initial algebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = in_A&lt;/math&gt;.<br /> * If &lt;math&gt;a: A\to TA&lt;/math&gt; is a final coalgebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = out_A&lt;/math&gt;.<br /> * We write &lt;math&gt;\mu f&lt;/math&gt; for the fixed point operator<br /> &lt;haskell&gt;<br /> mu f = x where x = f x<br /> &lt;/haskell&gt;<br /> <br /> We note that in the situation considered by MFP, inital algebras and final coalgebras coincide, and thus &lt;math&gt;in_A, out_A&lt;/math&gt; are the pair of isomorphic maps induced by either the initial algebra- or the final coalgebra-structure.<br /> <br /> ====Catamorphisms====<br /> <br /> A ''catamorphism'' is the uniquely existing morphism from an initial algebra to a different algebra. We have to define maps down to the return value type for each of the constructors of the complex data type we're recursing over, and the catamorphism will deconstruct the structure (trees, lists, ...) and do a generalized ''fold'' over the structure at hand before returning the final value.<br /> <br /> The intuition is that for catamorphisms we start essentially structured, and dismantle the structure.<br /> <br /> '''Example''': the length function from last lecture. This is the catamorphism for the functor &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; given by the maps<br /> &lt;haskell&gt;<br /> u :: Int<br /> u = 0<br /> <br /> m :: (A, Int) -&gt; Int<br /> m (a, n) = n+1<br /> &lt;/haskell&gt;<br /> <br /> MFP define the catamorphism by, supposing &lt;hask&gt;T&lt;/hask&gt; is initial for the functor &lt;hask&gt;F&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> cata :: (F a b -&gt; b) -&gt; T a -&gt; b<br /> cata phi = mu (\x -&gt; phi . fmap x . outT)<br /> &lt;/haskell&gt;<br /> <br /> We can reframe the example above as a catamorphism by observing that here, <br /> &lt;haskell&gt;<br /> data F a b = Nil | Cons a b deriving (Eq, Show)<br /> type T a = [a]<br /> <br /> instance Functor (F a) where<br /> fmap _ Nil = Nil<br /> fmap f (Cons n a) = Cons n (f a)<br /> <br /> outT :: T a -&gt; F a (T a)<br /> outT [] = Nil<br /> outT (a:as) = Cons a as<br /> <br /> lphi :: F a Int -&gt; Int<br /> lphi Nil = 0<br /> lphi (Cons a n) = n + 1<br /> <br /> l = cata lphi<br /> &lt;/haskell&gt;<br /> where we observe that &lt;hask&gt;mu&lt;/hask&gt; has a global definition for everything we do and &lt;hask&gt;out&lt;/hask&gt; is defined once we settle on the functor &lt;hask&gt;F&lt;/hask&gt; and its initial algebra. Thus, the definition of &lt;hask&gt;phi&lt;/hask&gt; really is the only place that the recursion data shows up. <br /> <br /> ====Anamorphisms====<br /> <br /> An ''anamorphism'' is the categorical dual to the catamorphism. It is the canonical morphism from a coalgebra to the final coalgebra for that endofunctor. <br /> <br /> Here, we start unstructured, and erect a structure, induced by the coalgebra structures involved. <br /> <br /> '''Example''': we can write a recursive function <br /> &lt;haskell&gt;<br /> first :: Int -&gt; [Int]<br /> first 1 = <br /> first n = n : first (n - 1)<br /> &lt;/haskell&gt;<br /> This is an anamorphism from the coalgebra for &lt;math&gt;P_{\mathbb N}(X) = 1 + \mathbb N\times X&lt;/math&gt; on &lt;math&gt;\mathbb N&lt;/math&gt; generated by the two maps<br /> &lt;haskell&gt;<br /> c 0 = Left ()<br /> c n = Right (n, n-1)<br /> &lt;/haskell&gt;<br /> and we observe that we can chase through the diagram<br /> :[[Image:CoalgebraMorphism.png]]<br /> to conclude that therefore<br /> &lt;haskell&gt;<br /> f 0 = []<br /> f n = n : f (n - 1)<br /> &lt;/haskell&gt;<br /> which is exactly the recursion we wrote to begin with.<br /> <br /> MFP define the anamorphism by a fixpoint as well, namely:<br /> &lt;haskell&gt;<br /> ana :: (b -&gt; F a b) -&gt; b -&gt; T a<br /> ana psi = mu (\x -&gt; inT . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> We can, again, recast our illustration above into a structural anamorphism, by:<br /> &lt;haskell&gt;<br /> -- Reuse mu, F, T from above<br /> inT :: F a (T a) -&gt; T a<br /> inT Nil = []<br /> inT (Cons a as) = a:as<br /> <br /> fpsi :: Int -&gt; F Int Int<br /> fpsi 0 = Nil<br /> fpsi n = Cons n (n-1)<br /> &lt;/haskell&gt;<br /> <br /> Again, we can note that the implementation of &lt;hask&gt;fpsi&lt;/hask&gt; here is exactly the &lt;hask&gt;c&lt;/hask&gt; above, and the resulting function will - as we can verify by compiling and running - give us the same kind of reversed list of the n first integers as the &lt;hask&gt;first&lt;/hask&gt; function above would.<br /> <br /> ====Hylomorphisms====<br /> <br /> The ''hylomorphisms'' capture one of the two possible compositions of anamorphisms and catamorphisms. Parametrized over an algebra &lt;math&gt;\phi: T A\to A&lt;/math&gt; and a coalgebra &lt;math&gt;\psi: B \to T B&lt;/math&gt; the hylomorphism is a recursion pattern that computes a value in &lt;math&gt;A&lt;/math&gt; from a value in &lt;math&gt;A&lt;/math&gt; by generating some sort of intermediate structure and then collapsing it again.<br /> <br /> It is, thus the composition of the uniquely existing morphism from a coalgebra to the final coalgebra for an endofunctor, followed by the uniquely existing morphism from the initial algebra to some other algebra.<br /> <br /> MFP define it, again, as a fix point: <br /> &lt;haskell&gt;<br /> hylo :: (F a b2 -&gt; b2) -&gt; (b1 -&gt; F a b1) -&gt; b1 -&gt; b2<br /> hylo phi psi = mu (\x -&gt; phi . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> First off, we can observe that by picking one or the other of &lt;math&gt;in_A, out_A&lt;/math&gt; as a parameter, we can recover both the anamorphisms and the catamorphisms as hylomorphisms.<br /> <br /> As an example, we'll compute the factorial function using a hylomorphism:<br /> <br /> &lt;haskell&gt;<br /> phi :: F Int Int -&gt; Int<br /> phi Nil = 1<br /> phi (Cons n m) = n*m<br /> <br /> psi :: Int -&gt; F Int Int<br /> psi 0 = Int<br /> psi n = Cons n (n-1)<br /> <br /> factorial = hylo phi psi<br /> &lt;/haskell&gt;<br /> <br /> ====Metamorphisms====<br /> <br /> The ''metamorphism'' is the ''other'' composition of an anamorphism with a catamorphism. It takes some structure, deconstructs it, and then reconstructs a new structure from it. <br /> <br /> As a recursion pattern, it's kinda boring - it'll take an interesting structure, deconstruct it into a ''scalar'' value, and then reconstruct some structure from that scalar. As such, it won't even capture the richness of &lt;math&gt;hom(F x, G y)&lt;/math&gt;, since any morphism expressed as a metamorphism will factor through a map &lt;math&gt;x\to y&lt;/math&gt;.<br /> <br /> ====Paramorphisms====<br /> <br /> ''Paramorphisms'' were discussed in the MFP paper as a way to extend the catamorphisms so that the operating function can access its arguments in computation as well as in recursion. We gave the factorial above as a hylomorphism instead of a catamorphism precisely because no simple enough catamorphic structure exists.<br /> <br /> ====Apomorphisms====<br /> <br /> The ''apomorphism'' is the dual of the paramorphism - it does with retention of values along the way what anamorphisms do compared to catamorphisms.<br /> <br /> ===Further reading===<br /> <br /> * Erik Meijer, Maarten Fokkinga, Ross Paterson: ''Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire'' [http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.41.125&amp;rep=rep1&amp;type=pdf]<br /> * L. Augusteijn: ''Sorting morphisms'' [http://www.springerlink.com/index/w543447353067h67.pdf]<br /> <br /> ===Further properties of adjunctions===<br /> <br /> ====RAPL====<br /> <br /> '''Proposition''' If &lt;math&gt;F&lt;/math&gt; is a ''right adjoint'', thus if &lt;math&gt;F&lt;/math&gt; has a left adjoint, then &lt;math&gt;F&lt;/math&gt; preserves limits in the sense that &lt;math&gt;F(\lim_{\leftarrow} A_i) = \lim_{\leftarrow} F(A_i)&lt;/math&gt;.<br /> <br /> Example: &lt;math&gt;(\lim_{\leftarrow_i} A_i)\times X = \lim_{\leftarrow_i} A_i\times X&lt;/math&gt;. <br /> <br /> We can use this to prove that things cannot be adjoints - since all right adjoints preserve limits, if a functor &lt;math&gt;G&lt;/math&gt; doesn't preserve limits, then it doesn't have a left adjoint.<br /> <br /> Similarly, and dually, left adjoints preserve colimits. Thus if a functor doesn't preserve colimits, it cannot be a left adjoint, thus cannot have a right adjoint.<br /> <br /> The proof of these statements build on the ''Yoneda lemma'': <br /> <br /> '''Lemma''' If &lt;math&gt;C&lt;/math&gt; is a locally small category (i.e. all hom-sets are sets). Then for any &lt;math&gt;c\in C_0&lt;/math&gt; and any functor &lt;math&gt;F: C^{op}\to Sets&lt;/math&gt; there is an isomorphism<br /> :&lt;math&gt;hom_{hom_{Sets^{C^{op}}}}(yC, F) = FC&lt;/math&gt;<br /> where we define &lt;math&gt;yC = d\mapsto hom_C(d,c) : C^{op}\to Sets&lt;/math&gt;.<br /> <br /> The Yoneda lemma has one important corollary: <br /> <br /> '''Corollary''' If &lt;math&gt;yA = yB&lt;/math&gt; then &lt;math&gt;A = B&lt;/math&gt;.<br /> <br /> Which, in turn has a number of important corollaries:<br /> <br /> '''Corollary''' &lt;math&gt;(A^B)^C = A^{B\times C}&lt;/math&gt;<br /> <br /> '''Corollary''' Adjoints are unique up to isomorphism - in particular, if &lt;math&gt;F: C\to D&lt;/math&gt; is a functor with right adjoints &lt;math&gt;U, V: D\to C&lt;/math&gt;, then &lt;math&gt;U = V&lt;/math&gt;.<br /> <br /> '''Proof''' &lt;math&gt;hom_C(C, UD) = hom_D(FC, D) = hom_C(C, VD)&lt;/math&gt;, and thus by the corollary to the Yoneda lemma, &lt;math&gt;UD = VD&lt;/math&gt;, natural in &lt;math&gt;D&lt;/math&gt;. <br /> <br /> ====Functors that are adjoints====<br /> <br /> * The functor &lt;math&gt;X\mapsto X\times A&lt;/math&gt; has right adjoint &lt;math&gt;Y\mapsto Y^A&lt;/math&gt;. The universal mapping property of the exponentials follows from the adjointness property.<br /> * The functor &lt;math&gt;\Delta: C\to C\times C, c\mapsto (c,c)&lt;/math&gt; has a left adjoint given by the coproduct &lt;math&gt;(X,Y)\mapsto X + Y&lt;/math&gt; and right adjoint the product &lt;math&gt;(X,Y)\mapsto X\times Y&lt;/math&gt;.<br /> * More generally, the functor &lt;math&gt;C\to C^J&lt;/math&gt; that takes &lt;math&gt;c&lt;/math&gt; to the constant functor &lt;math&gt;const_c(j) = c, const_c(f) = 1_c&lt;/math&gt; has left andright adjoints given by colimits and limits:<br /> :&lt;math&gt;\lim_\rightarrow -| \Delta -| \lim_\leftarrow&lt;/math&gt;<br /> * Pointed rings are pairs &lt;math&gt;(R, r\in R)&lt;/math&gt; of rings and one element singled out for attention. Homomorphisms of pointed rings need to take the distinguished point to the distinguished point. There is an obvious forgetful functor &lt;math&gt;U: Rings_* \to Rings&lt;/math&gt;, and this has a left adjoint - a free ring functor that adjoins a new indeterminate &lt;math&gt;R\mapsto (R[x], x)&lt;/math&gt;. This gives a formal definition of what we mean by ''formal polynomial expressions'' et.c.<br /> * Given sets &lt;math&gt;A, B&lt;/math&gt;, we can consider the powersets &lt;math&gt;P(A), P(B)&lt;/math&gt; containing, as elements, all subsets of &lt;math&gt;A, B&lt;/math&gt; respectively. Suppose &lt;math&gt;f:A\to B&lt;/math&gt; is a function, then &lt;math&gt;f^{-1}: P(B)\to P(A)&lt;/math&gt; takes subsets of &lt;math&gt;B&lt;/math&gt; to subsets of &lt;math&gt;A&lt;/math&gt;. <br /> :Viewing &lt;math&gt;P(A)&lt;/math&gt; and &lt;math&gt;P(B)&lt;/math&gt; as partially ordered sets by the inclusion operations, and then as categories induced by the partial order, &lt;math&gt;f^{-1}&lt;/math&gt; turns into a functor between partial orders. And it turns out &lt;math&gt;f^{-1}&lt;/math&gt; has a left adjoint given by the operation &lt;math&gt;im(f)&lt;/math&gt; taking a subset to the set of images under the function &lt;math&gt;f&lt;/math&gt;. And it has a right adjoint &lt;math&gt;f_*(U) = \{b\in B: f^{-1}(b)\subseteq U\}&lt;/math&gt;<br /> * We can introduce a categorical structure to logic. We let &lt;math&gt;L&lt;/math&gt; be a formal language, say of predicate logic. Then for any list &lt;math&gt;x = x_1, x_2, ..., x_n&lt;/math&gt; of variables, we have a preorder &lt;math&gt;Form(x)&lt;/math&gt; of formulas with no free variables not occuring in &lt;math&gt;x&lt;/math&gt;. The preorder on &lt;math&gt;Form(x)&lt;/math&gt; comes from the ''entailment'' operation - &lt;math&gt; f |- g&lt;/math&gt; if in every interpretation of the language, &lt;math&gt;f \Rightarrow g&lt;/math&gt;.<br /> : We can build an operation on these preorders - a functor on the underlying categories - by adjoining a single new variable: &lt;math&gt;*: Form(x) \to Form(x, y)&lt;/math&gt;, sending each form to itself. Obviously, if &lt;math&gt;f |- g&lt;/math&gt; with &lt;math&gt;x&lt;/math&gt; the source of free variables, if we introduce a new allowable free variable, but don't actually change the formulas, the entailment stays the same.<br /> : It turns out that there is a right adjoint to &lt;math&gt;*&lt;/math&gt; given by &lt;math&gt;f\mapsto \forall y. f&lt;/math&gt;. And a left adjoint to &lt;math&gt;*&lt;/math&gt; given by &lt;math&gt;f\mapsto \exists y. f&lt;/math&gt;. Adjointness properties give us classical deduction rules from logic.<br /> <br /> ===Homework===<br /> <br /> # Write a fold for the data type &lt;hask&gt;data T a = L a | B a a | C a a a&lt;/hask&gt; and demonstrate how this can be written as a catamorphism by giving the algebra it maps to. <br /> # Write the fibonacci function as a hylomorphism.<br /> # Write the Towers of Hanoi as a hylomorphism. You'll probably want to use binary trees as the intermediate data structure.<br /> # Write a prime numbers generator as an anamorphism.<br /> # * The integers have a partial order induced by the divisibility relation. We can thus take any integer and arrange all its divisors in a tree by having an edge &lt;math&gt;n \to d&lt;/math&gt; if &lt;math&gt;d|n&lt;/math&gt; and &lt;math&gt;d&lt;/math&gt; doesn't divide any other divisor of &lt;math&gt;n&lt;/math&gt;. Write an anamorphic function that will generate this tree for a given starting integer. Demonstrate how this function is an anamorphism by giving the algebra it maps from.<br /> :''Hint'': You will be helped by having a function to generate a list of all primes. One suggestion is:<br /> &lt;haskell&gt;<br /> primes :: [Integer]<br /> primes = sieve [2..]<br /> where<br /> sieve (p:xs) = p : sieve [x|x &lt;- xs, x mod p &gt; 0]<br /> &lt;/haskell&gt;<br /> :''Hint'': A good data structure to use is; with expected output of running the algorithm:<br /> &lt;haskell&gt;<br /> data Tree = Leaf Integer | Node Integer [Tree]<br /> <br /> divisionTree 60 = <br /> Node 60 [<br /> Node 30 [<br /> Node 15 [<br /> Leaf 5,<br /> Leaf 3],<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2]],<br /> Node 20 [<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]],<br /> Node 12 [<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]]]<br /> &lt;/haskell&gt;</div> Michiexile https://wiki.haskell.org/index.php?title=File:CoalgebraMorphism.png&diff=31622 File:CoalgebraMorphism.png 2009-11-17T18:39:04Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_9&diff=31621 User:Michiexile/MATH198/Lecture 9 2009-11-17T18:34:17Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Recursion patterns===<br /> <br /> Meijer, Fokkinga &amp; Patterson identified in the paper ''Functional programming with bananas, lenses, envelopes and barbed wire'' a number of generic patterns for recursive programming that they had observed, catalogued and systematized. The aim of that paper is to establish a number of ''rules'' for modifying and rewriting expressions involving these generic recursion patterns.<br /> <br /> As it turns out, these patterns are instances of the same phenomenon we saw last lecture: where the recursion comes from specifying a different algebra, and then take a uniquely existing morphism induced by initiality (or, as we shall see, finality). <br /> <br /> Before we go through the recursion patterns, we need to establish a few pieces of theoretical language, dualizing the Eilenberg-Moore algebra constructions from the last lecture.<br /> <br /> ====Coalgebras for endofunctors====<br /> <br /> '''Definition''' If &lt;math&gt;P: C\to C&lt;/math&gt; is an endofunctor, then a &lt;math&gt;P&lt;/math&gt;-''coalgebra'' on &lt;math&gt;A&lt;/math&gt; is a morphism &lt;math&gt;a: A\to PA&lt;/math&gt;.<br /> <br /> A ''morphism of coalgebras'': &lt;math&gt;f: a\to b&lt;/math&gt; is some &lt;math&gt;f: A\to B&lt;/math&gt; such that the diagram <br /> :[[Image:CoalgebraMorphism.png]]<br /> commutes. <br /> <br /> Just as with algebras, we get a category of coalgebras. And the interesting objects here are the ''final coalgebras''. Just as with algebras, we have<br /> <br /> '''Lemma''' (''Lambek'') If &lt;math&gt;a: A\to PA&lt;/math&gt; is a final coalgebra, it is an isomorphism.<br /> <br /> Finally, one thing that makes us care highly about these entities: in an appropriate category (such as &lt;math&gt;\omega-CPO&lt;/math&gt;), initial algebras and final coalgebras coincide, with the correspondence given by inverting the algebra/coalgebra morphism. In Haskell not quite true (specifically, the final coalgebra for the lists functor gives us streams...).<br /> <br /> Onwards to recursion schemes!<br /> <br /> We shall define a few specific morphisms we'll use repeatedly. This notation, introduced here, occurs all over the place in these corners of the literature, and are good to be aware of in general: <br /> * If &lt;math&gt;a: TA\to A&lt;/math&gt; is an initial algebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = in_A&lt;/math&gt;.<br /> * If &lt;math&gt;a: A\to TA&lt;/math&gt; is a final coalgebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = out_A&lt;/math&gt;.<br /> * We write &lt;math&gt;\mu f&lt;/math&gt; for the fixed point operator<br /> &lt;haskell&gt;<br /> mu f = x where x = f x<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\Delta g)&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> Delta f g = \x -&gt; (f x, g x)<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\nabla g) x&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> (Nabla f g) (Left x) = f x<br /> (Nabla f g) (Right x) = g x<br /> &lt;/haskell&gt;<br /> <br /> These two last constructions are directly motivated by the maps induced from the universal properties of products and coproducts.<br /> <br /> We shall write &lt;math&gt;(f\times g)&lt;/math&gt; and &lt;math&gt;(f+g)&lt;/math&gt; for the &lt;math&gt;\Delta&lt;/math&gt; and &lt;math&gt;\nabla&lt;/math&gt; constructions, respectively.<br /> <br /> We note that in the situation considered by MFP, inital algebras and final coalgebras coincide, and thus &lt;math&gt;in_A, out_A&lt;/math&gt; are the pair of isomorphic maps induced by either the initial algebra- or the final coalgebra-structure.<br /> <br /> ====Catamorphisms====<br /> <br /> A ''catamorphism'' is the uniquely existing morphism from an initial algebra to a different algebra. We have to define maps down to the return value type for each of the constructors of the complex data type we're recursing over, and the catamorphism will deconstruct the structure (trees, lists, ...) and do a generalized ''fold'' over the structure at hand before returning the final value.<br /> <br /> The intuition is that for catamorphisms we start essentially structured, and dismantle the structure.<br /> <br /> '''Example''': the length function from last lecture. This is the catamorphism for the functor &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; given by the maps<br /> &lt;haskell&gt;<br /> u :: Int<br /> u = 0<br /> <br /> m :: (A, Int) -&gt; Int<br /> m (a, n) = n+1<br /> &lt;/haskell&gt;<br /> <br /> MFP define the catamorphism by, supposing &lt;hask&gt;T&lt;/hask&gt; is initial for the functor &lt;hask&gt;F&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> cata :: (F a b -&gt; b) -&gt; T a -&gt; b<br /> cata phi = mu (\x -&gt; phi . fmap x . outT)<br /> &lt;/haskell&gt;<br /> <br /> We can reframe the example above as a catamorphism by observing that here, <br /> &lt;haskell&gt;<br /> data F a b = Nil | Cons a b deriving (Eq, Show)<br /> type T a = [a]<br /> <br /> instance Functor (F a) where<br /> fmap _ Nil = Nil<br /> fmap f (Cons n a) = Cons n (f a)<br /> <br /> outT :: T a -&gt; F a (T a)<br /> outT [] = Nil<br /> outT (a:as) = Cons a as<br /> <br /> lphi :: F a Int -&gt; Int<br /> lphi Nil = 0<br /> lphi (Cons a n) = n + 1<br /> <br /> l = cata lphi<br /> &lt;/haskell&gt;<br /> where we observe that &lt;hask&gt;mu&lt;/hask&gt; has a global definition for everything we do and &lt;hask&gt;out&lt;/hask&gt; is defined once we settle on the functor &lt;hask&gt;F&lt;/hask&gt; and its initial algebra. Thus, the definition of &lt;hask&gt;phi&lt;/hask&gt; really is the only place that the recursion data shows up. <br /> <br /> ====Anamorphisms====<br /> <br /> An ''anamorphism'' is the categorical dual to the catamorphism. It is the canonical morphism from a coalgebra to the final coalgebra for that endofunctor. <br /> <br /> Here, we start unstructured, and erect a structure, induced by the coalgebra structures involved. <br /> <br /> '''Example''': we can write a recursive function <br /> &lt;haskell&gt;<br /> first :: Int -&gt; [Int]<br /> first 1 = <br /> first n = n : first (n - 1)<br /> &lt;/haskell&gt;<br /> This is an anamorphism from the coalgebra for &lt;math&gt;P_{\mathbb N}(X) = 1 + \mathbb N\times X&lt;/math&gt; on &lt;math&gt;\mathbb N&lt;/math&gt; generated by the two maps<br /> &lt;haskell&gt;<br /> c 0 = Left ()<br /> c n = Right (n, n-1)<br /> &lt;/haskell&gt;<br /> and we observe that we can chase through the diagram<br /> :[[Image:CoalgebraMorphism.png]]<br /> to conclude that therefore<br /> &lt;haskell&gt;<br /> f 0 = []<br /> f n = n : f (n - 1)<br /> &lt;/haskell&gt;<br /> which is exactly the recursion we wrote to begin with.<br /> <br /> MFP define the anamorphism by a fixpoint as well, namely:<br /> &lt;haskell&gt;<br /> ana :: (b -&gt; F a b) -&gt; b -&gt; T a<br /> ana psi = mu (\x -&gt; inT . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> We can, again, recast our illustration above into a structural anamorphism, by:<br /> &lt;haskell&gt;<br /> -- Reuse mu, F, T from above<br /> inT :: F a (T a) -&gt; T a<br /> inT Nil = []<br /> inT (Cons a as) = a:as<br /> <br /> fpsi :: Int -&gt; F Int Int<br /> fpsi 0 = Nil<br /> fpsi n = Cons n (n-1)<br /> &lt;/haskell&gt;<br /> <br /> Again, we can note that the implementation of &lt;hask&gt;fpsi&lt;/hask&gt; here is exactly the &lt;hask&gt;c&lt;/hask&gt; above, and the resulting function will - as we can verify by compiling and running - give us the same kind of reversed list of the n first integers as the &lt;hask&gt;first&lt;/hask&gt; function above would.<br /> <br /> ====Hylomorphisms====<br /> <br /> The ''hylomorphisms'' capture one of the two possible compositions of anamorphisms and catamorphisms. Parametrized over an algebra &lt;math&gt;\phi: T A\to A&lt;/math&gt; and a coalgebra &lt;math&gt;\psi: B \to T B&lt;/math&gt; the hylomorphism is a recursion pattern that computes a value in &lt;math&gt;A&lt;/math&gt; from a value in &lt;math&gt;A&lt;/math&gt; by generating some sort of intermediate structure and then collapsing it again.<br /> <br /> It is, thus the composition of the uniquely existing morphism from a coalgebra to the final coalgebra for an endofunctor, followed by the uniquely existing morphism from the initial algebra to some other algebra.<br /> <br /> MFP define it, again, as a fix point: <br /> &lt;haskell&gt;<br /> hylo :: (F a b2 -&gt; b2) -&gt; (b1 -&gt; F a b1) -&gt; b1 -&gt; b2<br /> hylo phi psi = mu (\x -&gt; phi . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> First off, we can observe that by picking one or the other of &lt;math&gt;in_A, out_A&lt;/math&gt; as a parameter, we can recover both the anamorphisms and the catamorphisms as hylomorphisms.<br /> <br /> As an example, we'll compute the factorial function using a hylomorphism:<br /> <br /> &lt;haskell&gt;<br /> phi :: F Int Int -&gt; Int<br /> phi Nil = 1<br /> phi (Cons n m) = n*m<br /> <br /> psi :: Int -&gt; F Int Int<br /> psi 0 = Int<br /> psi n = Cons n (n-1)<br /> <br /> factorial = hylo phi psi<br /> &lt;/haskell&gt;<br /> <br /> ====Metamorphisms====<br /> <br /> The ''metamorphism'' is the ''other'' composition of an anamorphism with a catamorphism. It takes some structure, deconstructs it, and then reconstructs a new structure from it. <br /> <br /> As a recursion pattern, it's kinda boring - it'll take an interesting structure, deconstruct it into a ''scalar'' value, and then reconstruct some structure from that scalar. As such, it won't even capture the richness of &lt;math&gt;hom(F x, G y)&lt;/math&gt;, since any morphism expressed as a metamorphism will factor through a map &lt;math&gt;x\to y&lt;/math&gt;.<br /> <br /> ====Paramorphisms====<br /> <br /> ''Paramorphisms'' were discussed in the MFP paper as a way to extend the catamorphisms so that the operating function can access its arguments in computation as well as in recursion. We gave the factorial above as a hylomorphism instead of a catamorphism precisely because no simple enough catamorphic structure exists.<br /> <br /> ====Apomorphisms====<br /> <br /> The ''apomorphism'' is the dual of the paramorphism - it does with retention of values along the way what anamorphisms do compared to catamorphisms.<br /> <br /> ===Further reading===<br /> <br /> * Erik Meijer, Maarten Fokkinga, Ross Paterson: ''Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire'' [http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.41.125&amp;rep=rep1&amp;type=pdf]<br /> * L. Augusteijn: ''Sorting morphisms'' [http://www.springerlink.com/index/w543447353067h67.pdf]<br /> <br /> ===Further properties of adjunctions===<br /> <br /> ====RAPL====<br /> <br /> '''Proposition''' If &lt;math&gt;F&lt;/math&gt; is a ''right adjoint'', thus if &lt;math&gt;F&lt;/math&gt; has a left adjoint, then &lt;math&gt;F&lt;/math&gt; preserves limits in the sense that &lt;math&gt;F(\lim_{\leftarrow} A_i) = \lim_{\leftarrow} F(A_i)&lt;/math&gt;.<br /> <br /> Example: &lt;math&gt;(\lim_{\leftarrow_i} A_i)\times X = \lim_{\leftarrow_i} A_i\times X&lt;/math&gt;. <br /> <br /> We can use this to prove that things cannot be adjoints - since all right adjoints preserve limits, if a functor &lt;math&gt;G&lt;/math&gt; doesn't preserve limits, then it doesn't have a left adjoint.<br /> <br /> Similarly, and dually, left adjoints preserve colimits. Thus if a functor doesn't preserve colimits, it cannot be a left adjoint, thus cannot have a right adjoint.<br /> <br /> The proof of these statements build on the ''Yoneda lemma'': <br /> <br /> '''Lemma''' If &lt;math&gt;C&lt;/math&gt; is a locally small category (i.e. all hom-sets are sets). Then for any &lt;math&gt;c\in C_0&lt;/math&gt; and any functor &lt;math&gt;F: C^{op}\to Sets&lt;/math&gt; there is an isomorphism<br /> :&lt;math&gt;hom_{hom_{Sets^{C^{op}}}}(yC, F) = FC&lt;/math&gt;<br /> where we define &lt;math&gt;yC = d\mapsto hom_C(d,c) : C^{op}\to Sets&lt;/math&gt;.<br /> <br /> The Yoneda lemma has one important corollary: <br /> <br /> '''Corollary''' If &lt;math&gt;yA = yB&lt;/math&gt; then &lt;math&gt;A = B&lt;/math&gt;.<br /> <br /> Which, in turn has a number of important corollaries:<br /> <br /> '''Corollary''' &lt;math&gt;(A^B)^C = A^{B\times C}&lt;/math&gt;<br /> <br /> '''Corollary''' Adjoints are unique up to isomorphism - in particular, if &lt;math&gt;F: C\to D&lt;/math&gt; is a functor with right adjoints &lt;math&gt;U, V: D\to C&lt;/math&gt;, then &lt;math&gt;U = V&lt;/math&gt;.<br /> <br /> '''Proof''' &lt;math&gt;hom_C(C, UD) = hom_D(FC, D) = hom_C(C, VD)&lt;/math&gt;, and thus by the corollary to the Yoneda lemma, &lt;math&gt;UD = VD&lt;/math&gt;, natural in &lt;math&gt;D&lt;/math&gt;. <br /> <br /> ====Functors that are adjoints====<br /> <br /> * The functor &lt;math&gt;X\mapsto X\times A&lt;/math&gt; has right adjoint &lt;math&gt;Y\mapsto Y^A&lt;/math&gt;. The universal mapping property of the exponentials follows from the adjointness property.<br /> * The functor &lt;math&gt;\Delta: C\to C\times C, c\mapsto (c,c)&lt;/math&gt; has a left adjoint given by the coproduct &lt;math&gt;(X,Y)\mapsto X + Y&lt;/math&gt; and right adjoint the product &lt;math&gt;(X,Y)\mapsto X\times Y&lt;/math&gt;.<br /> * More generally, the functor &lt;math&gt;C\to C^J&lt;/math&gt; that takes &lt;math&gt;c&lt;/math&gt; to the constant functor &lt;math&gt;const_c(j) = c, const_c(f) = 1_c&lt;/math&gt; has left andright adjoints given by colimits and limits:<br /> :&lt;math&gt;\lim_\rightarrow -| \Delta -| \lim_\leftarrow&lt;/math&gt;<br /> * Pointed rings are pairs &lt;math&gt;(R, r\in R)&lt;/math&gt; of rings and one element singled out for attention. Homomorphisms of pointed rings need to take the distinguished point to the distinguished point. There is an obvious forgetful functor &lt;math&gt;U: Rings_* \to Rings&lt;/math&gt;, and this has a left adjoint - a free ring functor that adjoins a new indeterminate &lt;math&gt;R\mapsto (R[x], x)&lt;/math&gt;. This gives a formal definition of what we mean by ''formal polynomial expressions'' et.c.<br /> * Given sets &lt;math&gt;A, B&lt;/math&gt;, we can consider the powersets &lt;math&gt;P(A), P(B)&lt;/math&gt; containing, as elements, all subsets of &lt;math&gt;A, B&lt;/math&gt; respectively. Suppose &lt;math&gt;f:A\to B&lt;/math&gt; is a function, then &lt;math&gt;f^{-1}: P(B)\to P(A)&lt;/math&gt; takes subsets of &lt;math&gt;B&lt;/math&gt; to subsets of &lt;math&gt;A&lt;/math&gt;. <br /> :Viewing &lt;math&gt;P(A)&lt;/math&gt; and &lt;math&gt;P(B)&lt;/math&gt; as partially ordered sets by the inclusion operations, and then as categories induced by the partial order, &lt;math&gt;f^{-1}&lt;/math&gt; turns into a functor between partial orders. And it turns out &lt;math&gt;f^{-1}&lt;/math&gt; has a left adjoint given by the operation &lt;math&gt;im(f)&lt;/math&gt; taking a subset to the set of images under the function &lt;math&gt;f&lt;/math&gt;. And it has a right adjoint &lt;math&gt;f_*(U) = \{b\in B: f^{-1}(b)\subseteq U\}&lt;/math&gt;<br /> * We can introduce a categorical structure to logic. We let &lt;math&gt;L&lt;/math&gt; be a formal language, say of predicate logic. Then for any list &lt;math&gt;x = x_1, x_2, ..., x_n&lt;/math&gt; of variables, we have a preorder &lt;math&gt;Form(x)&lt;/math&gt; of formulas with no free variables not occuring in &lt;math&gt;x&lt;/math&gt;. The preorder on &lt;math&gt;Form(x)&lt;/math&gt; comes from the ''entailment'' operation - &lt;math&gt; f |- g&lt;/math&gt; if in every interpretation of the language, &lt;math&gt;f \Rightarrow g&lt;/math&gt;.<br /> : We can build an operation on these preorders - a functor on the underlying categories - by adjoining a single new variable: &lt;math&gt;*: Form(x) \to Form(x, y)&lt;/math&gt;, sending each form to itself. Obviously, if &lt;math&gt;f |- g&lt;/math&gt; with &lt;math&gt;x&lt;/math&gt; the source of free variables, if we introduce a new allowable free variable, but don't actually change the formulas, the entailment stays the same.<br /> : It turns out that there is a right adjoint to &lt;math&gt;*&lt;/math&gt; given by &lt;math&gt;f\mapsto \forall y. f&lt;/math&gt;. And a left adjoint to &lt;math&gt;*&lt;/math&gt; given by &lt;math&gt;f\mapsto \exists y. f&lt;/math&gt;. Adjointness properties give us classical deduction rules from logic.<br /> <br /> ===Homework===<br /> <br /> # Write a fold for the data type &lt;hask&gt;data T a = L a | B a a | C a a a&lt;/hask&gt; and demonstrate how this can be written as a catamorphism by giving the algebra it maps to. <br /> # Write the fibonacci function as a hylomorphism.<br /> # Write the Towers of Hanoi as a hylomorphism. You'll probably want to use binary trees as the intermediate data structure.<br /> # Write a prime numbers generator as an anamorphism.<br /> # * The integers have a partial order induced by the divisibility relation. We can thus take any integer and arrange all its divisors in a tree by having an edge &lt;math&gt;n \to d&lt;/math&gt; if &lt;math&gt;d|n&lt;/math&gt; and &lt;math&gt;d&lt;/math&gt; doesn't divide any other divisor of &lt;math&gt;n&lt;/math&gt;. Write an anamorphic function that will generate this tree for a given starting integer. Demonstrate how this function is an anamorphism by giving the algebra it maps from.<br /> :''Hint'': You will be helped by having a function to generate a list of all primes. One suggestion is:<br /> &lt;haskell&gt;<br /> primes :: [Integer]<br /> primes = sieve [2..]<br /> where<br /> sieve (p:xs) = p : sieve [x|x &lt;- xs, x mod p &gt; 0]<br /> &lt;/haskell&gt;<br /> :''Hint'': A good data structure to use is; with expected output of running the algorithm:<br /> &lt;haskell&gt;<br /> data Tree = Leaf Integer | Node Integer [Tree]<br /> <br /> divisionTree 60 = <br /> Node 60 [<br /> Node 30 [<br /> Node 15 [<br /> Leaf 5,<br /> Leaf 3],<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2]],<br /> Node 20 [<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]],<br /> Node 12 [<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]]]<br /> &lt;/haskell&gt;</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_9&diff=31618 User:Michiexile/MATH198/Lecture 9 2009-11-17T18:03:33Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Recursion patterns===<br /> <br /> Meijer, Fokkinga &amp; Patterson identified in the paper ''Functional programming with bananas, lenses, envelopes and barbed wire'' a number of generic patterns for recursive programming that they had observed, catalogued and systematized. The aim of that paper is to establish a number of ''rules'' for modifying and rewriting expressions involving these generic recursion patterns.<br /> <br /> As it turns out, these patterns are instances of the same phenomenon we saw last lecture: where the recursion comes from specifying a different algebra, and then take a uniquely existing morphism induced by initiality (or, as we shall see, finality). <br /> <br /> Before we go through the recursion patterns, we need to establish a few pieces of theoretical language, dualizing the Eilenberg-Moore algebra constructions from the last lecture.<br /> <br /> ====Coalgebras for endofunctors====<br /> <br /> '''Definition''' If &lt;math&gt;P: C\to C&lt;/math&gt; is an endofunctor, then a &lt;math&gt;P&lt;/math&gt;-''coalgebra'' on &lt;math&gt;A&lt;/math&gt; is a morphism &lt;math&gt;a: A\to PA&lt;/math&gt;.<br /> <br /> A ''morphism of coalgebras'': &lt;math&gt;f: a\to b&lt;/math&gt; is some &lt;math&gt;f: A\to B&lt;/math&gt; such that the diagram <br /> :[[Image:CoalgebraMorphism.png]]<br /> commutes. <br /> <br /> Just as with algebras, we get a category of coalgebras. And the interesting objects here are the ''final coalgebras''. Just as with algebras, we have<br /> <br /> '''Lemma''' (''Lambek'') If &lt;math&gt;a: A\to PA&lt;/math&gt; is a final coalgebra, it is an isomorphism.<br /> <br /> Finally, one thing that makes us care highly about these entities: in an appropriate category (such as &lt;math&gt;\omega-CPO&lt;/math&gt;), initial algebras and final coalgebras coincide, with the correspondence given by inverting the algebra/coalgebra morphism. In Haskell not quite true (specifically, the final coalgebra for the lists functor gives us streams...).<br /> <br /> Onwards to recursion schemes!<br /> <br /> We shall define a few specific morphisms we'll use repeatedly. This notation, introduced here, occurs all over the place in these corners of the literature, and are good to be aware of in general: <br /> * If &lt;math&gt;a: TA\to A&lt;/math&gt; is an initial algebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = in_A&lt;/math&gt;.<br /> * If &lt;math&gt;a: A\to TA&lt;/math&gt; is a final coalgebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = out_A&lt;/math&gt;.<br /> * We write &lt;math&gt;\mu f&lt;/math&gt; for the fixed point operator<br /> &lt;haskell&gt;<br /> mu f = x where x = f x<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\Delta g)&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> Delta f g = \x -&gt; (f x, g x)<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\nabla g) x&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> (Nabla f g) (Left x) = f x<br /> (Nabla f g) (Right x) = g x<br /> &lt;/haskell&gt;<br /> <br /> These two last constructions are directly motivated by the maps induced from the universal properties of products and coproducts.<br /> <br /> We shall write &lt;math&gt;(f\times g)&lt;/math&gt; and &lt;math&gt;(f+g)&lt;/math&gt; for the &lt;math&gt;\Delta&lt;/math&gt; and &lt;math&gt;\nabla&lt;/math&gt; constructions, respectively.<br /> <br /> We note that in the situation considered by MFP, inital algebras and final coalgebras coincide, and thus &lt;math&gt;in_A, out_A&lt;/math&gt; are the pair of isomorphic maps induced by either the initial algebra- or the final coalgebra-structure.<br /> <br /> ====Catamorphisms====<br /> <br /> A ''catamorphism'' is the uniquely existing morphism from an initial algebra to a different algebra. We have to define maps down to the return value type for each of the constructors of the complex data type we're recursing over, and the catamorphism will deconstruct the structure (trees, lists, ...) and do a generalized ''fold'' over the structure at hand before returning the final value.<br /> <br /> The intuition is that for catamorphisms we start essentially structured, and dismantle the structure.<br /> <br /> '''Example''': the length function from last lecture. This is the catamorphism for the functor &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; given by the maps<br /> &lt;haskell&gt;<br /> u :: Int<br /> u = 0<br /> <br /> m :: (A, Int) -&gt; Int<br /> m (a, n) = n+1<br /> &lt;/haskell&gt;<br /> <br /> MFP define the catamorphism by, supposing &lt;hask&gt;T&lt;/hask&gt; is initial for the functor &lt;hask&gt;F&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> cata :: (F a b -&gt; b) -&gt; T a -&gt; b<br /> cata phi = mu (\x -&gt; phi . fmap x . outT)<br /> &lt;/haskell&gt;<br /> <br /> We can reframe the example above as a catamorphism by observing that here, <br /> &lt;haskell&gt;<br /> data F a b = Nil | Cons a b deriving (Eq, Show)<br /> type T a = [a]<br /> <br /> instance Functor (F a) where<br /> fmap _ Nil = Nil<br /> fmap f (Cons n a) = Cons n (f a)<br /> <br /> outT :: T a -&gt; F a (T a)<br /> outT [] = Nil<br /> outT (a:as) = Cons a as<br /> <br /> lphi :: F a Int -&gt; Int<br /> lphi Nil = 0<br /> lphi (Cons a n) = n + 1<br /> <br /> l = cata lphi<br /> &lt;/haskell&gt;<br /> where we observe that &lt;hask&gt;mu&lt;/hask&gt; has a global definition for everything we do and &lt;hask&gt;out&lt;/hask&gt; is defined once we settle on the functor &lt;hask&gt;F&lt;/hask&gt; and its initial algebra. Thus, the definition of &lt;hask&gt;phi&lt;/hask&gt; really is the only place that the recursion data shows up. <br /> <br /> ====Anamorphisms====<br /> <br /> An ''anamorphism'' is the categorical dual to the catamorphism. It is the canonical morphism from a coalgebra to the final coalgebra for that endofunctor. <br /> <br /> Here, we start unstructured, and erect a structure, induced by the coalgebra structures involved. <br /> <br /> '''Example''': we can write a recursive function <br /> &lt;haskell&gt;<br /> first :: Int -&gt; [Int]<br /> first 1 = <br /> first n = n : first (n - 1)<br /> &lt;/haskell&gt;<br /> This is an anamorphism from the coalgebra for &lt;math&gt;P_{\mathbb N}(X) = 1 + \mathbb N\times X&lt;/math&gt; on &lt;math&gt;\mathbb N&lt;/math&gt; generated by the two maps<br /> &lt;haskell&gt;<br /> c 0 = Left ()<br /> c n = Right (n, n-1)<br /> &lt;/haskell&gt;<br /> and we observe that we can chase through the diagram<br /> :[[Image:CoalgebraMorphism.png]]<br /> to conclude that therefore<br /> &lt;haskell&gt;<br /> f 0 = []<br /> f n = n : f (n - 1)<br /> &lt;/haskell&gt;<br /> which is exactly the recursion we wrote to begin with.<br /> <br /> MFP define the anamorphism by a fixpoint as well, namely:<br /> &lt;haskell&gt;<br /> ana :: (b -&gt; F a b) -&gt; b -&gt; T a<br /> ana psi = mu (\x -&gt; inT . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> We can, again, recast our illustration above into a structural anamorphism, by:<br /> &lt;haskell&gt;<br /> -- Reuse mu, F, T from above<br /> inT :: F a (T a) -&gt; T a<br /> inT Nil = []<br /> inT (Cons a as) = a:as<br /> <br /> fpsi :: Int -&gt; F Int Int<br /> fpsi 0 = Nil<br /> fpsi n = Cons n (n-1)<br /> &lt;/haskell&gt;<br /> <br /> Again, we can note that the implementation of &lt;hask&gt;fpsi&lt;/hask&gt; here is exactly the &lt;hask&gt;c&lt;/hask&gt; above, and the resulting function will - as we can verify by compiling and running - give us the same kind of reversed list of the n first integers as the &lt;hask&gt;first&lt;/hask&gt; function above would.<br /> <br /> ====Hylomorphisms====<br /> <br /> The ''hylomorphisms'' capture one of the two possible compositions of anamorphisms and catamorphisms. Parametrized over an algebra &lt;math&gt;\phi: T A\to A&lt;/math&gt; and a coalgebra &lt;math&gt;\psi: B \to T B&lt;/math&gt; the hylomorphism is a recursion pattern that computes a value in &lt;math&gt;A&lt;/math&gt; from a value in &lt;math&gt;A&lt;/math&gt; by generating some sort of intermediate structure and then collapsing it again.<br /> <br /> It is, thus the composition of the uniquely existing morphism from a coalgebra to the final coalgebra for an endofunctor, followed by the uniquely existing morphism from the initial algebra to some other algebra.<br /> <br /> MFP define it, again, as a fix point: <br /> &lt;haskell&gt;<br /> hylo :: (F a b2 -&gt; b2) -&gt; (b1 -&gt; F a b1) -&gt; b1 -&gt; b2<br /> hylo phi psi = mu (\x -&gt; phi . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> First off, we can observe that by picking one or the other of &lt;math&gt;in_A, out_A&lt;/math&gt; as a parameter, we can recover both the anamorphisms and the catamorphisms as hylomorphisms.<br /> <br /> As an example, we'll compute the factorial function using a hylomorphism:<br /> <br /> &lt;haskell&gt;<br /> phi :: F Int Int -&gt; Int<br /> phi Nil = 1<br /> phi (Cons n m) = n*m<br /> <br /> psi :: Int -&gt; F Int Int<br /> psi 0 = Int<br /> psi n = Cons n (n-1)<br /> <br /> factorial = hylo phi psi<br /> &lt;/haskell&gt;<br /> <br /> ====Metamorphisms====<br /> <br /> The ''metamorphism'' is the ''other'' composition of an anamorphism with a catamorphism. It takes some structure, deconstructs it, and then reconstructs a new structure from it. <br /> <br /> As a recursion pattern, it's kinda boring - it'll take an interesting structure, deconstruct it into a ''scalar'' value, and then reconstruct some structure from that scalar. As such, it won't even capture the richness of &lt;math&gt;hom(F x, G y)&lt;/math&gt;, since any morphism expressed as a metamorphism will factor through a map &lt;math&gt;x\to y&lt;/math&gt;.<br /> <br /> ====Paramorphisms====<br /> <br /> ''Paramorphisms'' were discussed in the MFP paper as a way to extend the catamorphisms so that the operating function can access its arguments in computation as well as in recursion. We gave the factorial above as a hylomorphism instead of a catamorphism precisely because no simple enough catamorphic structure exists.<br /> <br /> ====Apomorphisms====<br /> <br /> The ''apomorphism'' is the dual of the paramorphism - it does with retention of values along the way what anamorphisms do compared to catamorphisms.<br /> <br /> ===Further reading===<br /> <br /> Terminology in the literature: in and out, inl, inr. <br /> Bananas et.c.<br /> Sorting morphisms.<br /> <br /> ===Further properties of adjunctions===<br /> <br /> ====RAPL====<br /> <br /> '''Proposition''' If &lt;math&gt;F&lt;/math&gt; is a ''right adjoint'', thus if &lt;math&gt;F&lt;/math&gt; has a left adjoint, then &lt;math&gt;F&lt;/math&gt; preserves limits in the sense that &lt;math&gt;F(\lim_{\leftarrow} A_i) = \lim_{\leftarrow} F(A_i)&lt;/math&gt;.<br /> <br /> Example: &lt;math&gt;(\lim_{\leftarrow_i} A_i)\times X = \lim_{\leftarrow_i} A_i\times X&lt;/math&gt;. <br /> <br /> We can use this to prove that things cannot be adjoints - since all right adjoints preserve limits, if a functor &lt;math&gt;G&lt;/math&gt; doesn't preserve limits, then it doesn't have a left adjoint.<br /> <br /> Similarly, and dually, left adjoints preserve colimits. Thus if a functor doesn't preserve colimits, it cannot be a left adjoint, thus cannot have a right adjoint.<br /> <br /> The proof of these statements build on the ''Yoneda lemma'': <br /> <br /> '''Lemma''' If &lt;math&gt;C&lt;/math&gt; is a locally small category (i.e. all hom-sets are sets). Then for any &lt;math&gt;c\in C_0&lt;/math&gt; and any functor &lt;math&gt;F: C^{op}\to Sets&lt;/math&gt; there is an isomorphism<br /> :&lt;math&gt;hom_{hom_{Sets^{C^{op}}}}(yC, F) = FC&lt;/math&gt;<br /> where we define &lt;math&gt;yC = d\mapsto hom_C(d,c) : C^{op}\to Sets&lt;/math&gt;.<br /> <br /> The Yoneda lemma has one important corollary: <br /> <br /> '''Corollary''' If &lt;math&gt;yA = yB&lt;/math&gt; then &lt;math&gt;A = B&lt;/math&gt;.<br /> <br /> Which, in turn has a number of important corollaries:<br /> <br /> '''Corollary''' &lt;math&gt;(A^B)^C = A^{B\times C}&lt;/math&gt;<br /> <br /> '''Corollary''' Adjoints are unique up to isomorphism - in particular, if &lt;math&gt;F: C\to D&lt;/math&gt; is a functor with right adjoints &lt;math&gt;U, V: D\to C&lt;/math&gt;, then &lt;math&gt;U = V&lt;/math&gt;.<br /> <br /> '''Proof''' &lt;math&gt;hom_C(C, UD) = hom_D(FC, D) = hom_C(C, VD)&lt;/math&gt;, and thus by the corollary to the Yoneda lemma, &lt;math&gt;UD = VD&lt;/math&gt;, natural in &lt;math&gt;D&lt;/math&gt;. <br /> <br /> ====Functors that are adjoints====<br /> <br /> * The functor &lt;math&gt;X\mapsto X\times A&lt;/math&gt; has right adjoint &lt;math&gt;Y\mapsto Y^A&lt;/math&gt;. The universal mapping property of the exponentials follows from the adjointness property.<br /> * The functor &lt;math&gt;\Delta: C\to C\times C, c\mapsto (c,c)&lt;/math&gt; has a left adjoint given by the coproduct &lt;math&gt;(X,Y)\mapsto X + Y&lt;/math&gt; and right adjoint the product &lt;math&gt;(X,Y)\mapsto X\times Y&lt;/math&gt;.<br /> * More generally, the functor &lt;math&gt;C\to C^J&lt;/math&gt; that takes &lt;math&gt;c&lt;/math&gt; to the constant functor &lt;math&gt;const_c(j) = c, const_c(f) = 1_c&lt;/math&gt; has left andright adjoints given by colimits and limits:<br /> :&lt;math&gt;\lim_\rightarrow -| \Delta -| \lim_\leftarrow&lt;/math&gt;<br /> * Pointed rings are pairs &lt;math&gt;(R, r\in R)&lt;/math&gt; of rings and one element singled out for attention. Homomorphisms of pointed rings need to take the distinguished point to the distinguished point. There is an obvious forgetful functor &lt;math&gt;U: Rings_* \to Rings&lt;/math&gt;, and this has a left adjoint - a free ring functor that adjoins a new indeterminate &lt;math&gt;R\mapsto (R[x], x)&lt;/math&gt;. This gives a formal definition of what we mean by ''formal polynomial expressions'' et.c.<br /> * Given sets &lt;math&gt;A, B&lt;/math&gt;, we can consider the powersets &lt;math&gt;P(A), P(B)&lt;/math&gt; containing, as elements, all subsets of &lt;math&gt;A, B&lt;/math&gt; respectively. Suppose &lt;math&gt;f:A\to B&lt;/math&gt; is a function, then &lt;math&gt;f^{-1}: P(B)\to P(A)&lt;/math&gt; takes subsets of &lt;math&gt;B&lt;/math&gt; to subsets of &lt;math&gt;A&lt;/math&gt;. <br /> :Viewing &lt;math&gt;P(A)&lt;/math&gt; and &lt;math&gt;P(B)&lt;/math&gt; as partially ordered sets by the inclusion operations, and then as categories induced by the partial order, &lt;math&gt;f^{-1}&lt;/math&gt; turns into a functor between partial orders. And it turns out &lt;math&gt;f^{-1}&lt;/math&gt; has a left adjoint given by the operation &lt;math&gt;im(f)&lt;/math&gt; taking a subset to the set of images under the function &lt;math&gt;f&lt;/math&gt;. And it has a right adjoint &lt;math&gt;f_*(U) = \{b\in B: f^{-1}(b)\subseteq U\}&lt;/math&gt;<br /> * We can introduce a categorical structure to logic. We let &lt;math&gt;L&lt;/math&gt; be a formal language, say of predicate logic. Then for any list &lt;math&gt;x = x_1, x_2, ..., x_n&lt;/math&gt; of variables, we have a preorder &lt;math&gt;Form(x)&lt;/math&gt; of formulas with no free variables not occuring in &lt;math&gt;x&lt;/math&gt;. The preorder on &lt;math&gt;Form(x)&lt;/math&gt; comes from the ''entailment'' operation - &lt;math&gt; f |- g&lt;/math&gt; if in every interpretation of the language, &lt;math&gt;f \Rightarrow g&lt;/math&gt;.<br /> : We can build an operation on these preorders - a functor on the underlying categories - by adjoining a single new variable: &lt;math&gt;*: Form(x) \to Form(x, y)&lt;/math&gt;, sending each form to itself. Obviously, if &lt;math&gt;f |- g&lt;/math&gt; with &lt;math&gt;x&lt;/math&gt; the source of free variables, if we introduce a new allowable free variable, but don't actually change the formulas, the entailment stays the same.<br /> : It turns out that there is a right adjoint to &lt;math&gt;*&lt;/math&gt; given by &lt;math&gt;f\mapsto \forall y. f&lt;/math&gt;. And a left adjoint to &lt;math&gt;*&lt;/math&gt; given by &lt;math&gt;f\mapsto \exists y. f&lt;/math&gt;. Adjointness properties give us classical deduction rules from logic.<br /> <br /> ===Homework===<br /> <br /> # Write a fold for the data type &lt;hask&gt;data T a = L a | B a a | C a a a&lt;/hask&gt; and demonstrate how this can be written as a catamorphism by giving the algebra it maps to. <br /> # Write the fibonacci function as a hylomorphism.<br /> # Write the Towers of Hanoi as a hylomorphism. You'll probably want to use binary trees as the intermediate data structure.<br /> # Write a prime numbers generator as an anamorphism.<br /> # * The integers have a partial order induced by the divisibility relation. We can thus take any integer and arrange all its divisors in a tree by having an edge &lt;math&gt;n \to d&lt;/math&gt; if &lt;math&gt;d|n&lt;/math&gt; and &lt;math&gt;d&lt;/math&gt; doesn't divide any other divisor of &lt;math&gt;n&lt;/math&gt;. Write an anamorphic function that will generate this tree for a given starting integer. Demonstrate how this function is an anamorphism by giving the algebra it maps from.<br /> :''Hint'': You will be helped by having a function to generate a list of all primes. One suggestion is:<br /> &lt;haskell&gt;<br /> primes :: [Integer]<br /> primes = sieve [2..]<br /> where<br /> sieve (p:xs) = p : sieve [x|x &lt;- xs, x mod p &gt; 0]<br /> &lt;/haskell&gt;<br /> :''Hint'': A good data structure to use is; with expected output of running the algorithm:<br /> &lt;haskell&gt;<br /> data Tree = Leaf Integer | Node Integer [Tree]<br /> <br /> divisionTree 60 = <br /> Node 60 [<br /> Node 30 [<br /> Node 15 [<br /> Leaf 5,<br /> Leaf 3],<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2]],<br /> Node 20 [<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]],<br /> Node 12 [<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]]]<br /> &lt;/haskell&gt;</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_9&diff=31613 User:Michiexile/MATH198/Lecture 9 2009-11-17T00:51:06Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Recursion patterns===<br /> <br /> Meijer, Fokkinga &amp; Patterson identified in the paper ''Functional programming with bananas, lenses, envelopes and barbed wire'' a number of generic patterns for recursive programming that they had observed, catalogued and systematized. The aim of that paper is to establish a number of ''rules'' for modifying and rewriting expressions involving these generic recursion patterns.<br /> <br /> As it turns out, these patterns are instances of the same phenomenon we saw last lecture: where the recursion comes from specifying a different algebra, and then take a uniquely existing morphism induced by initiality (or, as we shall see, finality). <br /> <br /> Before we go through the recursion patterns, we need to establish a few pieces of theoretical language, dualizing the Eilenberg-Moore algebra constructions from the last lecture.<br /> <br /> ====Coalgebras for endofunctors====<br /> <br /> '''Definition''' If &lt;math&gt;P: C\to C&lt;/math&gt; is an endofunctor, then a &lt;math&gt;P&lt;/math&gt;-''coalgebra'' on &lt;math&gt;A&lt;/math&gt; is a morphism &lt;math&gt;a: A\to PA&lt;/math&gt;.<br /> <br /> A ''morphism of coalgebras'': &lt;math&gt;f: a\to b&lt;/math&gt; is some &lt;math&gt;f: A\to B&lt;/math&gt; such that the diagram <br /> :[[Image:CoalgebraMorphism.png]]<br /> commutes. <br /> <br /> Just as with algebras, we get a category of coalgebras. And the interesting objects here are the ''final coalgebras''. Just as with algebras, we have<br /> <br /> '''Lemma''' (''Lambek'') If &lt;math&gt;a: A\to PA&lt;/math&gt; is a final coalgebra, it is an isomorphism.<br /> <br /> Finally, one thing that makes us care highly about these entities: in an appropriate category (such as &lt;math&gt;\omega-CPO&lt;/math&gt;), initial algebras and final coalgebras coincide, with the correspondence given by inverting the algebra/coalgebra morphism. In Haskell not quite true (specifically, the final coalgebra for the lists functor gives us streams...).<br /> <br /> Onwards to recursion schemes!<br /> <br /> We shall define a few specific morphisms we'll use repeatedly. This notation, introduced here, occurs all over the place in these corners of the literature, and are good to be aware of in general: <br /> * If &lt;math&gt;a: TA\to A&lt;/math&gt; is an initial algebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = in_A&lt;/math&gt;.<br /> * If &lt;math&gt;a: A\to TA&lt;/math&gt; is a final coalgebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = out_A&lt;/math&gt;.<br /> * We write &lt;math&gt;\mu f&lt;/math&gt; for the fixed point operator<br /> &lt;haskell&gt;<br /> mu f = x where x = f x<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\Delta g)&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> Delta f g = \x -&gt; (f x, g x)<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\nabla g) x&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> (Nabla f g) (Left x) = f x<br /> (Nabla f g) (Right x) = g x<br /> &lt;/haskell&gt;<br /> <br /> These two last constructions are directly motivated by the maps induced from the universal properties of products and coproducts.<br /> <br /> We shall write &lt;math&gt;(f\times g)&lt;/math&gt; and &lt;math&gt;(f+g)&lt;/math&gt; for the &lt;math&gt;\Delta&lt;/math&gt; and &lt;math&gt;\nabla&lt;/math&gt; constructions, respectively.<br /> <br /> We note that in the situation considered by MFP, inital algebras and final coalgebras coincide, and thus &lt;math&gt;in_A, out_A&lt;/math&gt; are the pair of isomorphic maps induced by either the initial algebra- or the final coalgebra-structure.<br /> <br /> ====Catamorphisms====<br /> <br /> A ''catamorphism'' is the uniquely existing morphism from an initial algebra to a different algebra. We have to define maps down to the return value type for each of the constructors of the complex data type we're recursing over, and the catamorphism will deconstruct the structure (trees, lists, ...) and do a generalized ''fold'' over the structure at hand before returning the final value.<br /> <br /> The intuition is that for catamorphisms we start essentially structured, and dismantle the structure.<br /> <br /> '''Example''': the length function from last lecture. This is the catamorphism for the functor &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; given by the maps<br /> &lt;haskell&gt;<br /> u :: Int<br /> u = 0<br /> <br /> m :: (A, Int) -&gt; Int<br /> m (a, n) = n+1<br /> &lt;/haskell&gt;<br /> <br /> MFP define the catamorphism by, supposing &lt;hask&gt;T&lt;/hask&gt; is initial for the functor &lt;hask&gt;F&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> cata :: (F a b -&gt; b) -&gt; T a -&gt; b<br /> cata phi = mu (\x -&gt; phi . fmap x . outT)<br /> &lt;/haskell&gt;<br /> <br /> We can reframe the example above as a catamorphism by observing that here, <br /> &lt;haskell&gt;<br /> data F a b = Nil | Cons a b deriving (Eq, Show)<br /> type T a = [a]<br /> <br /> instance Functor (F a) where<br /> fmap _ Nil = Nil<br /> fmap f (Cons n a) = Cons n (f a)<br /> <br /> outT :: T a -&gt; F a (T a)<br /> outT [] = Nil<br /> outT (a:as) = Cons a as<br /> <br /> lphi :: F a Int -&gt; Int<br /> lphi Nil = 0<br /> lphi (Cons a n) = n + 1<br /> <br /> l = cata lphi<br /> &lt;/haskell&gt;<br /> where we observe that &lt;hask&gt;mu&lt;/hask&gt; has a global definition for everything we do and &lt;hask&gt;out&lt;/hask&gt; is defined once we settle on the functor &lt;hask&gt;F&lt;/hask&gt; and its initial algebra. Thus, the definition of &lt;hask&gt;phi&lt;/hask&gt; really is the only place that the recursion data shows up. <br /> <br /> ====Anamorphisms====<br /> <br /> An ''anamorphism'' is the categorical dual to the catamorphism. It is the canonical morphism from a coalgebra to the final coalgebra for that endofunctor. <br /> <br /> Here, we start unstructured, and erect a structure, induced by the coalgebra structures involved. <br /> <br /> '''Example''': we can write a recursive function <br /> &lt;haskell&gt;<br /> first :: Int -&gt; [Int]<br /> first 1 = <br /> first n = n : first (n - 1)<br /> &lt;/haskell&gt;<br /> This is an anamorphism from the coalgebra for &lt;math&gt;P_{\mathbb N}(X) = 1 + \mathbb N\times X&lt;/math&gt; on &lt;math&gt;\mathbb N&lt;/math&gt; generated by the two maps<br /> &lt;haskell&gt;<br /> c 0 = Left ()<br /> c n = Right (n, n-1)<br /> &lt;/haskell&gt;<br /> and we observe that we can chase through the diagram<br /> :[[Image:CoalgebraMorphism.png]]<br /> to conclude that therefore<br /> &lt;haskell&gt;<br /> f 0 = []<br /> f n = n : f (n - 1)<br /> &lt;/haskell&gt;<br /> which is exactly the recursion we wrote to begin with.<br /> <br /> MFP define the anamorphism by a fixpoint as well, namely:<br /> &lt;haskell&gt;<br /> ana :: (b -&gt; F a b) -&gt; b -&gt; T a<br /> ana psi = mu (\x -&gt; inT . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> We can, again, recast our illustration above into a structural anamorphism, by:<br /> &lt;haskell&gt;<br /> -- Reuse mu, F, T from above<br /> inT :: F a (T a) -&gt; T a<br /> inT Nil = []<br /> inT (Cons a as) = a:as<br /> <br /> fpsi :: Int -&gt; F Int Int<br /> fpsi 0 = Nil<br /> fpsi n = Cons n (n-1)<br /> &lt;/haskell&gt;<br /> <br /> Again, we can note that the implementation of &lt;hask&gt;fpsi&lt;/hask&gt; here is exactly the &lt;hask&gt;c&lt;/hask&gt; above, and the resulting function will - as we can verify by compiling and running - give us the same kind of reversed list of the n first integers as the &lt;hask&gt;first&lt;/hask&gt; function above would.<br /> <br /> ====Hylomorphisms====<br /> <br /> The ''hylomorphisms'' capture one of the two possible compositions of anamorphisms and catamorphisms. Parametrized over an algebra &lt;math&gt;\phi: T A\to A&lt;/math&gt; and a coalgebra &lt;math&gt;\psi: B \to T B&lt;/math&gt; the hylomorphism is a recursion pattern that computes a value in &lt;math&gt;A&lt;/math&gt; from a value in &lt;math&gt;A&lt;/math&gt; by generating some sort of intermediate structure and then collapsing it again.<br /> <br /> It is, thus the composition of the uniquely existing morphism from a coalgebra to the final coalgebra for an endofunctor, followed by the uniquely existing morphism from the initial algebra to some other algebra.<br /> <br /> MFP define it, again, as a fix point: <br /> &lt;haskell&gt;<br /> hylo :: (F a b2 -&gt; b2) -&gt; (b1 -&gt; F a b1) -&gt; b1 -&gt; b2<br /> hylo phi psi = mu (\x -&gt; phi . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> First off, we can observe that by picking one or the other of &lt;math&gt;in_A, out_A&lt;/math&gt; as a parameter, we can recover both the anamorphisms and the catamorphisms as hylomorphisms.<br /> <br /> As an example, we'll compute the factorial function using a hylomorphism:<br /> <br /> &lt;haskell&gt;<br /> phi :: F Int Int -&gt; Int<br /> phi Nil = 1<br /> phi (Cons n m) = n*m<br /> <br /> psi :: Int -&gt; F Int Int<br /> psi 0 = Int<br /> psi n = Cons n (n-1)<br /> <br /> factorial = hylo phi psi<br /> &lt;/haskell&gt;<br /> <br /> ====Metamorphisms====<br /> <br /> The ''metamorphism'' is the ''other'' composition of an anamorphism with a catamorphism. It takes some structure, deconstructs it, and then reconstructs a new structure from it. <br /> <br /> As a recursion pattern, it's kinda boring - it'll take an interesting structure, deconstruct it into a ''scalar'' value, and then reconstruct some structure from that scalar. As such, it won't even capture the richness of &lt;math&gt;hom(F x, G y)&lt;/math&gt;, since any morphism expressed as a metamorphism will factor through a map &lt;math&gt;x\to y&lt;/math&gt;.<br /> <br /> ====Paramorphisms====<br /> <br /> ''Paramorphisms'' were discussed in the MFP paper as a way to extend the catamorphisms so that the operating function can access its arguments in computation as well as in recursion. We gave the factorial above as a hylomorphism instead of a catamorphism precisely because no simple enough catamorphic structure exists.<br /> <br /> ====Apomorphisms====<br /> <br /> The ''apomorphism'' is the dual of the paramorphism - it does with retention of values along the way what anamorphisms do compared to catamorphisms.<br /> <br /> ===Further reading===<br /> <br /> Terminology in the literature: in and out, inl, inr. <br /> Bananas et.c.<br /> Sorting morphisms.<br /> <br /> ===Homework===<br /> <br /> # Write a fold for the data type &lt;hask&gt;data T a = L a | B a a | C a a a&lt;/hask&gt; and demonstrate how this can be written as a catamorphism by giving the algebra it maps to. <br /> # Write the fibonacci function as a hylomorphism.<br /> # Write the Towers of Hanoi as a hylomorphism. You'll probably want to use binary trees as the intermediate data structure.<br /> # Write a prime numbers generator as an anamorphism.<br /> # * The integers have a partial order induced by the divisibility relation. We can thus take any integer and arrange all its divisors in a tree by having an edge &lt;math&gt;n \to d&lt;/math&gt; if &lt;math&gt;d|n&lt;/math&gt; and &lt;math&gt;d&lt;/math&gt; doesn't divide any other divisor of &lt;math&gt;n&lt;/math&gt;. Write an anamorphic function that will generate this tree for a given starting integer. Demonstrate how this function is an anamorphism by giving the algebra it maps from.<br /> :''Hint'': You will be helped by having a function to generate a list of all primes. One suggestion is:<br /> &lt;haskell&gt;<br /> primes :: [Integer]<br /> primes = sieve [2..]<br /> where<br /> sieve (p:xs) = p : sieve [x|x &lt;- xs, x mod p &gt; 0]<br /> &lt;/haskell&gt;<br /> :''Hint'': A good data structure to use is; with expected output of running the algorithm:<br /> &lt;haskell&gt;<br /> data Tree = Leaf Integer | Node Integer [Tree]<br /> <br /> divisionTree 60 = <br /> Node 60 [<br /> Node 30 [<br /> Node 15 [<br /> Leaf 5,<br /> Leaf 3],<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2]],<br /> Node 20 [<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]],<br /> Node 12 [<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]]]<br /> &lt;/haskell&gt;</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_9&diff=31612 User:Michiexile/MATH198/Lecture 9 2009-11-17T00:13:54Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Recursion patterns===<br /> <br /> Meijer, Fokkinga &amp; Patterson identified in the paper ''Functional programming with bananas, lenses, envelopes and barbed wire'' a number of generic patterns for recursive programming that they had observed, catalogued and systematized. The aim of that paper is to establish a number of ''rules'' for modifying and rewriting expressions involving these generic recursion patterns.<br /> <br /> As it turns out, these patterns are instances of the same phenomenon we saw last lecture: where the recursion comes from specifying a different algebra, and then take a uniquely existing morphism induced by initiality (or, as we shall see, finality). <br /> <br /> Before we go through the recursion patterns, we need to establish a few pieces of theoretical language, dualizing the Eilenberg-Moore algebra constructions from the last lecture.<br /> <br /> ====Coalgebras for endofunctors====<br /> <br /> '''Definition''' If &lt;math&gt;P: C\to C&lt;/math&gt; is an endofunctor, then a &lt;math&gt;P&lt;/math&gt;-''coalgebra'' on &lt;math&gt;A&lt;/math&gt; is a morphism &lt;math&gt;a: A\to PA&lt;/math&gt;.<br /> <br /> A ''morphism of coalgebras'': &lt;math&gt;f: a\to b&lt;/math&gt; is some &lt;math&gt;f: A\to B&lt;/math&gt; such that the diagram <br /> :[[Image:CoalgebraMorphism.png]]<br /> commutes. <br /> <br /> Just as with algebras, we get a category of coalgebras. And the interesting objects here are the ''final coalgebras''. Just as with algebras, we have<br /> <br /> '''Lemma''' (''Lambek'') If &lt;math&gt;a: A\to PA&lt;/math&gt; is a final coalgebra, it is an isomorphism.<br /> <br /> Finally, one thing that makes us care highly about these entities: in an appropriate category (such as &lt;math&gt;\omega-CPO&lt;/math&gt;), initial algebras and final coalgebras coincide, with the correspondence given by inverting the algebra/coalgebra morphism. In Haskell not quite true (specifically, the final coalgebra for the lists functor gives us streams...).<br /> <br /> Onwards to recursion schemes!<br /> <br /> We shall define a few specific morphisms we'll use repeatedly. This notation, introduced here, occurs all over the place in these corners of the literature, and are good to be aware of in general: <br /> * If &lt;math&gt;a: TA\to A&lt;/math&gt; is an initial algebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = in_A&lt;/math&gt;.<br /> * If &lt;math&gt;a: A\to TA&lt;/math&gt; is a final coalgebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = out_A&lt;/math&gt;.<br /> * We write &lt;math&gt;\mu f&lt;/math&gt; for the fixed point operator<br /> &lt;haskell&gt;<br /> mu f = x where x = f x<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\Delta g)&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> Delta f g = \x -&gt; (f x, g x)<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\nabla g) x&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> (Nabla f g) (Left x) = f x<br /> (Nabla f g) (Right x) = g x<br /> &lt;/haskell&gt;<br /> <br /> These two last constructions are directly motivated by the maps induced from the universal properties of products and coproducts.<br /> <br /> We shall write &lt;math&gt;(f\times g)&lt;/math&gt; and &lt;math&gt;(f+g)&lt;/math&gt; for the &lt;math&gt;\Delta&lt;/math&gt; and &lt;math&gt;\nabla&lt;/math&gt; constructions, respectively.<br /> <br /> We note that in the situation considered by MFP, inital algebras and final coalgebras coincide, and thus &lt;math&gt;in_A, out_A&lt;/math&gt; are the pair of isomorphic maps induced by either the initial algebra- or the final coalgebra-structure.<br /> <br /> ====Catamorphisms====<br /> <br /> A ''catamorphism'' is the uniquely existing morphism from an initial algebra to a different algebra. We have to define maps down to the return value type for each of the constructors of the complex data type we're recursing over, and the catamorphism will deconstruct the structure (trees, lists, ...) and do a generalized ''fold'' over the structure at hand before returning the final value.<br /> <br /> The intuition is that for catamorphisms we start essentially structured, and dismantle the structure.<br /> <br /> '''Example''': the length function from last lecture. This is the catamorphism for the functor &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; given by the maps<br /> &lt;haskell&gt;<br /> u :: Int<br /> u = 0<br /> <br /> m :: (A, Int) -&gt; Int<br /> m (a, n) = n+1<br /> &lt;/haskell&gt;<br /> <br /> MFP define the catamorphism by, supposing &lt;hask&gt;T&lt;/hask&gt; is initial for the functor &lt;hask&gt;F&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> cata :: (F a b -&gt; b) -&gt; T a -&gt; b<br /> cata phi = mu (\x -&gt; phi . fmap x . outT)<br /> &lt;/haskell&gt;<br /> <br /> We can reframe the example above as a catamorphism by observing that here, <br /> &lt;haskell&gt;<br /> data F a b = Nil | Cons a b deriving (Eq, Show)<br /> type T a = [a]<br /> <br /> instance Functor (F a) where<br /> fmap _ Nil = Nil<br /> fmap f (Cons n a) = Cons n (f a)<br /> <br /> outT :: T a -&gt; F a (T a)<br /> outT [] = Nil<br /> outT (a:as) = Cons a as<br /> <br /> lphi :: F a Int -&gt; Int<br /> lphi Nil = 0<br /> lphi (Cons a n) = n + 1<br /> <br /> l = cata lphi<br /> &lt;/haskell&gt;<br /> where we observe that &lt;hask&gt;mu&lt;/hask&gt; has a global definition for everything we do and &lt;hask&gt;out&lt;/hask&gt; is defined once we settle on the functor &lt;hask&gt;F&lt;/hask&gt; and its initial algebra. Thus, the definition of &lt;hask&gt;phi&lt;/hask&gt; really is the only place that the recursion data shows up. <br /> <br /> ====Anamorphisms====<br /> <br /> An ''anamorphism'' is the categorical dual to the catamorphism. It is the canonical morphism from a coalgebra to the final coalgebra for that endofunctor. <br /> <br /> Here, we start unstructured, and erect a structure, induced by the coalgebra structures involved. <br /> <br /> '''Example''': we can write a recursive function <br /> &lt;haskell&gt;<br /> first :: Int -&gt; [Int]<br /> first 1 = <br /> first n = n : first (n - 1)<br /> &lt;/haskell&gt;<br /> This is an anamorphism from the coalgebra for &lt;math&gt;P_{\mathbb N}(X) = 1 + \mathbb N\times X&lt;/math&gt; on &lt;math&gt;\mathbb N&lt;/math&gt; generated by the two maps<br /> &lt;haskell&gt;<br /> c 0 = Left ()<br /> c n = Right (n, n-1)<br /> &lt;/haskell&gt;<br /> and we observe that we can chase through the diagram<br /> :[[Image:CoalgebraMorphism.png]]<br /> to conclude that therefore<br /> &lt;haskell&gt;<br /> f 0 = []<br /> f n = n : f (n - 1)<br /> &lt;/haskell&gt;<br /> which is exactly the recursion we wrote to begin with.<br /> <br /> MFP define the anamorphism by a fixpoint as well, namely:<br /> &lt;haskell&gt;<br /> ana psi = mu (\x -&gt; inT . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> We can, again, recast our illustration above into a structural anamorphism, by:<br /> &lt;haskell&gt;<br /> -- Reuse mu, F, T from above<br /> inT :: F a (T a) -&gt; T a<br /> inT Nil = []<br /> inT (Cons a as) = a:as<br /> <br /> fpsi :: Int -&gt; F Int Int<br /> fpsi 0 = Nil<br /> fpsi n = Cons n (n-1)<br /> &lt;/haskell&gt;<br /> <br /> Again, we can note that the implementation of &lt;hask&gt;fpsi&lt;/hask&gt; here is exactly the &lt;hask&gt;c&lt;/hask&gt; above, and the resulting function will - as we can verify by compiling and running - give us the same kind of reversed list of the n first integers as the &lt;hask&gt;first&lt;/hask&gt; function above would.<br /> <br /> ====Hylomorphisms====<br /> <br /> The ''hylomorphisms'' capture one of the two possible compositions of anamorphisms and catamorphisms. Parametrized over an algebra &lt;math&gt;\phi: T A\to A&lt;/math&gt; and a coalgebra &lt;math&gt;\psi: B \to T B&lt;/math&gt; the hylomorphism is a recursion pattern that computes a value in &lt;math&gt;A&lt;/math&gt; from a value in &lt;math&gt;A&lt;/math&gt; by generating some sort of intermediate structure and then collapsing it again.<br /> <br /> It is, thus the composition of the uniquely existing morphism from a coalgebra to the final coalgebra for an endofunctor, followed by the uniquely existing morphism from the initial algebra to some other algebra.<br /> <br /> MFP define it, again, as a fix point: <br /> &lt;haskell&gt;<br /> hylo phi psi = mu (\x -&gt; phi . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> First off, we can observe that by picking one or the other of &lt;math&gt;in_A, out_A&lt;/math&gt; as a parameter, we can recover both the anamorphisms and the catamorphisms as hylomorphisms.<br /> <br /> As an example, we'll compute the factorial function using a hylomorphism:<br /> <br /> &lt;haskell&gt;<br /> phi :: F Int Int -&gt; Int<br /> phi Nil = 1<br /> phi (Cons n m) = n*m<br /> <br /> psi :: Int -&gt; F Int Int<br /> psi 0 = Int<br /> psi n = Cons n (n-1)<br /> <br /> factorial = hylo phi psi<br /> &lt;/haskell&gt;<br /> <br /> <br /> ====Metamorphisms====<br /> <br /> ====Paramorphisms====<br /> <br /> ====Apomorphisms====<br /> <br /> ===Further reading===<br /> <br /> Terminology in the literature: in and out, inl, inr. <br /> <br /> <br /> ===Homework===<br /> <br /> # Write a fold for the data type &lt;hask&gt;data T a = L a | B a a | C a a a&lt;/hask&gt; and demonstrate how this can be written as a catamorphism by giving the algebra it maps to. <br /> # Write the fibonacci function as a hylomorphism.<br /> # * The integers have a partial order induced by the divisibility relation. We can thus take any integer and arrange all its divisors in a tree by having an edge &lt;math&gt;n \to d&lt;/math&gt; if &lt;math&gt;d|n&lt;/math&gt; and &lt;math&gt;d&lt;/math&gt; doesn't divide any other divisor of &lt;math&gt;n&lt;/math&gt;. Write an anamorphic function that will generate this tree for a given starting integer. Demonstrate how this function is an anamorphism by giving the algebra it maps from.<br /> :''Hint'': You will be helped by having a function to generate a list of all primes. One suggestion is:<br /> &lt;haskell&gt;<br /> primes :: [Integer]<br /> primes = sieve [2..]<br /> where<br /> sieve (p:xs) = p : sieve [x|x &lt;- xs, x mod p &gt; 0]<br /> &lt;/haskell&gt;<br /> :''Hint'': A good data structure to use is; with expected output of running the algorithm:<br /> &lt;haskell&gt;<br /> data Tree = Leaf Integer | Node Integer [Tree]<br /> <br /> divisionTree 60 = <br /> Node 60 [<br /> Node 30 [<br /> Node 15 [<br /> Leaf 5,<br /> Leaf 3],<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2]],<br /> Node 20 [<br /> Node 10 [<br /> Leaf 5,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]],<br /> Node 12 [<br /> Node 6 [<br /> Leaf 3,<br /> Leaf 2],<br /> Node 4 [<br /> Leaf 2]]]<br /> &lt;/haskell&gt;</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_9&diff=31608 User:Michiexile/MATH198/Lecture 9 2009-11-16T22:49:45Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Recursion patterns===<br /> <br /> Meijer, Fokkinga &amp; Patterson identified in the paper ''Functional programming with bananas, lenses, envelopes and barbed wire'' a number of generic patterns for recursive programming that they had observed, catalogued and systematized. The aim of that paper is to establish a number of ''rules'' for modifying and rewriting expressions involving these generic recursion patterns.<br /> <br /> As it turns out, these patterns are instances of the same phenomenon we saw last lecture: where the recursion comes from specifying a different algebra, and then take a uniquely existing morphism induced by initiality (or, as we shall see, finality). <br /> <br /> Before we go through the recursion patterns, we need to establish a few pieces of theoretical language, dualizing the Eilenberg-Moore algebra constructions from the last lecture.<br /> <br /> ====Coalgebras for endofunctors====<br /> <br /> '''Definition''' If &lt;math&gt;P: C\to C&lt;/math&gt; is an endofunctor, then a &lt;math&gt;P&lt;/math&gt;-''coalgebra'' on &lt;math&gt;A&lt;/math&gt; is a morphism &lt;math&gt;a: A\to PA&lt;/math&gt;.<br /> <br /> A ''morphism of coalgebras'': &lt;math&gt;f: a\to b&lt;/math&gt; is some &lt;math&gt;f: A\to B&lt;/math&gt; such that the diagram <br /> :[[Image:CoalgebraMorphism.png]]<br /> commutes. <br /> <br /> Just as with algebras, we get a category of coalgebras. And the interesting objects here are the ''final coalgebras''. Just as with algebras, we have<br /> <br /> '''Lemma''' (''Lambek'') If &lt;math&gt;a: A\to PA&lt;/math&gt; is a final coalgebra, it is an isomorphism.<br /> <br /> Finally, one thing that makes us care highly about these entities: in an appropriate category (such as &lt;math&gt;\omega-CPO&lt;/math&gt;), initial algebras and final coalgebras coincide, with the correspondence given by inverting the algebra/coalgebra morphism. In Haskell not quite true (specifically, the final coalgebra for the lists functor gives us streams...).<br /> <br /> Onwards to recursion schemes!<br /> <br /> We shall define a few specific morphisms we'll use repeatedly. This notation, introduced here, occurs all over the place in these corners of the literature, and are good to be aware of in general: <br /> * If &lt;math&gt;a: TA\to A&lt;/math&gt; is an initial algebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = in_A&lt;/math&gt;.<br /> * If &lt;math&gt;a: A\to TA&lt;/math&gt; is a final coalgebra for &lt;math&gt;T&lt;/math&gt;, we denote &lt;math&gt;a = out_A&lt;/math&gt;.<br /> * We write &lt;math&gt;\mu f&lt;/math&gt; for the fixed point operator<br /> &lt;haskell&gt;<br /> mu f = x where x = f x<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\Delta g)&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> Delta f g = \x -&gt; (f x, g x)<br /> &lt;/haskell&gt;<br /> * MFP write &lt;math&gt;(f\nabla g) x&lt;/math&gt; for<br /> &lt;haskell&gt;<br /> (Nabla f g) (Left x) = f x<br /> (Nabla f g) (Right x) = g x<br /> &lt;/haskell&gt;<br /> <br /> These two last constructions are directly motivated by the maps induced from the universal properties of products and coproducts.<br /> <br /> We shall write &lt;math&gt;(f\times g)&lt;/math&gt; and &lt;math&gt;(f+g)&lt;/math&gt; for the &lt;math&gt;\Delta&lt;/math&gt; and &lt;math&gt;\nabla&lt;/math&gt; constructions, respectively.<br /> <br /> We note that in the situation considered by MFP, inital algebras and final coalgebras coincide, and thus &lt;math&gt;in_A, out_A&lt;/math&gt; are the pair of isomorphic maps induced by either the initial algebra- or the final coalgebra-structure.<br /> <br /> ====Catamorphisms====<br /> <br /> A ''catamorphism'' is the uniquely existing morphism from an initial algebra to a different algebra. We have to define maps down to the return value type for each of the constructors of the complex data type we're recursing over, and the catamorphism will deconstruct the structure (trees, lists, ...) and do a generalized ''fold'' over the structure at hand before returning the final value.<br /> <br /> The intuition is that for catamorphisms we start essentially structured, and dismantle the structure.<br /> <br /> '''Example''': the length function from last lecture. This is the catamorphism for the functor &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; given by the maps<br /> &lt;haskell&gt;<br /> u :: Int<br /> u = 0<br /> <br /> m :: (A, Int) -&gt; Int<br /> m (a, n) = n+1<br /> &lt;/haskell&gt;<br /> <br /> MFP define the catamorphism by, supposing &lt;hask&gt;T&lt;/hask&gt; is initial for the functor &lt;hask&gt;F&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> cata :: (F a b -&gt; b) -&gt; T a -&gt; b<br /> cata phi = mu (\x -&gt; phi . fmap x . outT)<br /> &lt;/haskell&gt;<br /> <br /> We can reframe the example above as a catamorphism by observing that here, <br /> &lt;haskell&gt;<br /> data F a b = Nil | Cons a b deriving (Eq, Show)<br /> type T a = [a]<br /> <br /> instance Functor (F a) where<br /> fmap _ Nil = Nil<br /> fmap f (Cons n a) = Cons n (f a)<br /> <br /> outT :: T a -&gt; F a (T a)<br /> outT [] = Nil<br /> outT (a:as) = Cons a as<br /> <br /> lphi :: F a Int -&gt; Int<br /> lphi Nil = 0<br /> lphi (Cons a n) = n + 1<br /> <br /> l = cata lphi<br /> &lt;/haskell&gt;<br /> where we observe that &lt;hask&gt;mu&lt;/hask&gt; has a global definition for everything we do and &lt;hask&gt;out&lt;/hask&gt; is defined once we settle on the functor &lt;hask&gt;F&lt;/hask&gt; and its initial algebra. Thus, the definition of &lt;hask&gt;phi&lt;/hask&gt; really is the only place that the recursion data shows up. <br /> <br /> ====Anamorphisms====<br /> <br /> An ''anamorphism'' is the categorical dual to the catamorphism. It is the canonical morphism from a coalgebra to the final coalgebra for that endofunctor. <br /> <br /> Here, we start unstructured, and erect a structure, induced by the coalgebra structures involved. <br /> <br /> '''Example''': we can write a recursive function <br /> &lt;haskell&gt;<br /> first :: Int -&gt; [Int]<br /> first 1 = <br /> first n = n : first (n - 1)<br /> &lt;/haskell&gt;<br /> This is an anamorphism from the coalgebra for &lt;math&gt;P_{\mathbb N}(X) = 1 + \mathbb N\times X&lt;/math&gt; on &lt;math&gt;\mathbb N&lt;/math&gt; generated by the two maps<br /> &lt;haskell&gt;<br /> c 0 = Left ()<br /> c n = Right (n, n-1)<br /> &lt;/haskell&gt;<br /> and we observe that we can chase through the diagram<br /> :[[Image:CoalgebraMorphism.png]]<br /> to conclude that therefore<br /> &lt;haskell&gt;<br /> f 0 = []<br /> f n = n : f (n - 1)<br /> &lt;/haskell&gt;<br /> which is exactly the recursion we wrote to begin with.<br /> <br /> MFP define the anamorphism by a fixpoint as well, namely:<br /> &lt;haskell&gt;<br /> ana psi = mu (\x -&gt; inT . fmap x . psi)<br /> &lt;/haskell&gt;<br /> <br /> We can, again, recast our illustration above into a structural anamorphism, by:<br /> &lt;haskell&gt;<br /> -- Reuse mu, F, T from above<br /> inT :: F a (T a) -&gt; T a<br /> inT Nil = []<br /> inT (Cons a as) = a:as<br /> <br /> fpsi :: Int -&gt; F Int Int<br /> fpsi 0 = Nil<br /> fpsi n = Cons n (n-1)<br /> &lt;/haskell&gt;<br /> <br /> <br /> <br /> <br /> <br /> ====Hylomorphisms====<br /> <br /> ====Metamorphisms====<br /> <br /> ====Paramorphisms====<br /> <br /> ====Apomorphisms====<br /> <br /> ===Further reading===<br /> <br /> Terminology in the literature: in and out, inl, inr. <br /> <br /> <br /> ===Homework===<br /> <br /> # Write a fold for the data type &lt;hask&gt;data T a = L a | B a a | C a a a&lt;/hask&gt; and demonstrate how this can be written as a catamorphism by giving the algebra it maps to. <br /> # The integers have a partial order induced by the divisibility relation. We can thus take any integer and arrange all its divisors in a tree by having an edge &lt;math&gt;n \to d&lt;/math&gt; if &lt;math&gt;d|n&lt;/math&gt; and &lt;math&gt;d&lt;/math&gt; doesn't divide any other divisor of &lt;math&gt;n&lt;/math&gt;. Write an anamorphic function that will generate this tree for a given starting integer. Demonstrate how this function is an anamorphism by giving the algebra it maps from.</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_9&diff=31573 User:Michiexile/MATH198/Lecture 9 2009-11-14T08:26:07Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Recursion patterns===<br /> <br /> ((X, Y and Z)) identified in the paper ((Bananas et.c.)) a number of generic patterns for recursive programming that they had observed, catalogued and systematized. The aim of that paper is to establish a number of ''rules'' for modifying and rewriting expressions involving these generic recursion patterns.<br /> <br /> As it turns out, these patterns are instances of the same phenomenon we saw last lecture: where the recursion comes from specifying a different algebra, and then take a uniquely existing morphism induced by initiality (or, as we shall see, finality). <br /> <br /> Before we go through the recursion patterns, we need to establish a few pieces of theoretical language, dualizing the Eilenberg-Moore algebra constructions from the last lecture.<br /> <br /> ====Coalgebras for endofunctors====<br /> <br /> '''Definition''' If &lt;math&gt;P: C\to C&lt;/math&gt; is an endofunctor, then a &lt;math&gt;P&lt;/math&gt;-''coalgebra'' on &lt;math&gt;A&lt;/math&gt; is a morphism &lt;math&gt;a: A\to PA&lt;/math&gt;.<br /> <br /> A ''morphism of coalgebras'': &lt;math&gt;f: a\to b&lt;/math&gt; is some &lt;math&gt;f: A\to B&lt;/math&gt; such that the diagram <br /> :[[Image:CoalgebraMorphism.png]]<br /> commutes. <br /> <br /> Just as with algebras, we get a category of coalgebras. And the interesting objects here are the ''final coalgebras''. Just as with algebras, we have<br /> <br /> '''Lemma''' (''Lambek'') If &lt;math&gt;a: A\to PA&lt;/math&gt; is a final coalgebra, it is an isomorphism.<br /> <br /> Finally, one thing that makes us care highly about these entities: in an appropriate category (such as &lt;math&gt;\omega-CPO&lt;/math&gt;), initial algebras and final coalgebras coincide, with the correspondence given by inverting the algebra/coalgebra morphism. In Haskell not quite true (specifically, the final coalgebra for the lists functor gives us streams...).<br /> <br /> Onwards to recursion schemes!<br /> <br /> ====Catamorphisms====<br /> <br /> A ''catamorphism'' is the uniquely existing morphism from an initial algebra to a different algebra. We have to define maps down to the return value type for each of the constructors of the complex data type we're recursing over, and the catamorphism will deconstruct the structure (trees, lists, ...) and do a generalized ''fold'' over the structure at hand before returning the final value.<br /> <br /> The intuition is that for catamorphisms we start essentially structured, and dismantle the structure.<br /> <br /> '''Example''': the length function from last lecture. This is the catamorphism for the functor &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; given by the maps<br /> &lt;haskell&gt;<br /> u :: Int<br /> u = 0<br /> <br /> m :: (A, Int) -&gt; Int<br /> m (a, n) = n+1<br /> &lt;/haskell&gt;<br /> <br /> ====Anamorphisms====<br /> <br /> An ''anamorphism'' is the categorical dual to the catamorphism. It is the canonical morphism from a coalgebra to the final coalgebra for that endofunctor. <br /> <br /> Here, we start unstructured, and erect a structure, induced by the coalgebra structures involved. <br /> <br /> '''Example''': we can write a recursive function <br /> &lt;haskell&gt;<br /> first :: Int -&gt; [Int]<br /> first 1 = <br /> first n = n : first (n - 1)<br /> &lt;/haskell&gt;<br /> This is an anamorphism from the coalgebra for &lt;math&gt;P_{\mathbb N}(X) = 1 + \mathbb N\times X&lt;/math&gt; on &lt;math&gt;\mathbb N&lt;/math&gt; generated by the two maps<br /> &lt;haskell&gt;<br /> c 0 = Left ()<br /> c n = Right (n, n-1)<br /> &lt;/haskell&gt;<br /> and we observe that we can chase through the diagram<br /> :[[Image:CoalgebraMorphism.png]]<br /> to conclude that therefore<br /> &lt;haskell&gt;<br /> f 0 = []<br /> f n = n : f (n - 1)<br /> &lt;/haskell&gt;<br /> which is exactly the recursion we wrote to begin with.<br /> <br /> ====Hylomorphisms====<br /> <br /> ====Metamorphisms====<br /> <br /> ====Paramorphisms====<br /> <br /> ====Apomorphisms====<br /> <br /> ===Further reading===<br /> <br /> Terminology in the literature: in and out, inl, inr. <br /> <br /> <br /> ===Homework===<br /> <br /> # Write a fold for the data type &lt;hask&gt;data T a = L a | B a a | C a a a&lt;/hask&gt; and demonstrate how this can be written as a catamorphism by giving the algebra it maps to. <br /> # The integers have a partial order induced by the divisibility relation. We can thus take any integer and arrange all its divisors in a tree by having an edge &lt;math&gt;n \to d&lt;/math&gt; if &lt;math&gt;d|n&lt;/math&gt; and &lt;math&gt;d&lt;/math&gt; doesn't divide any other divisor of &lt;math&gt;n&lt;/math&gt;. Write an anamorphic function that will generate this tree for a given starting integer. Demonstrate how this function is an anamorphism by giving the algebra it maps from.</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_9&diff=31568 User:Michiexile/MATH198/Lecture 9 2009-11-13T19:01:35Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Coalgebras for endofunctors===<br /> <br /> ===Recursion patterns===<br /> <br /> ====Catamorphisms====<br /> <br /> ====Anamorphisms====<br /> <br /> ====Hylomorphisms====<br /> <br /> ====Metamorphisms====<br /> <br /> ====Paramorphisms====<br /> <br /> ====Apomorphisms====</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_8&diff=31531 User:Michiexile/MATH198/Lecture 8 2009-11-11T18:59:59Z <p>Michiexile: </p> <hr /> <div>===Algebras over monads===<br /> <br /> We recall from the last lecture the definition of an Eilenberg-Moore algebra over a monad &lt;math&gt;T = (T, \eta, \mu)&lt;/math&gt;: <br /> <br /> '''Definition''' An ''algebra'' over a monad &lt;math&gt;T&lt;/math&gt; in a category &lt;math&gt;C&lt;/math&gt; (a &lt;math&gt;T&lt;/math&gt;-algebra) is a morphism &lt;math&gt;\alpha\in C(TA, A)&lt;/math&gt;, such that the diagrams below both commute:<br /> <br /> [[Image:EilenbergMooreUnity.png]]<br /> [[Image:EilenbergMooreAssociativity.png]]<br /> <br /> While a monad corresponds to the imposition of some structure on the objects in a category, an algebra over that monad corresponds to some evaluation of that structure. <br /> <br /> ====Example: monoids====<br /> <br /> Let &lt;math&gt;T&lt;/math&gt; be the Kleene star monad - the one we get from the adjunction of free and forgetful functors between Monoids and Sets. Then a &lt;math&gt;T&lt;/math&gt;-algebra on a set &lt;math&gt;A&lt;/math&gt; is equivalent to a monoid structure on &lt;math&gt;A&lt;/math&gt;.<br /> <br /> Indeed, if we have a monoid structure on &lt;math&gt;A&lt;/math&gt;, given by &lt;math&gt;m:A^2\to A&lt;/math&gt; and &lt;math&gt;u:1\to A&lt;/math&gt;, we can construct a &lt;math&gt;T&lt;/math&gt;-algebra by<br /> :&lt;math&gt;\alpha([]) = u&lt;/math&gt;<br /> :&lt;math&gt;\alpha([a_1,a_2,\dots,a_n]) = m(a_1,\alpha([a_2,\dots,a_n]))&lt;/math&gt;<br /> This gives us, indeed, a &lt;math&gt;T&lt;/math&gt;-algebra structure on &lt;math&gt;A&lt;/math&gt;. Associativity and unity follows from the corresponding properties in the monoid.<br /> <br /> On the other hand, if we have a &lt;math&gt;T&lt;/math&gt;-algebra structure on &lt;math&gt;A&lt;/math&gt;, we can construct a monoid structure by setting<br /> :&lt;math&gt;u = \alpha([])&lt;/math&gt;<br /> :&lt;math&gt;m(a,b) = \alpha([a,b])&lt;/math&gt; <br /> It is clear that associativity of &lt;math&gt;m&lt;/math&gt; follows from the associativity of &lt;math&gt;\alpha&lt;/math&gt;, and unitality of &lt;math&gt;u&lt;/math&gt; follows from the unitality of &lt;math&gt;\alpha&lt;/math&gt;.<br /> <br /> ====Example: Vector spaces====<br /> <br /> We have free and forgetful functors <br /> :&lt;math&gt;Set \to^{free} k-Vect \to^{forgetful} Set&lt;/math&gt;<br /> forming an adjoint pair; where the free functor takes a set &lt;math&gt;S&lt;/math&gt; and returns the vector space with basis &lt;math&gt;S&lt;/math&gt;; while the forgetful functor takes a vector space and returns the set of all its elements.<br /> <br /> The composition of these yields a monad &lt;math&gt;T&lt;/math&gt; in &lt;math&gt;Set&lt;/math&gt; taking a set &lt;math&gt;S&lt;/math&gt; to the set of all formal linear combinations of elements in &lt;math&gt;S&lt;/math&gt;. The monad multiplication takes formal linear combinations of formal linear combinations and multiplies them out:<br /> :&lt;math&gt;3(2v+5w)-5(3v+2w) = 6v+15w-15v-10w = -9v+5w&lt;/math&gt;<br /> <br /> A &lt;math&gt;T&lt;/math&gt;-algebra is a map &lt;math&gt;\alpha: TA\to A&lt;/math&gt; that ''acts like a vector space'' in the sense that &lt;math&gt;\alpha(\sum\alpha_i(\sum\beta_jv_j)) = \alpha(\sum\alpha_i\beta_jv_j)&lt;/math&gt;.<br /> <br /> We can define &lt;math&gt;\lambda\cdot v = \alpha(\lambda v)&lt;/math&gt; and &lt;math&gt;v+w=\alpha(v+w)&lt;/math&gt;. The operations thus defined are associative, distributive, commutative, and everything else we could wish for in order to define a vector space - precisely because the operations inside &lt;math&gt;TA&lt;/math&gt; are, and &lt;math&gt;\alpha&lt;/math&gt; is associative. <br /> <br /> ----<br /> <br /> The moral behind these examples is that using monads and monad algebras, we have significant power in defining and studying algebraic structures with categorical and algebraic tools. This paradigm ties in closely with the theory of ''operads'' - which has its origins in topology, but has come to good use within certain branches of universal algebra.<br /> <br /> An (non-symmetric) ''operad'' is a graded set &lt;math&gt;O = \bigoplus_i O_i&lt;/math&gt; equipped with composition operations &lt;math&gt;\circ_i: O_n\oplus O_m\to O_{n+m-1}&lt;/math&gt; that obey certain unity and associativity conditions. As it turns out, non-symmetric operads correspond to the summands in a monad with polynomial underlying functor, and from a non-symmetric operad we can construct a corresponding monad.<br /> <br /> The designator non-symmetric floats in this text o avoid dealing with the slightly more general theory of symmetric operads - which allow us to resort the input arguments, thus including the symmetrizer of a symmetric monoidal category in the entire definition. <br /> <br /> To read more about these correspondences, I can recommend you start with: the blog posts ''Monads in Mathematics'' here:<br /> [http://embuchestissues.wordpress.com/tag/monads-in-mathematics/]<br /> <br /> <br /> ===Algebras over endofunctors===<br /> <br /> Suppose we started out with an endofunctor that is not the underlying functor of a monad - or an endofunctor for which we don't want to settle on a monadic structure. We can still do a lot of the Eilenberg-Moore machinery on this endofunctor - but we don't get quite the power of algebraic specification that monads offer us. At the core, here, lies the lack of associativity for a generic endofunctor - and algebras over endofunctors, once defined, will correspond to non-associative correspondences to their monadic counterparts.<br /> <br /> '''Definition''' For an endofunctor &lt;math&gt;P:C\to C&lt;/math&gt;, we define a ''&lt;math&gt;P&lt;/math&gt;-algebra'' to be an arrow &lt;math&gt;\alpha\in C(PA,A)&lt;/math&gt;.<br /> <br /> A homomorphism of &lt;math&gt;P&lt;/math&gt;-algebras &lt;math&gt;\alpha\to\beta&lt;/math&gt; is some arrow &lt;math&gt;f:A\to B&lt;/math&gt; such that the diagram below commutes:<br /> :[[Image:EilenbergMoorePMorphism.png]]<br /> <br /> This homomorphism definition does not need much work to apply to the monadic case as well.<br /> <br /> ====Example: Groups====<br /> <br /> A group is a set &lt;math&gt;G&lt;/math&gt; with operations &lt;math&gt;u: 1\to G, i: G\to G, m: G\times G\to G&lt;/math&gt;, such that &lt;math&gt;u&lt;/math&gt; is a unit for &lt;math&gt;m&lt;/math&gt;, &lt;math&gt;m&lt;/math&gt; is associative, and &lt;math&gt;i&lt;/math&gt; is an inverse.<br /> <br /> Ignoring for a moment the properties, the theory of groups is captured by these three maps, or by a diagram<br /> :[[Image:GroupDiagram.png]]<br /> <br /> We can summarize the diagram as<br /> :&lt;math&gt;1+G+G\times G \mapsto^{[u,i,m]} G&lt;/math&gt;<br /> and thus recognize that groups are some equationally defined subcategory of the category of &lt;math&gt;T&lt;/math&gt;-algebras for the polynomial functor &lt;math&gt;T(X) = 1 + X + X\times X&lt;/math&gt;. The subcategory is ''full'', since if we have two algebras &lt;math&gt;\gamma: T(G)\to G&lt;/math&gt; and &lt;math&gt;\eta: T(H)\to H&lt;/math&gt;, that both lie within the subcategory that fulfills all the additional axioms, then certainly any morphism &lt;math&gt;\gamma\to\eta&lt;/math&gt; will be compatible with the structure maps, and thus will be a group homomorphism.<br /> <br /> ----<br /> <br /> We shall denote the category of &lt;math&gt;P&lt;/math&gt;-algebras in a category &lt;math&gt;C&lt;/math&gt; by &lt;math&gt;P-Alg(C)&lt;/math&gt;, or just &lt;math&gt;P-Alg&lt;/math&gt; if the category is implicitly understood.<br /> <br /> This category is wider than the corresponding concept for a monad. We don't require the kind of associativity we would for a monad - we just lock down the underlying structure. This distinction is best understood with an example: <br /> <br /> The free monoids monad has monoids for its algebras. On the other hand, we can pick out the underlying functor of that monad, forgetting about the unit and multiplication. An algebra over this structure is a slightly more general object: we no longer require &lt;math&gt;(a\cdot b)\cdot c = a\cdot (b\cdot c)&lt;/math&gt;, and thus, the theory we get is that of a ''magma''. We have concatenation, but we can't drop the brackets, and so we get something more reminiscent of a binary tree. <br /> <br /> ===Initial &lt;math&gt;P&lt;/math&gt;-algebras and recursion===<br /> <br /> Consider the polynomical functor &lt;math&gt;P(X) = 1 + X&lt;/math&gt; on the category of sets. It's algebras form a category, by the definitions above - and an algebra needs to pick out one special element 0, and one endomorphism T, for a given set.<br /> <br /> What would an initial object in this category of P-algebras look like? It would be an object &lt;math&gt;I&lt;/math&gt; equipped with maps &lt;math&gt;1 \to^o I \leftarrow^n I&lt;/math&gt;. For any other pair of maps &lt;math&gt;a: 1\to X, s: X\to X&lt;/math&gt;, we'd have a unique arrow &lt;math&gt;u: I\to X&lt;/math&gt; such that <br /> :[[Image:NNOcommutes.png]]<br /> commutes, or in equations such that<br /> :&lt;math&gt;u(o) = a&lt;/math&gt;<br /> :&lt;math&gt;u(n(x)) = s(u(x))&lt;/math&gt;<br /> <br /> Now, unwrapping the definitions in place, we notice that we will have elements &lt;math&gt;o, n(o), n(n(o), \dots&lt;/math&gt; in &lt;math&gt;I&lt;/math&gt;, and the initiality will force us to not have any ''other'' elements floating around. Also, intiality will prevent us from having any elements not in this minimally forced list.<br /> <br /> We can rename the elements to form something more recognizable - by equating an element in &lt;math&gt;I&lt;/math&gt; with the number of applications of &lt;math&gt;n&lt;/math&gt; to &lt;math&gt;o&lt;/math&gt;. This yields, for us, elements &lt;math&gt;0, 1, 2, \dots&lt;/math&gt; with one function that picks out the &lt;math&gt;0&lt;/math&gt;, and another that gives us the cussessor.<br /> <br /> This should be recognizable as exactly the natural numbers; with just enough structure on them to make the principle of mathematical induction work: suppose we can prove some statement &lt;math&gt;P(0)&lt;/math&gt;, and we can extend a proof of &lt;math&gt;P(n)&lt;/math&gt; to &lt;math&gt;P(n+1)&lt;/math&gt;. Then induction tells us that the statement holds for all &lt;math&gt;P(n)&lt;/math&gt;.<br /> <br /> More importantly, recursive definitions of functions from natural numbers can be performed here by choosing an appropriate algebra mapping to.<br /> <br /> This correspondence between the initial object of &lt;math&gt;P(X) = 1 + X&lt;/math&gt; is the reason such an initial object in a category with coproducts and terminal objects is called a ''natural numbers object''. <br /> <br /> For another example, we consider the functor &lt;math&gt;P(X) = 1 + X\times X&lt;/math&gt;. <br /> <br /> '''Pop Quiz''' Can you think of a structure with this as underlying defining functor?<br /> <br /> An initial &lt;math&gt;1+X\times X&lt;/math&gt;-algebra would be some diagram<br /> :&lt;math&gt;1 \to^o I \leftarrow^m I\times I&lt;/math&gt;<br /> such that for any other such diagram<br /> :&lt;math&gt;1 \to^a X \leftarrow^* X\times X&lt;/math&gt;<br /> we have a unique arrow &lt;math&gt;u:I\to X&lt;/math&gt; such that<br /> :[[Image:MonoidCommutes.png]]<br /> commutes.<br /> <br /> Unwrapping the definition, working over Sets again, we find we are forced to have some element &lt;math&gt;*&lt;/math&gt;, the image of &lt;math&gt;o&lt;/math&gt;. Any two elements &lt;math&gt;S,T&lt;/math&gt; in the set give rise to some &lt;math&gt;(S,T)&lt;/math&gt;, which we can view as being the binary tree<br /> :[[Image:MagmaComposition.png]]<br /> <br /> The same way that we could construct induction as an algebra map from a natural numbers object, we can use this object to construct a tree-shaped induction; and similarily, we can develop what amounts to the theory of ''structural induction'' using these more general approaches to induction.<br /> <br /> ====Example of structural induction====<br /> <br /> Using the structure of &lt;math&gt;1+X\times X&lt;/math&gt;-algebras we shall prove the following statement:<br /> <br /> '''Proposition''' The number of leaves in a binary tree is one more than the number of internal nodes.<br /> <br /> '''Proof''' We write down the actual Haskell data type for the binary tree initial algebra.<br /> &lt;haskell&gt;<br /> data Tree = Leaf | Node Tree Tree<br /> <br /> nLeaves Leaf = 1<br /> nLeaves (Node s t) = nLeaves s + nLeaves t<br /> <br /> nNodes Leaf = 0<br /> nNodes (Node s t) = 1 + nNodes s + nNodes t<br /> &lt;/haskell&gt;<br /> <br /> Now, it is clear, as a base case, that for the no-nodes tree &lt;hask&gt;Leaf&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> nLeaves Leaf = 1 + nNodes Leaf<br /> &lt;/haskell&gt;<br /> <br /> For the structural induction, now, we consider some binary tree, where we assume the statement to be known for each of the two subtrees. Hence, we have<br /> &lt;haskell&gt;<br /> tree = Node s t<br /> <br /> nLeaves s = 1 + nNodes s<br /> nLeaves t = 1 + nNodes t<br /> &lt;/haskell&gt;<br /> and we may compute<br /> &lt;haskell&gt;<br /> nLeaves tree = nLeaves s + nLeaves t <br /> = 1 + nNodes s + 1 + nNodes t <br /> = 2 + nNodes s + nNodes t<br /> <br /> nNodes tree = 1 + nNodes s + nNodes t<br /> &lt;/haskell&gt;<br /> <br /> Now, since the statement is proven for each of the cases in the structural description of the data, it follows form the principle of structural induction that the proof is finished.<br /> <br /> In order to really nail down what we are doing here, we need to define what we mean by predicates in a strict manner. There is a way to do this using ''fibrations'', but this reaches far outside the scope of this course. For the really interested reader, I'll refer to [http://www.springerlink.com/content/d022nlv03n26nm03/]. <br /> <br /> Another way to do this is to introduce a ''topos'', and work it all out in terms of its ''internal logic'', but again, this reaches outside the scope of this course.<br /> <br /> ====Lambek's lemma====<br /> <br /> What we do when we write a recursive data type definition in Haskell ''really'' to some extent is to define a data type as the initial algebra of the corresponding functor. This intuitive equivalence is vindicated by the following <br /> <br /> '''Lemma''' ''Lambek'' If &lt;math&gt;P: C\to C&lt;/math&gt; has an initial algebra &lt;math&gt;I&lt;/math&gt;, then &lt;math&gt;P(I) = I&lt;/math&gt;.<br /> <br /> '''Proof''' Let &lt;math&gt;a: PA\to A&lt;/math&gt; be an initial &lt;math&gt;P&lt;/math&gt;-algebra. We can apply &lt;math&gt;P&lt;/math&gt; again, and get a chain<br /> :&lt;math&gt;PPA \to^{Pa} PA \to^a A&lt;/math&gt;<br /> We can fill out the diagram<br /> :[[Image:LambekPartialDiagram.png]]<br /> to form the diagram<br /> :[[Image:LambekDiagram.png]]<br /> where &lt;math&gt;f&lt;/math&gt; is induced by initiality, since &lt;math&gt;Pa:PPa\to Pa&lt;/math&gt; is also a &lt;math&gt;P&lt;/math&gt;-algebra.<br /> <br /> The diagram above commutes, and thus &lt;math&gt;af = 1_{PA}&lt;/math&gt; and &lt;math&gt;fa = 1_A&lt;/math&gt;. Thus &lt;math&gt;f&lt;/math&gt; is an inverse to &lt;math&gt;a&lt;/math&gt;. QED.<br /> <br /> Thus, by Lambek's lemma we ''know'' that if &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; then for that &lt;math&gt;P_A&lt;/math&gt;, the initial algebra - should it exist - will fulfill&lt;math&gt;I = 1 + A\times I&lt;/math&gt;, which in turn is exactly what we write, defining this, in Haskell code: <br /> &lt;haskell&gt;<br /> List a = Nil | Cons a List<br /> &lt;/haskell&gt;<br /> <br /> ====Recursive definitions with the unique maps from the initial algebra====<br /> <br /> Consider the following &lt;math&gt;P_A(X)&lt;/math&gt;-algebra structure &lt;math&gt;l: P_A(\mathbb N)\to\mathbb N&lt;/math&gt; on the natural numbers:<br /> &lt;haskell&gt;<br /> l(*) = 0<br /> l(a,n) = 1 + n<br /> &lt;/haskell&gt;<br /> <br /> We get a unique map &lt;math&gt;f&lt;/math&gt; from the initial algebra for &lt;math&gt;P_A(X)&lt;/math&gt; (lists of elements of type &lt;math&gt;A&lt;/math&gt;) to &lt;math&gt;\mathbb N&lt;/math&gt; from this definition. This map will fulfill:<br /> &lt;haskell&gt;<br /> f(Nil) = l(*) = 0<br /> f(Cons a xs) = l(a,f(xs)) = 1 + f(xs)<br /> &lt;/haskell&gt;<br /> which starts taking on the shape of the usual definition of the length of a list:<br /> &lt;haskell&gt;<br /> length(Nil) = 0<br /> length(Cons a xs) = 1 + length(xs)<br /> &lt;/haskell&gt;<br /> <br /> And thus, the machinery of endofunctor algebras gives us a strong method for doing recursive definitions in a theoretically sound manner.<br /> <br /> ===Homework===<br /> <br /> Complete credit will be given for 8 of the 13 questions.<br /> <br /> # Find a monad whose algebras are ''associative algebras'': vector spaces with a binary, associative, unitary operation (multiplication) defined on them. Factorize the monad into a free/forgetful adjoint pair.<br /> # Find an endofunctor of &lt;math&gt;Hask&lt;/math&gt; whose initial object describes trees that are either binary of ternary at each point, carrying values from some &lt;math&gt;A&lt;/math&gt; in the leaves.<br /> # Write an implementation of the monad of vector spaces in Haskell. If this is tricky, restrict the domain of the monad to, say, a 3-element set, and implement the specific example of a 3-dimensional vector space as a monad. Hint: [http://sigfpe.blogspot.com] has written about this approach.<br /> # Find a &lt;math&gt;X\mapsto 1+A\times X&lt;/math&gt;-algebra &lt;math&gt;L&lt;/math&gt; such that the unique map from the initial algebra &lt;math&gt;I&lt;/math&gt; to &lt;math&gt;L&lt;/math&gt; results in the function that will reverse a given list.<br /> # Find a &lt;math&gt;X\mapsto 1+A\times X&lt;/math&gt;-algebra structure on the object &lt;math&gt;1+A&lt;/math&gt; that will pick out the first element of a list, if possible.<br /> # Find a &lt;math&gt;X\mapsto \mathbb N+X\times X&lt;/math&gt;-algebra structure on the object &lt;math&gt;\mathbb N&lt;/math&gt; that will pick out the sum of the leaf values for the binary tree in the initial object.<br /> # Complete the proof of Lambek's lemma by proving the diagram commutes.<br /> # * We define a ''coalgebra'' for an endofunctor &lt;math&gt;T&lt;/math&gt; to be some arrow &lt;math&gt;\gamma: A \to TA&lt;/math&gt;. If &lt;math&gt;T&lt;/math&gt; is a comonad - i.e. equipped with a counit &lt;math&gt;\epsilon: T\to 1&lt;/math&gt; and a cocomposition &lt;math&gt;\Delta: T\to T\times T&lt;/math&gt;, then we define a coalgebra for the comonad &lt;math&gt;T&lt;/math&gt; to additionally fulfill &lt;math&gt;\gamma\circ T\gamma = \gamma\circ\Delta&lt;/math&gt; (compatibility) and &lt;math&gt;\epsilon_A\circ\gamma = 1_A&lt;/math&gt; (counitality).<br /> ## (2pt) Prove that if &lt;math&gt;T&lt;/math&gt; is an endofunctor, then if &lt;math&gt;T&lt;/math&gt; has an initial algebra, then it is a coalgebra. Does &lt;math&gt;T&lt;/math&gt; necessarily have a final coalgebra?<br /> ## (2pt) Prove that if &lt;math&gt;U,F&lt;/math&gt; are an adjoint pair, then &lt;math&gt;FU&lt;/math&gt; forms a comonad.<br /> ## (2pt) Describe a final coalgebra over the comonad formed from the free/forgetful adjunction between the categories of Monoids and Sets.<br /> ## (2pt) Describe a final coalgebra over the endofunctor &lt;math&gt;P(X) = 1 + X&lt;/math&gt;.<br /> ## (2pt) Describe a final coalgebra over the endofunctor &lt;math&gt;P(X) = 1 + A\times X&lt;/math&gt;.<br /> ## (2pt) Prove that if &lt;math&gt;c: C\to PC&lt;/math&gt; is a final coalgebra for an endofunctor &lt;math&gt;P:C\to C&lt;/math&gt;, then &lt;math&gt;c&lt;/math&gt; is an isomorphism.</div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_8&diff=31530 User:Michiexile/MATH198/Lecture 8 2009-11-11T18:59:23Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Algebras over monads===<br /> <br /> We recall from the last lecture the definition of an Eilenberg-Moore algebra over a monad &lt;math&gt;T = (T, \eta, \mu)&lt;/math&gt;: <br /> <br /> '''Definition''' An ''algebra'' over a monad &lt;math&gt;T&lt;/math&gt; in a category &lt;math&gt;C&lt;/math&gt; (a &lt;math&gt;T&lt;/math&gt;-algebra) is a morphism &lt;math&gt;\alpha\in C(TA, A)&lt;/math&gt;, such that the diagrams below both commute:<br /> <br /> [[Image:EilenbergMooreUnity.png]]<br /> [[Image:EilenbergMooreAssociativity.png]]<br /> <br /> While a monad corresponds to the imposition of some structure on the objects in a category, an algebra over that monad corresponds to some evaluation of that structure. <br /> <br /> ====Example: monoids====<br /> <br /> Let &lt;math&gt;T&lt;/math&gt; be the Kleene star monad - the one we get from the adjunction of free and forgetful functors between Monoids and Sets. Then a &lt;math&gt;T&lt;/math&gt;-algebra on a set &lt;math&gt;A&lt;/math&gt; is equivalent to a monoid structure on &lt;math&gt;A&lt;/math&gt;.<br /> <br /> Indeed, if we have a monoid structure on &lt;math&gt;A&lt;/math&gt;, given by &lt;math&gt;m:A^2\to A&lt;/math&gt; and &lt;math&gt;u:1\to A&lt;/math&gt;, we can construct a &lt;math&gt;T&lt;/math&gt;-algebra by<br /> :&lt;math&gt;\alpha([]) = u&lt;/math&gt;<br /> :&lt;math&gt;\alpha([a_1,a_2,\dots,a_n]) = m(a_1,\alpha([a_2,\dots,a_n]))&lt;/math&gt;<br /> This gives us, indeed, a &lt;math&gt;T&lt;/math&gt;-algebra structure on &lt;math&gt;A&lt;/math&gt;. Associativity and unity follows from the corresponding properties in the monoid.<br /> <br /> On the other hand, if we have a &lt;math&gt;T&lt;/math&gt;-algebra structure on &lt;math&gt;A&lt;/math&gt;, we can construct a monoid structure by setting<br /> :&lt;math&gt;u = \alpha([])&lt;/math&gt;<br /> :&lt;math&gt;m(a,b) = \alpha([a,b])&lt;/math&gt; <br /> It is clear that associativity of &lt;math&gt;m&lt;/math&gt; follows from the associativity of &lt;math&gt;\alpha&lt;/math&gt;, and unitality of &lt;math&gt;u&lt;/math&gt; follows from the unitality of &lt;math&gt;\alpha&lt;/math&gt;.<br /> <br /> ====Example: Vector spaces====<br /> <br /> We have free and forgetful functors <br /> :&lt;math&gt;Set \to^{free} k-Vect \to^{forgetful} Set&lt;/math&gt;<br /> forming an adjoint pair; where the free functor takes a set &lt;math&gt;S&lt;/math&gt; and returns the vector space with basis &lt;math&gt;S&lt;/math&gt;; while the forgetful functor takes a vector space and returns the set of all its elements.<br /> <br /> The composition of these yields a monad &lt;math&gt;T&lt;/math&gt; in &lt;math&gt;Set&lt;/math&gt; taking a set &lt;math&gt;S&lt;/math&gt; to the set of all formal linear combinations of elements in &lt;math&gt;S&lt;/math&gt;. The monad multiplication takes formal linear combinations of formal linear combinations and multiplies them out:<br /> :&lt;math&gt;3(2v+5w)-5(3v+2w) = 6v+15w-15v-10w = -9v+5w&lt;/math&gt;<br /> <br /> A &lt;math&gt;T&lt;/math&gt;-algebra is a map &lt;math&gt;\alpha: TA\to A&lt;/math&gt; that ''acts like a vector space'' in the sense that &lt;math&gt;\alpha(\sum\alpha_i(\sum\beta_jv_j)) = \alpha(\sum\alpha_i\beta_jv_j)&lt;/math&gt;.<br /> <br /> We can define &lt;math&gt;\lambda\cdot v = \alpha(\lambda v)&lt;/math&gt; and &lt;math&gt;v+w=\alpha(v+w)&lt;/math&gt;. The operations thus defined are associative, distributive, commutative, and everything else we could wish for in order to define a vector space - precisely because the operations inside &lt;math&gt;TA&lt;/math&gt; are, and &lt;math&gt;\alpha&lt;/math&gt; is associative. <br /> <br /> ----<br /> <br /> The moral behind these examples is that using monads and monad algebras, we have significant power in defining and studying algebraic structures with categorical and algebraic tools. This paradigm ties in closely with the theory of ''operads'' - which has its origins in topology, but has come to good use within certain branches of universal algebra.<br /> <br /> An (non-symmetric) ''operad'' is a graded set &lt;math&gt;O = \bigoplus_i O_i&lt;/math&gt; equipped with composition operations &lt;math&gt;\circ_i: O_n\oplus O_m\to O_{n+m-1}&lt;/math&gt; that obey certain unity and associativity conditions. As it turns out, non-symmetric operads correspond to the summands in a monad with polynomial underlying functor, and from a non-symmetric operad we can construct a corresponding monad.<br /> <br /> The designator non-symmetric floats in this text o avoid dealing with the slightly more general theory of symmetric operads - which allow us to resort the input arguments, thus including the symmetrizer of a symmetric monoidal category in the entire definition. <br /> <br /> To read more about these correspondences, I can recommend you start with: the blog posts ''Monads in Mathematics'' here:<br /> [http://embuchestissues.wordpress.com/tag/monads-in-mathematics/]<br /> <br /> <br /> ===Algebras over endofunctors===<br /> <br /> Suppose we started out with an endofunctor that is not the underlying functor of a monad - or an endofunctor for which we don't want to settle on a monadic structure. We can still do a lot of the Eilenberg-Moore machinery on this endofunctor - but we don't get quite the power of algebraic specification that monads offer us. At the core, here, lies the lack of associativity for a generic endofunctor - and algebras over endofunctors, once defined, will correspond to non-associative correspondences to their monadic counterparts.<br /> <br /> '''Definition''' For an endofunctor &lt;math&gt;P:C\to C&lt;/math&gt;, we define a ''&lt;math&gt;P&lt;/math&gt;-algebra'' to be an arrow &lt;math&gt;\alpha\in C(PA,A)&lt;/math&gt;.<br /> <br /> A homomorphism of &lt;math&gt;P&lt;/math&gt;-algebras &lt;math&gt;\alpha\to\beta&lt;/math&gt; is some arrow &lt;math&gt;f:A\to B&lt;/math&gt; such that the diagram below commutes:<br /> :[[Image:EilenbergMoorePMorphism.png]]<br /> <br /> This homomorphism definition does not need much work to apply to the monadic case as well.<br /> <br /> ====Example: Groups====<br /> <br /> A group is a set &lt;math&gt;G&lt;/math&gt; with operations &lt;math&gt;u: 1\to G, i: G\to G, m: G\times G\to G&lt;/math&gt;, such that &lt;math&gt;u&lt;/math&gt; is a unit for &lt;math&gt;m&lt;/math&gt;, &lt;math&gt;m&lt;/math&gt; is associative, and &lt;math&gt;i&lt;/math&gt; is an inverse.<br /> <br /> Ignoring for a moment the properties, the theory of groups is captured by these three maps, or by a diagram<br /> :[[Image:GroupDiagram.png]]<br /> <br /> We can summarize the diagram as<br /> :&lt;math&gt;1+G+G\times G \mapsto^{[u,i,m]} G&lt;/math&gt;<br /> and thus recognize that groups are some equationally defined subcategory of the category of &lt;math&gt;T&lt;/math&gt;-algebras for the polynomial functor &lt;math&gt;T(X) = 1 + X + X\times X&lt;/math&gt;. The subcategory is ''full'', since if we have two algebras &lt;math&gt;\gamma: T(G)\to G&lt;/math&gt; and &lt;math&gt;\eta: T(H)\to H&lt;/math&gt;, that both lie within the subcategory that fulfills all the additional axioms, then certainly any morphism &lt;math&gt;\gamma\to\eta&lt;/math&gt; will be compatible with the structure maps, and thus will be a group homomorphism.<br /> <br /> ----<br /> <br /> We shall denote the category of &lt;math&gt;P&lt;/math&gt;-algebras in a category &lt;math&gt;C&lt;/math&gt; by &lt;math&gt;P-Alg(C)&lt;/math&gt;, or just &lt;math&gt;P-Alg&lt;/math&gt; if the category is implicitly understood.<br /> <br /> This category is wider than the corresponding concept for a monad. We don't require the kind of associativity we would for a monad - we just lock down the underlying structure. This distinction is best understood with an example: <br /> <br /> The free monoids monad has monoids for its algebras. On the other hand, we can pick out the underlying functor of that monad, forgetting about the unit and multiplication. An algebra over this structure is a slightly more general object: we no longer require &lt;math&gt;(a\cdot b)\cdot c = a\cdot (b\cdot c)&lt;/math&gt;, and thus, the theory we get is that of a ''magma''. We have concatenation, but we can't drop the brackets, and so we get something more reminiscent of a binary tree. <br /> <br /> ===Initial &lt;math&gt;P&lt;/math&gt;-algebras and recursion===<br /> <br /> Consider the polynomical functor &lt;math&gt;P(X) = 1 + X&lt;/math&gt; on the category of sets. It's algebras form a category, by the definitions above - and an algebra needs to pick out one special element 0, and one endomorphism T, for a given set.<br /> <br /> What would an initial object in this category of P-algebras look like? It would be an object &lt;math&gt;I&lt;/math&gt; equipped with maps &lt;math&gt;1 \to^o I \leftarrow^n I&lt;/math&gt;. For any other pair of maps &lt;math&gt;a: 1\to X, s: X\to X&lt;/math&gt;, we'd have a unique arrow &lt;math&gt;u: I\to X&lt;/math&gt; such that <br /> :[[Image:NNOcommutes.png]]<br /> commutes, or in equations such that<br /> :&lt;math&gt;u(o) = a&lt;/math&gt;<br /> :&lt;math&gt;u(n(x)) = s(u(x))&lt;/math&gt;<br /> <br /> Now, unwrapping the definitions in place, we notice that we will have elements &lt;math&gt;o, n(o), n(n(o), \dots&lt;/math&gt; in &lt;math&gt;I&lt;/math&gt;, and the initiality will force us to not have any ''other'' elements floating around. Also, intiality will prevent us from having any elements not in this minimally forced list.<br /> <br /> We can rename the elements to form something more recognizable - by equating an element in &lt;math&gt;I&lt;/math&gt; with the number of applications of &lt;math&gt;n&lt;/math&gt; to &lt;math&gt;o&lt;/math&gt;. This yields, for us, elements &lt;math&gt;0, 1, 2, \dots&lt;/math&gt; with one function that picks out the &lt;math&gt;0&lt;/math&gt;, and another that gives us the cussessor.<br /> <br /> This should be recognizable as exactly the natural numbers; with just enough structure on them to make the principle of mathematical induction work: suppose we can prove some statement &lt;math&gt;P(0)&lt;/math&gt;, and we can extend a proof of &lt;math&gt;P(n)&lt;/math&gt; to &lt;math&gt;P(n+1)&lt;/math&gt;. Then induction tells us that the statement holds for all &lt;math&gt;P(n)&lt;/math&gt;.<br /> <br /> More importantly, recursive definitions of functions from natural numbers can be performed here by choosing an appropriate algebra mapping to.<br /> <br /> This correspondence between the initial object of &lt;math&gt;P(X) = 1 + X&lt;/math&gt; is the reason such an initial object in a category with coproducts and terminal objects is called a ''natural numbers object''. <br /> <br /> For another example, we consider the functor &lt;math&gt;P(X) = 1 + X\times X&lt;/math&gt;. <br /> <br /> '''Pop Quiz''' Can you think of a structure with this as underlying defining functor?<br /> <br /> An initial &lt;math&gt;1+X\times X&lt;/math&gt;-algebra would be some diagram<br /> :&lt;math&gt;1 \to^o I \leftarrow^m I\times I&lt;/math&gt;<br /> such that for any other such diagram<br /> :&lt;math&gt;1 \to^a X \leftarrow^* X\times X&lt;/math&gt;<br /> we have a unique arrow &lt;math&gt;u:I\to X&lt;/math&gt; such that<br /> :[[Image:MonoidCommutes.png]]<br /> commutes.<br /> <br /> Unwrapping the definition, working over Sets again, we find we are forced to have some element &lt;math&gt;*&lt;/math&gt;, the image of &lt;math&gt;o&lt;/math&gt;. Any two elements &lt;math&gt;S,T&lt;/math&gt; in the set give rise to some &lt;math&gt;(S,T)&lt;/math&gt;, which we can view as being the binary tree<br /> :[[Image:MagmaComposition.png]]<br /> <br /> The same way that we could construct induction as an algebra map from a natural numbers object, we can use this object to construct a tree-shaped induction; and similarily, we can develop what amounts to the theory of ''structural induction'' using these more general approaches to induction.<br /> <br /> ====Example of structural induction====<br /> <br /> Using the structure of &lt;math&gt;1+X\times X&lt;/math&gt;-algebras we shall prove the following statement:<br /> <br /> '''Proposition''' The number of leaves in a binary tree is one more than the number of internal nodes.<br /> <br /> '''Proof''' We write down the actual Haskell data type for the binary tree initial algebra.<br /> &lt;haskell&gt;<br /> data Tree = Leaf | Node Tree Tree<br /> <br /> nLeaves Leaf = 1<br /> nLeaves (Node s t) = nLeaves s + nLeaves t<br /> <br /> nNodes Leaf = 0<br /> nNodes (Node s t) = 1 + nNodes s + nNodes t<br /> &lt;/haskell&gt;<br /> <br /> Now, it is clear, as a base case, that for the no-nodes tree &lt;hask&gt;Leaf&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> nLeaves Leaf = 1 + nNodes Leaf<br /> &lt;/haskell&gt;<br /> <br /> For the structural induction, now, we consider some binary tree, where we assume the statement to be known for each of the two subtrees. Hence, we have<br /> &lt;haskell&gt;<br /> tree = Node s t<br /> <br /> nLeaves s = 1 + nNodes s<br /> nLeaves t = 1 + nNodes t<br /> &lt;/haskell&gt;<br /> and we may compute<br /> &lt;haskell&gt;<br /> nLeaves tree = nLeaves s + nLeaves t <br /> = 1 + nNodes s + 1 + nNodes t <br /> = 2 + nNodes s + nNodes t<br /> <br /> nNodes tree = 1 + nNodes s + nNodes t<br /> &lt;/haskell&gt;<br /> <br /> Now, since the statement is proven for each of the cases in the structural description of the data, it follows form the principle of structural induction that the proof is finished.<br /> <br /> In order to really nail down what we are doing here, we need to define what we mean by predicates in a strict manner. There is a way to do this using ''fibrations'', but this reaches far outside the scope of this course. For the really interested reader, I'll refer to [http://www.springerlink.com/content/d022nlv03n26nm03/]. <br /> <br /> Another way to do this is to introduce a ''topos'', and work it all out in terms of its ''internal logic'', but again, this reaches outside the scope of this course.<br /> <br /> ====Lambek's lemma====<br /> <br /> What we do when we write a recursive data type definition in Haskell ''really'' to some extent is to define a data type as the initial algebra of the corresponding functor. This intuitive equivalence is vindicated by the following <br /> <br /> '''Lemma''' ''Lambek'' If &lt;math&gt;P: C\to C&lt;/math&gt; has an initial algebra &lt;math&gt;I&lt;/math&gt;, then &lt;math&gt;P(I) = I&lt;/math&gt;.<br /> <br /> '''Proof''' Let &lt;math&gt;a: PA\to A&lt;/math&gt; be an initial &lt;math&gt;P&lt;/math&gt;-algebra. We can apply &lt;math&gt;P&lt;/math&gt; again, and get a chain<br /> :&lt;math&gt;PPA \to^{Pa} PA \to^a A&lt;/math&gt;<br /> We can fill out the diagram<br /> :[[Image:LambekPartialDiagram.png]]<br /> to form the diagram<br /> :[[Image:LambekDiagram.png]]<br /> where &lt;math&gt;f&lt;/math&gt; is induced by initiality, since &lt;math&gt;Pa:PPa\to Pa&lt;/math&gt; is also a &lt;math&gt;P&lt;/math&gt;-algebra.<br /> <br /> The diagram above commutes, and thus &lt;math&gt;af = 1_{PA}&lt;/math&gt; and &lt;math&gt;fa = 1_A&lt;/math&gt;. Thus &lt;math&gt;f&lt;/math&gt; is an inverse to &lt;math&gt;a&lt;/math&gt;. QED.<br /> <br /> Thus, by Lambek's lemma we ''know'' that if &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; then for that &lt;math&gt;P_A&lt;/math&gt;, the initial algebra - should it exist - will fulfill&lt;math&gt;I = 1 + A\times I&lt;/math&gt;, which in turn is exactly what we write, defining this, in Haskell code: <br /> &lt;haskell&gt;<br /> List a = Nil | Cons a List<br /> &lt;/haskell&gt;<br /> <br /> ====Recursive definitions with the unique maps from the initial algebra====<br /> <br /> Consider the following &lt;math&gt;P_A(X)&lt;/math&gt;-algebra structure &lt;math&gt;l: P_A(\mathbb N)\to\mathbb N&lt;/math&gt; on the natural numbers:<br /> &lt;haskell&gt;<br /> l(*) = 0<br /> l(a,n) = 1 + n<br /> &lt;/haskell&gt;<br /> <br /> We get a unique map &lt;math&gt;f&lt;/math&gt; from the initial algebra for &lt;math&gt;P_A(X)&lt;/math&gt; (lists of elements of type &lt;math&gt;A&lt;/math&gt;) to &lt;math&gt;\mathbb N&lt;/math&gt; from this definition. This map will fulfill:<br /> &lt;haskell&gt;<br /> f(Nil) = l(*) = 0<br /> f(Cons a xs) = l(a,f(xs)) = 1 + f(xs)<br /> &lt;/haskell&gt;<br /> which starts taking on the shape of the usual definition of the length of a list:<br /> &lt;haskell&gt;<br /> length(Nil) = 0<br /> length(Cons a xs) = 1 + length(xs)<br /> &lt;/haskell&gt;<br /> <br /> And thus, the machinery of endofunctor algebras gives us a strong method for doing recursive definitions in a theoretically sound manner.<br /> <br /> ===Homework===<br /> <br /> Complete credit will be given for 8 of the 13 questions.<br /> <br /> # Find a monad whose algebras are ''associative algebras'': vector spaces with a binary, associative, unitary operation (multiplication) defined on them. Factorize the monad into a free/forgetful adjoint pair.<br /> # Find an endofunctor of &lt;math&gt;Hask&lt;/math&gt; whose initial object describes trees that are either binary of ternary at each point, carrying values from some &lt;math&gt;A&lt;/math&gt; in the leaves.<br /> # Write an implementation of the monad of vector spaces in Haskell. If this is tricky, restrict the domain of the monad to, say, a 3-element set, and implement the specific example of a 3-dimensional vector space as a monad. Hint: [http://sigfpe.blogspot.com] has written about this approach.<br /> # Find a &lt;math&gt;X\mapsto 1+A\times X&lt;/math&gt;-algebra &lt;math&gt;L&lt;/math&gt; such that the unique map from the initial algebra &lt;math&gt;I&lt;/math&gt; to &lt;math&gt;L&lt;/math&gt; results in the function that will reverse a given list.<br /> # Find a &lt;math&gt;X\mapsto 1+A\times X&lt;/math&gt;-algebra structure on the object &lt;math&gt;1+A&lt;/math&gt; that will pick out the first element of a list, if possible.<br /> # Find a &lt;math&gt;X\mapsto \mathbb N+X\times X&lt;/math&gt;-algebra structure on the object &lt;math&gt;\mathbb N&lt;/math&gt; that will pick out the sum of the leaf values for the binary tree in the initial object.<br /> # Complete the proof of Lambek's lemma by proving the diagram commutes.<br /> # * We define a ''coalgebra'' for an endofunctor &lt;math&gt;T&lt;/math&gt; to be some arrow &lt;math&gt;\gamma: A \to TA&lt;/math&gt;. If &lt;math&gt;T&lt;/math&gt; is a comonad - i.e. equipped with a counit &lt;math&gt;\epsilon: T\to 1&lt;/math&gt; and a cocomposition &lt;math&gt;\Delta: T\to T\times T&lt;/math&gt;, then we define a coalgebra for the comonad &lt;math&gt;T&lt;/math&gt; to additionally fulfill &lt;math&gt;\gamma\circ T\gamma = \gamma\circ\Delta&lt;/math&gt; (compatibility) and &lt;math&gt;\epsilon_A\circ\gamma = 1_A&lt;/math&gt; (counitality).<br /> ## (2pt) Prove that if &lt;math&gt;T&lt;/math&gt; is an endofunctor, then if &lt;math&gt;T&lt;/math&gt; has an initial algebra, then it is a coalgebra. Does &lt;math&gt;T&lt;/math&gt; necessarily have a final coalgebra?<br /> ## (2pt) Prove that if &lt;math&gt;U,F&lt;/math&gt; are an adjoint pair, then &lt;math&gt;FU&lt;/math&gt; forms a comonad.<br /> ## (2pt) Describe a final coalgebra over the comonad formed from the free/forgetful adjunction between the categories of Monoids and Sets.<br /> ## (2pt) Describe a final coalgebra over the endofunctor &lt;math&gt;P(X) = 1 + X&lt;/math&gt;.<br /> ## (2pt) Describe a final coalgebra over the endofunctor &lt;math&gt;P(X) = 1 + A\times X&lt;/math&gt;.<br /> ## (2pt) Prove that if &lt;math&gt;c: C\to PC&lt;/math&gt; is a final coalgebra for an endofunctor &lt;math&gt;P:C\to C&lt;/math&gt;, then &lt;math&gt;c&lt;/math&gt; is an isomorphism.</div> Michiexile https://wiki.haskell.org/index.php?title=File:LambekDiagram.png&diff=31529 File:LambekDiagram.png 2009-11-11T18:58:03Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:LambekPartialDiagram.png&diff=31528 File:LambekPartialDiagram.png 2009-11-11T18:57:30Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=User:Michiexile/MATH198/Lecture_8&diff=31527 User:Michiexile/MATH198/Lecture 8 2009-11-11T18:53:44Z <p>Michiexile: </p> <hr /> <div>IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.<br /> <br /> <br /> ===Algebras over monads===<br /> <br /> We recall from the last lecture the definition of an Eilenberg-Moore algebra over a monad &lt;math&gt;T = (T, \eta, \mu)&lt;/math&gt;: <br /> <br /> '''Definition''' An ''algebra'' over a monad &lt;math&gt;T&lt;/math&gt; in a category &lt;math&gt;C&lt;/math&gt; (a &lt;math&gt;T&lt;/math&gt;-algebra) is a morphism &lt;math&gt;\alpha\in C(TA, A)&lt;/math&gt;, such that the diagrams below both commute:<br /> <br /> [[Image:EilenbergMooreUnity.png]]<br /> [[Image:EilenbergMooreAssociativity.png]]<br /> <br /> While a monad corresponds to the imposition of some structure on the objects in a category, an algebra over that monad corresponds to some evaluation of that structure. <br /> <br /> ====Example: monoids====<br /> <br /> Let &lt;math&gt;T&lt;/math&gt; be the Kleene star monad - the one we get from the adjunction of free and forgetful functors between Monoids and Sets. Then a &lt;math&gt;T&lt;/math&gt;-algebra on a set &lt;math&gt;A&lt;/math&gt; is equivalent to a monoid structure on &lt;math&gt;A&lt;/math&gt;.<br /> <br /> Indeed, if we have a monoid structure on &lt;math&gt;A&lt;/math&gt;, given by &lt;math&gt;m:A^2\to A&lt;/math&gt; and &lt;math&gt;u:1\to A&lt;/math&gt;, we can construct a &lt;math&gt;T&lt;/math&gt;-algebra by<br /> :&lt;math&gt;\alpha([]) = u&lt;/math&gt;<br /> :&lt;math&gt;\alpha([a_1,a_2,\dots,a_n]) = m(a_1,\alpha([a_2,\dots,a_n]))&lt;/math&gt;<br /> This gives us, indeed, a &lt;math&gt;T&lt;/math&gt;-algebra structure on &lt;math&gt;A&lt;/math&gt;. Associativity and unity follows from the corresponding properties in the monoid.<br /> <br /> On the other hand, if we have a &lt;math&gt;T&lt;/math&gt;-algebra structure on &lt;math&gt;A&lt;/math&gt;, we can construct a monoid structure by setting<br /> :&lt;math&gt;u = \alpha([])&lt;/math&gt;<br /> :&lt;math&gt;m(a,b) = \alpha([a,b])&lt;/math&gt; <br /> It is clear that associativity of &lt;math&gt;m&lt;/math&gt; follows from the associativity of &lt;math&gt;\alpha&lt;/math&gt;, and unitality of &lt;math&gt;u&lt;/math&gt; follows from the unitality of &lt;math&gt;\alpha&lt;/math&gt;.<br /> <br /> (((potential headache: shouldn't &lt;math&gt;\eta&lt;/math&gt; show up more? Instead of the empty list, maybe?)))<br /> <br /> ====Example: Vector spaces====<br /> <br /> We have free and forgetful functors <br /> :&lt;math&gt;Set \to^{free} k-Vect \to^{forgetful} Set&lt;/math&gt;<br /> forming an adjoint pair; where the free functor takes a set &lt;math&gt;S&lt;/math&gt; and returns the vector space with basis &lt;math&gt;S&lt;/math&gt;; while the forgetful functor takes a vector space and returns the set of all its elements.<br /> <br /> The composition of these yields a monad &lt;math&gt;T&lt;/math&gt; in &lt;math&gt;Set&lt;/math&gt; taking a set &lt;math&gt;S&lt;/math&gt; to the set of all formal linear combinations of elements in &lt;math&gt;S&lt;/math&gt;. The monad multiplication takes formal linear combinations of formal linear combinations and multiplies them out:<br /> :&lt;math&gt;3(2v+5w)-5(3v+2w) = 6v+15w-15v-10w = -9v+5w&lt;/math&gt;<br /> <br /> A &lt;math&gt;T&lt;/math&gt;-algebra is a map &lt;math&gt;\alpha: TA\to A&lt;/math&gt; that ''acts like a vector space'' in the sense that &lt;math&gt;\alpha(\sum\alpha_i(\sum\beta_jv_j)) = \alpha(\sum\alpha_i\beta_jv_j)&lt;/math&gt;.<br /> <br /> We can define &lt;math&gt;\lambda\cdot v = \alpha(\lambda v)&lt;/math&gt; and &lt;math&gt;v+w=\alpha(v+w)&lt;/math&gt;. The operations thus defined are associative, distributive, commutative, and everything else we could wish for in order to define a vector space - precisely because the operations inside &lt;math&gt;TA&lt;/math&gt; are, and &lt;math&gt;\alpha&lt;/math&gt; is associative. <br /> <br /> ----<br /> <br /> The moral behind these examples is that using monads and monad algebras, we have significant power in defining and studying algebraic structures with categorical and algebraic tools. This paradigm ties in closely with the theory of ''operads'' - which has its origins in topology, but has come to good use within certain branches of universal algebra.<br /> <br /> An (non-symmetric) ''operad'' is a graded set &lt;math&gt;O = \bigoplus_i O_i&lt;/math&gt; equipped with composition operations &lt;math&gt;\circ_i: O_n\oplus O_m\to O_{n+m-1}&lt;/math&gt; that obey certain unity and associativity conditions. As it turns out, non-symmetric operads correspond to the summands in a monad with polynomial underlying functor, and from a non-symmetric operad we can construct a corresponding monad.<br /> <br /> The designator non-symmetric floats in this text o avoid dealing with the slightly more general theory of symmetric operads - which allow us to resort the input arguments, thus including the symmetrizer of a symmetric monoidal category in the entire definition. <br /> <br /> To read more about these correspondences, I can recommend you start with: the blog posts ''Monads in Mathematics'' here:<br /> [http://embuchestissues.wordpress.com/tag/monads-in-mathematics/]<br /> <br /> <br /> ===Algebras over endofunctors===<br /> <br /> Suppose we started out with an endofunctor that is not the underlying functor of a monad - or an endofunctor for which we don't want to settle on a monadic structure. We can still do a lot of the Eilenberg-Moore machinery on this endofunctor - but we don't get quite the power of algebraic specification that monads offer us. At the core, here, lies the lack of associativity for a generic endofunctor - and algebras over endofunctors, once defined, will correspond to non-associative correspondences to their monadic counterparts.<br /> <br /> '''Definition''' For an endofunctor &lt;math&gt;P:C\to C&lt;/math&gt;, we define a ''&lt;math&gt;P&lt;/math&gt;-algebra'' to be an arrow &lt;math&gt;\alpha\in C(PA,A)&lt;/math&gt;.<br /> <br /> A homomorphism of &lt;math&gt;P&lt;/math&gt;-algebras &lt;math&gt;\alpha\to\beta&lt;/math&gt; is some arrow &lt;math&gt;f:A\to B&lt;/math&gt; such that the diagram below commutes:<br /> :[[Image:EilenbergMoorePMorphism.png]]<br /> <br /> This homomorphism definition does not need much work to apply to the monadic case as well.<br /> <br /> ====Example: Groups====<br /> <br /> A group is a set &lt;math&gt;G&lt;/math&gt; with operations &lt;math&gt;u: 1\to G, i: G\to G, m: G\times G\to G&lt;/math&gt;, such that &lt;math&gt;u&lt;/math&gt; is a unit for &lt;math&gt;m&lt;/math&gt;, &lt;math&gt;m&lt;/math&gt; is associative, and &lt;math&gt;i&lt;/math&gt; is an inverse.<br /> <br /> Ignoring for a moment the properties, the theory of groups is captured by these three maps, or by a diagram<br /> :[[Image:GroupDiagram.png]]<br /> <br /> We can summarize the diagram as<br /> :&lt;math&gt;1+G+G\times G \mapsto^{[u,i,m]} G&lt;/math&gt;<br /> and thus recognize that groups are some equationally defined subcategory of the category of &lt;math&gt;T&lt;/math&gt;-algebras for the polynomial functor &lt;math&gt;T(X) = 1 + X + X\times X&lt;/math&gt;. The subcategory is ''full'', since if we have two algebras &lt;math&gt;\gamma: T(G)\to G&lt;/math&gt; and &lt;math&gt;\eta: T(H)\to H&lt;/math&gt;, that both lie within the subcategory that fulfills all the additional axioms, then certainly any morphism &lt;math&gt;\gamma\to\eta&lt;/math&gt; will be compatible with the structure maps, and thus will be a group homomorphism.<br /> <br /> ----<br /> <br /> We shall denote the category of &lt;math&gt;P&lt;/math&gt;-algebras in a category &lt;math&gt;C&lt;/math&gt; by &lt;math&gt;P-Alg(C)&lt;/math&gt;, or just &lt;math&gt;P-Alg&lt;/math&gt; if the category is implicitly understood.<br /> <br /> This category is wider than the corresponding concept for a monad. We don't require the kind of associativity we would for a monad - we just lock down the underlying structure. This distinction is best understood with an example: <br /> <br /> The free monoids monad has monoids for its algebras. On the other hand, we can pick out the underlying functor of that monad, forgetting about the unit and multiplication. An algebra over this structure is a slightly more general object: we no longer require &lt;math&gt;(a\cdot b)\cdot c = a\cdot (b\cdot c)&lt;/math&gt;, and thus, the theory we get is that of a ''magma''. We have concatenation, but we can't drop the brackets, and so we get something more reminiscent of a binary tree. <br /> <br /> ===Initial &lt;math&gt;P&lt;/math&gt;-algebras and recursion===<br /> <br /> Consider the polynomical functor &lt;math&gt;P(X) = 1 + X&lt;/math&gt; on the category of sets. It's algebras form a category, by the definitions above - and an algebra needs to pick out one special element 0, and one endomorphism T, for a given set.<br /> <br /> What would an initial object in this category of P-algebras look like? It would be an object &lt;math&gt;I&lt;/math&gt; equipped with maps &lt;math&gt;1 \to^o I \leftarrow^n I&lt;/math&gt;. For any other pair of maps &lt;math&gt;a: 1\to X, s: X\to X&lt;/math&gt;, we'd have a unique arrow &lt;math&gt;u: I\to X&lt;/math&gt; such that <br /> :[[Image:NNOcommutes.png]]<br /> commutes, or in equations such that<br /> :&lt;math&gt;u(o) = a&lt;/math&gt;<br /> :&lt;math&gt;u(n(x)) = s(u(x))&lt;/math&gt;<br /> <br /> Now, unwrapping the definitions in place, we notice that we will have elements &lt;math&gt;o, n(o), n(n(o), \dots&lt;/math&gt; in &lt;math&gt;I&lt;/math&gt;, and the initiality will force us to not have any ''other'' elements floating around. Also, intiality will prevent us from having any elements not in this minimally forced list.<br /> <br /> We can rename the elements to form something more recognizable - by equating an element in &lt;math&gt;I&lt;/math&gt; with the number of applications of &lt;math&gt;n&lt;/math&gt; to &lt;math&gt;o&lt;/math&gt;. This yields, for us, elements &lt;math&gt;0, 1, 2, \dots&lt;/math&gt; with one function that picks out the &lt;math&gt;0&lt;/math&gt;, and another that gives us the cussessor.<br /> <br /> This should be recognizable as exactly the natural numbers; with just enough structure on them to make the principle of mathematical induction work: suppose we can prove some statement &lt;math&gt;P(0)&lt;/math&gt;, and we can extend a proof of &lt;math&gt;P(n)&lt;/math&gt; to &lt;math&gt;P(n+1)&lt;/math&gt;. Then induction tells us that the statement holds for all &lt;math&gt;P(n)&lt;/math&gt;.<br /> <br /> More importantly, recursive definitions of functions from natural numbers can be performed here by choosing an appropriate algebra mapping to.<br /> <br /> This correspondence between the initial object of &lt;math&gt;P(X) = 1 + X&lt;/math&gt; is the reason such an initial object in a category with coproducts and terminal objects is called a ''natural numbers object''. <br /> <br /> For another example, we consider the functor &lt;math&gt;P(X) = 1 + X\times X&lt;/math&gt;. <br /> <br /> '''Pop Quiz''' Can you think of a structure with this as underlying defining functor?<br /> <br /> An initial &lt;math&gt;1+X\times X&lt;/math&gt;-algebra would be some diagram<br /> :&lt;math&gt;1 \to^o I \leftarrow^m I\times I&lt;/math&gt;<br /> such that for any other such diagram<br /> :&lt;math&gt;1 \to^a X \leftarrow^* X\times X&lt;/math&gt;<br /> we have a unique arrow &lt;math&gt;u:I\to X&lt;/math&gt; such that<br /> :[[Image:MonoidCommutes.png]]<br /> commutes.<br /> <br /> Unwrapping the definition, working over Sets again, we find we are forced to have some element &lt;math&gt;*&lt;/math&gt;, the image of &lt;math&gt;o&lt;/math&gt;. Any two elements &lt;math&gt;S,T&lt;/math&gt; in the set give rise to some &lt;math&gt;(S,T)&lt;/math&gt;, which we can view as being the binary tree<br /> :[[Image:MagmaComposition.png]]<br /> <br /> The same way that we could construct induction as an algebra map from a natural numbers object, we can use this object to construct a tree-shaped induction; and similarily, we can develop what amounts to the theory of ''structural induction'' using these more general approaches to induction.<br /> <br /> ====Example of structural induction====<br /> <br /> Using the structure of &lt;math&gt;1+X\times X&lt;/math&gt;-algebras we shall prove the following statement:<br /> <br /> '''Proposition''' The number of leaves in a binary tree is one more than the number of internal nodes.<br /> <br /> '''Proof''' We write down the actual Haskell data type for the binary tree initial algebra.<br /> &lt;haskell&gt;<br /> data Tree = Leaf | Node Tree Tree<br /> <br /> nLeaves Leaf = 1<br /> nLeaves (Node s t) = nLeaves s + nLeaves t<br /> <br /> nNodes Leaf = 0<br /> nNodes (Node s t) = 1 + nNodes s + nNodes t<br /> &lt;/haskell&gt;<br /> <br /> Now, it is clear, as a base case, that for the no-nodes tree &lt;hask&gt;Leaf&lt;/hask&gt;:<br /> &lt;haskell&gt;<br /> nLeaves Leaf = 1 + nNodes Leaf<br /> &lt;/haskell&gt;<br /> <br /> For the structural induction, now, we consider some binary tree, where we assume the statement to be known for each of the two subtrees. Hence, we have<br /> &lt;haskell&gt;<br /> tree = Node s t<br /> <br /> nLeaves s = 1 + nNodes s<br /> nLeaves t = 1 + nNodes t<br /> &lt;/haskell&gt;<br /> and we may compute<br /> &lt;haskell&gt;<br /> nLeaves tree = nLeaves s + nLeaves t <br /> = 1 + nNodes s + 1 + nNodes t <br /> = 2 + nNodes s + nNodes t<br /> <br /> nNodes tree = 1 + nNodes s + nNodes t<br /> &lt;/haskell&gt;<br /> <br /> Now, since the statement is proven for each of the cases in the structural description of the data, it follows form the principle of structural induction that the proof is finished.<br /> <br /> In order to really nail down what we are doing here, we need to define what we mean by predicates in a strict manner. There is a way to do this using ''fibrations'', but this reaches far outside the scope of this course. For the really interested reader, I'll refer to [http://www.springerlink.com/content/d022nlv03n26nm03/]. <br /> <br /> Another way to do this is to introduce a ''topos'', and work it all out in terms of its ''internal logic'', but again, this reaches outside the scope of this course.<br /> <br /> ====Lambek's lemma====<br /> <br /> What we do when we write a recursive data type definition in Haskell ''really'' to some extent is to define a data type as the initial algebra of the corresponding functor. This intuitive equivalence is vindicated by the following <br /> <br /> '''Lemma''' ''Lambek'' If &lt;math&gt;P: C\to C&lt;/math&gt; has an initial algebra &lt;math&gt;I&lt;/math&gt;, then &lt;math&gt;P(I) = I&lt;/math&gt;.<br /> <br /> '''Proof''' Let &lt;math&gt;a: PA\to A&lt;/math&gt; be an initial &lt;math&gt;P&lt;/math&gt;-algebra. We can apply &lt;math&gt;P&lt;/math&gt; again, and get a chain<br /> :&lt;math&gt;PPA \to^{Pa} PA \to^a A&lt;/math&gt;<br /> We can fill out the diagram<br /> :[[Image:LambekPartialDiagram.png]]<br /> to form the diagram<br /> :[[Image:LambekDiagram.png]]<br /> where &lt;math&gt;f&lt;/math&gt; is induced by initiality, since &lt;math&gt;Pa:PPa\to Pa&lt;/math&gt; is also a &lt;math&gt;P&lt;/math&gt;-algebra.<br /> <br /> The diagram above commutes, and thus &lt;math&gt;af = 1_{PA}&lt;/math&gt; and &lt;math&gt;fa = 1_A&lt;/math&gt;. Thus &lt;math&gt;f&lt;/math&gt; is an inverse to &lt;math&gt;a&lt;/math&gt;. QED.<br /> <br /> Thus, by Lambek's lemma we ''know'' that if &lt;math&gt;P_A(X) = 1 + A\times X&lt;/math&gt; then for that &lt;math&gt;P_A&lt;/math&gt;, the initial algebra - should it exist - will fulfill&lt;math&gt;I = 1 + A\times I&lt;/math&gt;, which in turn is exactly what we write, defining this, in Haskell code: <br /> &lt;haskell&gt;<br /> List a = Nil | Cons a List<br /> &lt;/haskell&gt;<br /> <br /> ====Recursive definitions with the unique maps from the initial algebra====<br /> <br /> Consider the following &lt;math&gt;P_A(X)&lt;/math&gt;-algebra structure &lt;math&gt;l: P_A(\mathbb N)\to\mathbb N&lt;/math&gt; on the natural numbers:<br /> &lt;haskell&gt;<br /> l(*) = 0<br /> l(a,n) = 1 + n<br /> &lt;/haskell&gt;<br /> <br /> We get a unique map &lt;math&gt;f&lt;/math&gt; from the initial algebra for &lt;math&gt;P_A(X)&lt;/math&gt; (lists of elements of type &lt;math&gt;A&lt;/math&gt;) to &lt;math&gt;\mathbb N&lt;/math&gt; from this definition. This map will fulfill:<br /> &lt;haskell&gt;<br /> f(Nil) = l(*) = 0<br /> f(Cons a xs) = l(a,f(xs)) = 1 + f(xs)<br /> &lt;/haskell&gt;<br /> which starts taking on the shape of the usual definition of the length of a list:<br /> &lt;haskell&gt;<br /> length(Nil) = 0<br /> length(Cons a xs) = 1 + length(xs)<br /> &lt;/haskell&gt;<br /> <br /> And thus, the machinery of endofunctor algebras gives us a strong method for doing recursive definitions in a theoretically sound manner.<br /> <br /> ===Homework===<br /> <br /> Complete credit will be given for 8 of the 13 questions.<br /> <br /> # Find a monad whose algebras are ''associative algebras'': vector spaces with a binary, associative, unitary operation (multiplication) defined on them. Factorize the monad into a free/forgetful adjoint pair.<br /> # Find an endofunctor of &lt;math&gt;Hask&lt;/math&gt; whose initial object describes trees that are either binary of ternary at each point, carrying values from some &lt;math&gt;A&lt;/math&gt; in the leaves.<br /> # Write an implementation of the monad of vector spaces in Haskell. If this is tricky, restrict the domain of the monad to, say, a 3-element set, and implement the specific example of a 3-dimensional vector space as a monad. Hint: [http://sigfpe.blogspot.com] has written about this approach.<br /> # Find a &lt;math&gt;X\mapsto 1+A\times X&lt;/math&gt;-algebra &lt;math&gt;L&lt;/math&gt; such that the unique map from the initial algebra &lt;math&gt;I&lt;/math&gt; to &lt;math&gt;L&lt;/math&gt; results in the function that will reverse a given list.<br /> # Find a &lt;math&gt;X\mapsto 1+A\times X&lt;/math&gt;-algebra structure on the object &lt;math&gt;1+A&lt;/math&gt; that will pick out the first element of a list, if possible.<br /> # Find a &lt;math&gt;X\mapsto \mathbb N+X\times X&lt;/math&gt;-algebra structure on the object &lt;math&gt;\mathbb N&lt;/math&gt; that will pick out the sum of the leaf values for the binary tree in the initial object.<br /> # Complete the proof of Lambek's lemma by proving the diagram commutes.<br /> # * We define a ''coalgebra'' for an endofunctor &lt;math&gt;T&lt;/math&gt; to be some arrow &lt;math&gt;\gamma: A \to TA&lt;/math&gt;. If &lt;math&gt;T&lt;/math&gt; is a comonad - i.e. equipped with a counit &lt;math&gt;\epsilon: T\to 1&lt;/math&gt; and a cocomposition &lt;math&gt;\Delta: T\to T\times T&lt;/math&gt;, then we define a coalgebra for the comonad &lt;math&gt;T&lt;/math&gt; to additionally fulfill &lt;math&gt;\gamma\circ T\gamma = \gamma\circ\Delta&lt;/math&gt; (compatibility) and &lt;math&gt;\epsilon_A\circ\gamma = 1_A&lt;/math&gt; (counitality).<br /> ## (2pt) Prove that if &lt;math&gt;T&lt;/math&gt; is an endofunctor, then if &lt;math&gt;T&lt;/math&gt; has an initial algebra, then it is a coalgebra. Does &lt;math&gt;T&lt;/math&gt; necessarily have a final coalgebra?<br /> ## (2pt) Prove that if &lt;math&gt;U,F&lt;/math&gt; are an adjoint pair, then &lt;math&gt;FU&lt;/math&gt; forms a comonad.<br /> ## (2pt) Describe a final coalgebra over the comonad formed from the free/forgetful adjunction between the categories of Monoids and Sets.<br /> ## (2pt) Describe a final coalgebra over the endofunctor &lt;math&gt;P(X) = 1 + X&lt;/math&gt;.<br /> ## (2pt) Describe a final coalgebra over the endofunctor &lt;math&gt;P(X) = 1 + A\times X&lt;/math&gt;.<br /> ## (2pt) Prove that if &lt;math&gt;c: C\to PC&lt;/math&gt; is a final coalgebra for an endofunctor &lt;math&gt;P:C\to C&lt;/math&gt;, then &lt;math&gt;c&lt;/math&gt; is an isomorphism.</div> Michiexile https://wiki.haskell.org/index.php?title=File:MagmaComposition.png&diff=31526 File:MagmaComposition.png 2009-11-11T18:42:02Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:MonoidCommutes.png&diff=31525 File:MonoidCommutes.png 2009-11-11T18:41:45Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:NNOcommutes.png&diff=31524 File:NNOcommutes.png 2009-11-11T18:41:24Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:GroupDiagram.png&diff=31523 File:GroupDiagram.png 2009-11-11T18:41:00Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:EilenbergMoorePMorphism.png&diff=31522 File:EilenbergMoorePMorphism.png 2009-11-11T18:40:40Z <p>Michiexile: </p> <hr /> <div></div> Michiexile https://wiki.haskell.org/index.php?title=File:EilenbergMooreAssociativity.png&diff=31521 File:EilenbergMooreAssociativity.png 2009-11-11T18:39:45Z <p>Michiexile: </p> <hr /> <div></div> Michiexile