ebook img

Programming Language Semantics (Lectures Slides) PDF

297 Pages·2018·0.832 MB·
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Programming Language Semantics (Lectures Slides)

CS522 - Programming Language Semantics Some Category Theory Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 Category theory appeared for at least two important reasons: 1. to capture general concepts and principles from various particular instances of mathematics; and 2. to eliminate some of the foundational concerns, especially those related to set theory. While the usefulness of category theory is still debatable in mathematics, there is no doubt that category theory is a very powerful language to express and handle complex computer science concepts. In what follows, we shall use category theory as a means to define some very intuitive models of (cid:21) -calculus. But first, let us introduce some basic notions of category theory. 3 Category C A category consists of: jCj C • A class of objects written , or Ob( ). It is called a “class” to reflect the fact that it does not need to obey the constraints of set theory; one can think of a class as something “potentially larger than a set”; 2 jCj • A set of morphisms, or arrows, for any two objects A; B , C 2 C written (A; B). The fact that f (A; B) is often expressed ! using the more familiar notation f : A B. The object A is called the domain of f, or its source, and B is called the codomain, or the target of f; ! 2 jCj • A special identity morphism 1 : A A for any object A ; A C (cid:2) C ! C • A composition operator _ ;_ : (A; B) (B; C) (A; C) for 4 2 jCj any (not necessarily distinct) objects A; B; C , with the following properties: 2 jCj – (identity) 1 ; f = f; 1 = f for any A; B and any A B ! f : A B, and ! – (associativity) (f; g); h = (f; g); h for any f : A B, ! ! g : B C, and h : C D. Categories are everywhere. For example: • Set is the category whose objects are sets and whose morphisms are the usual functions; • Setinj is the category whose objects are sets and whose morphisms are the injective functions; • Setsurj is the category whose objects are sets and whose morphisms are the surjective functions. Exercise 1 Prove that the above are indeed categories. 5 Note that it may be the case that there are no morphisms between some given objects. For example, there is no morphism in Setinj(f1; 2g; f1g). Let us discuss several other categories: • Mon is the category of monoids, i.e., structures (cid:1) (cid:2) ! 2 (cid:1) (M; _ _ : M M M; e M) with _ _ associative and identity e, with structure preserving functions, i.e., functions ! (cid:1) (cid:1) f : M N such that f(a b) = f(a) f(b) and f(e ) = e , M N M N as morphisms; • Grp is the category of groups and morphisms of groups; • Poset is the category of partially ordered sets and monotone functions between them; (cid:20) • Real is the category whose objects are the real numbers and (cid:20) ! (cid:20) whose morphisms are given by the “ ” relation: p q iff p q. Exercise 2 Show that the above are categories. 6 Let us continue the discussion on categorical concepts. Given ! ! morphisms f : A B and g : B A, one can obtain the ! ! morphisms f; g : A A and g; f : B B. If these morphisms are the identities on A and B, respectively, the morphisms f and g are called isomorphisms and the objects A and B are said to be ≃ isomorphic. The notation A B is often used to denote that A and B are isomorphic objects. 7 Diagrams C A diagram in a category is a directed graph whose nodes are C objects and whose arrows are morphisms in . Formally, a diagram ! jCj ! C consists of a pair of mappings d : Nodes and d : Arrows , ! C written compactly d : (Nodes; Arrows) , where (Nodes; Arrows) is some (not necessarily finite) labeled digraph ! (i.e., directed, or oriented, graph), such that for any (cid:11) : i j in ! C Arrows, d((cid:11)) is a morphism d(i) d(j) in . To simplify writing, we draw diagrams directly as digraphs and do not specify the mapping explicitly. For example, the following nine figures represent are diagrams: 8 f // f // f // A @ B A B A B @ } @ } ~~} g u g h (cid:15)(cid:15) (cid:15)(cid:15) C // C D v f )) >> B A 55 B A ~ f ~ ~ ~ g A @ B @ @ g C // // // qqq(cid:3)(cid:3)A;;; : : : An : : : A1 A(cid:15)GG 100 xxqq (cid:1)(cid:1)(cid:3): : : (cid:29)(cid:29) (cid:15) 0 (cid:15) 0 A A : : : A : : : (cid:15) 0 1 2 n (cid:15) 0 f (cid:15) A 0g 1(cid:15) @@ 2 ? 01 (cid:0) ? (cid:15) (cid:0) ? 0 (cid:15) (cid:0) ? 0 (cid:15)(cid:0)(cid:0) ??0 (cid:15)(cid:0) g (cid:31)(cid:31) (cid:23)(cid:23) f . 2 2 . ′ A > . ??A > (cid:127) > (cid:127) > (cid:127) > (cid:127) > (cid:127) (cid:30)(cid:30) (cid:127) g f n n A n 9 A diagram is said to commute, or is a commutative diagram, iff any two paths between any two nodes correspond to equal morphisms, where path concatenation is interpreted as morphism composition. For example, the top-left diagram commutes iff f; g = h; the top-right diagram commutes iff f; g = u; v; the middle diagram commutes iff f = g; the bottom-right diagram commutes iff (cid:20) (cid:20) f ; g = f ; g for all numbers 1 i; j n. i i j j (cid:20) An interesting diagram in the category Real is that of positive ! (cid:20) numbers, with an arrow p q iff p q. Unless explicitly stated differently, from now on we assume all the diagrams that we draw to be commutative. 10 Cones and Limits ! C Given a diagram d : (Nodes; Arrows) , a cone of d is a pair f g jCj ! (C; (cid:13) , where C is an object in and (cid:13) : C d(i) are i i2Nodes i C morphisms in with the property that (cid:13) ; d((cid:11)) = (cid:13) for any i j ! (cid:11) : i j in Arrows: d(i) == (cid:13) z izz z C D d((cid:11)) D D D !! (cid:15)(cid:15) (cid:13) i d(j) In other words, all the diagrams formed by the cone with any edge in the diagram commute. The terminology of “cone” probably comes from graphical resemblance with the 3D figure obtained when one regards the diagram as a disc and C as a point above the plane of the disc, which is connected to every point in the diagram.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.